結果

問題 No.1170 Never Want to Walk
ユーザー oevloevl
提出日時 2020-08-14 22:11:48
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,616 bytes
コンパイル時間 2,378 ms
コンパイル使用メモリ 213,328 KB
実行使用メモリ 29,596 KB
最終ジャッジ日時 2024-04-18 22:02:09
合計ジャッジ時間 9,125 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); ++i)
using namespace std;

class UnionFind {
public:
    vector<int> uni;
    UnionFind(int s) : uni(s, -1) {}
    int root(int a) {
        return uni[a] < 0 ? a : uni[a] = root(uni[a]);
    }
    bool connect(int a, int b) {
        a = root(a);
        b = root(b);
        if(a == b) return false;
        if(uni[a] > uni[b]) swap(a, b);
        uni[a] = uni[a] + uni[b];
        uni[b] = a;
        return true;
    }
    bool isConnect(int a, int b) {
        return root(a) == root(b);
    }
    int size(int a) {
        return -uni[root(a)];
    }
};

int main() {
    int N, A, B;
    cin >> N >> A >> B;
    vector<int> X(N);
    map<int, int> id;
    rep(i, N) {
        cin >> X[i];
        id[X[i]] = i;
        id[-X[i]] = i;
    }
    for(auto &e : X) cin >> e;
    UnionFind uf(N);
    rep(_, 2) {
        for(auto &x : X) {
            auto it = lower_bound(X.begin(), X.end(), x + A);
            auto jt = upper_bound(X.begin(), X.end(), x + B);
            if(it == X.end()) continue;
            if(jt == X.begin()) continue;
            jt = prev(jt);
            int i = id[*it];
            int j = id[*jt];
            if(uf.isConnect(i, j)) {
                uf.connect(id[x], i);
            } else {
                for(int pos = i; pos < j; ++pos) {
                    uf.connect(pos, pos + 1);
                    if(uf.isConnect(i, j)) break;
                }
            }
        }
        for(auto &x : X) x = -x;
        sort(X.begin(), X.end());
    }
    rep(i, N) cout << uf.size(i) << '\n';
    return 0;
}
0