結果

問題 No.1170 Never Want to Walk
ユーザー Manuel1024Manuel1024
提出日時 2021-04-28 23:47:39
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,450 ms / 2,000 ms
コード長 1,700 bytes
コンパイル時間 688 ms
コンパイル使用メモリ 75,800 KB
実行使用メモリ 4,924 KB
最終ジャッジ日時 2023-09-22 06:26:51
合計ジャッジ時間 21,750 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 9 ms
4,380 KB
testcase_13 AC 8 ms
4,384 KB
testcase_14 AC 8 ms
4,376 KB
testcase_15 AC 8 ms
4,380 KB
testcase_16 AC 9 ms
4,380 KB
testcase_17 AC 8 ms
4,376 KB
testcase_18 AC 9 ms
4,376 KB
testcase_19 AC 9 ms
4,380 KB
testcase_20 AC 9 ms
4,380 KB
testcase_21 AC 8 ms
4,380 KB
testcase_22 AC 9 ms
4,380 KB
testcase_23 AC 8 ms
4,376 KB
testcase_24 AC 9 ms
4,380 KB
testcase_25 AC 8 ms
4,380 KB
testcase_26 AC 9 ms
4,376 KB
testcase_27 AC 1,374 ms
4,576 KB
testcase_28 AC 1,365 ms
4,588 KB
testcase_29 AC 1,427 ms
4,596 KB
testcase_30 AC 1,396 ms
4,636 KB
testcase_31 AC 1,374 ms
4,556 KB
testcase_32 AC 1,384 ms
4,600 KB
testcase_33 AC 1,360 ms
4,924 KB
testcase_34 AC 1,409 ms
4,728 KB
testcase_35 AC 1,414 ms
4,624 KB
testcase_36 AC 1,375 ms
4,600 KB
testcase_37 AC 1,371 ms
4,668 KB
testcase_38 AC 1,450 ms
4,596 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
struct UnionFind{
    vector<int> parent;
    UnionFind(int n){
        parent = vector<int>(n, -1);
    }

    int root(int x){
        if(parent[x] < 0) return x;
        else return parent[x] = root(parent[x]);
    }

    bool same(int x, int y){
        x = root(x);
        y = root(y);
        return x == y;
    }

    int count(int x){
        x = root(x);
        return -parent[x];
    }

    void unite(int x, int y){
        x = root(x);
        y = root(y);
        if(x == y) return;
        if(count(x) < count(y)){
            int t = x; x = y; y = t;
        }

        parent[x] += parent[y];
        parent[y] = x;
    }
};

int main(){
    int n, a, b;
    cin >> n >> a >> b;
    vector<int> x(n);
    for(auto &p: x) cin >> p;

    UnionFind data(n);
    int plind = -1, prind = -1;
    for(int i = 0; i < n; i++){
        int lind = n;
        int lwa = i;
        while(lind-lwa > 1){
            int mid = (lind+lwa)/2;
            if(abs(x[mid]-x[i]) >= a) lind = mid;
            else lwa = mid;
        }
        int rind = i;
        int rwa = n;
        while(rwa-rind > 1){
            int mid = (rind+rwa)/2;
            if(abs(x[mid]-x[i]) <= b) rind = mid;
            else rwa = mid;
        }
        //cerr << lind << " " << rind << " -> ";

        if(prind >= lind){
            lind = prind;
            prind = rind;
        }else{
            plind = lind;
            prind = rind;
        }
        cerr << lind << " " << rind << endl;
        for(int j = lind; j <= rind; j++) data.unite(i, j);
    }

    for(int i = 0; i < n; i++) cout << data.count(i) << endl;
    return 0;
}
0