結果

問題 No.1170 Never Want to Walk
ユーザー merom686merom686
提出日時 2020-08-14 21:53:53
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 43 ms / 2,000 ms
コード長 1,205 bytes
コンパイル時間 951 ms
コンパイル使用メモリ 96,440 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-18 21:38:41
合計ジャッジ時間 3,357 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

struct UnionFind {
    UnionFind(int n) : p(n, -1) {}
    int root(int u) {
        return p[u] < 0 ? u : p[u] = root(p[u]);
    }
    int size(int u) {
        return -p[root(u)];
    }
    bool same(int u, int v) {
        return root(u) == root(v);
    }
    void unite(int u, int v) {
        u = root(u);
        v = root(v);
        if (u == v) return;
        if (p[u] > p[v]) swap(u, v);
        p[u] += p[v];
        p[v] = u;
    }
    vector<int> p;
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n, a, b;
    cin >> n >> a >> b;

    vector<int> x(n);
    for (int i = 0; i < n; i++) {
        cin >> x[i];
    }

    UnionFind uf(n);
    int i0, i1 = 0;
    for (int i = 0; i < n; i++) {
        i0 = i1;
        while (i1 < n && x[i1] <= x[i] + b) i1++;
        for (int j = i1 - 1; j >= max(i0 - 1, 0); j--) {
            if (x[j] < x[i] + a) break;
            uf.unite(i, j);
        }
    }

    for (int i = 0; i < n; i++) {
        cout << uf.size(i) << '\n';
    }

    return 0;
}
0