【題解】AtCoder ABC160D – Line++

【題目敘述】https://atcoder.jp/contests/abc160/tasks/abc160_d

#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;

int main() {
    int N, X, Y;
    cin >> N >> X >> Y;
    int dist[N+1][N+1];
    int ans[N+1];
    memset(dist, 0x3F, sizeof(dist));
    memset(ans, 0, sizeof(ans));
    for (int i = 1; i < N; i++){
        for (int j = i+1; j <= N; j++){
            dist[i][j] = min({abs(j-i), abs(X-i)+1+abs(j-Y), abs(Y-i)+1+abs(j-X)});
            ans[dist[i][j]]++;
        }
    }
    for (int i = 1; i < N; i++){
        cout << ans[i] << "\n";
    }
    return 0;
}

分享本文 Share with friends