結果

問題 No.1170 Never Want to Walk
ユーザー mgingin142857mgingin142857
提出日時 2020-08-14 22:05:29
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 272 ms / 2,000 ms
コード長 1,827 bytes
コンパイル時間 1,743 ms
コンパイル使用メモリ 166,760 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-18 21:53:32
合計ジャッジ時間 6,903 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,248 KB
testcase_02 AC 1 ms
5,248 KB
testcase_03 AC 2 ms
5,248 KB
testcase_04 AC 2 ms
5,248 KB
testcase_05 AC 1 ms
5,248 KB
testcase_06 AC 2 ms
5,248 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 3 ms
5,376 KB
testcase_13 AC 3 ms
5,376 KB
testcase_14 AC 3 ms
5,376 KB
testcase_15 AC 3 ms
5,376 KB
testcase_16 AC 3 ms
5,376 KB
testcase_17 AC 3 ms
5,376 KB
testcase_18 AC 3 ms
5,376 KB
testcase_19 AC 3 ms
5,376 KB
testcase_20 AC 4 ms
5,376 KB
testcase_21 AC 3 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 3 ms
5,376 KB
testcase_24 AC 3 ms
5,376 KB
testcase_25 AC 2 ms
5,376 KB
testcase_26 AC 4 ms
5,376 KB
testcase_27 AC 260 ms
5,376 KB
testcase_28 AC 249 ms
5,376 KB
testcase_29 AC 268 ms
5,376 KB
testcase_30 AC 271 ms
5,376 KB
testcase_31 AC 266 ms
5,376 KB
testcase_32 AC 268 ms
5,376 KB
testcase_33 AC 261 ms
5,376 KB
testcase_34 AC 265 ms
5,376 KB
testcase_35 AC 272 ms
5,376 KB
testcase_36 AC 243 ms
5,376 KB
testcase_37 AC 262 ms
5,376 KB
testcase_38 AC 262 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll, ll> P;
using VP = vector<P>;
using VVP = vector<VP>;
using VI = vector<ll>;
using VVI = vector<VI>;
using VVVI = vector<VVI>;
const int inf = 1e9 + 7;
const ll INF = 1LL << 61;
const ll mod = 1e9 + 7;

template <class T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

template <class T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

struct UnionFind {
    vector<int> data;

    UnionFind(int sz) { data.assign(sz, -1); }

    bool unite(int x, int y) {
        x = find(x), y = find(y);
        if (x == y) return (false);
        if (data[x] > data[y]) swap(x, y);
        data[x] += data[y];
        data[y] = x;
        return (true);
    }

    int find(int k) {
        if (data[k] < 0) return (k);
        return (data[k] = find(data[k]));
    }

    int size(int k) { return (-data[find(k)]); }
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int i, j;
    int n, a, b;
    cin >> n >> a >> b;
    int x[n];
    for (i = 0; i < n; i++) {
        cin >> x[i];
    }
    UnionFind uf(n);
    int l = 0;
    int r = -1;
    while (1) {
        r++;
        if (x[r] - x[l] >= a && x[r] - x[l] <= b) uf.unite(l, r);
        while (r + 1 < n && x[r + 1] - x[l] <= b) {
            r++;
            if (x[r] - x[l] >= a) uf.unite(l, r);
        }
        while (l + 1 < n && x[r] - x[l + 1] >= a) {
            l++;
            if (x[r] - x[l] <= b) uf.unite(l, r);
        }
        //cout << l << " " << r << endl;
        if (l == n - 1) break;
    }
    for (i = 0; i < n; i++) {
        cout << uf.size(i) << endl;
    }
}
0