結果

問題 No.1170 Never Want to Walk
ユーザー 👑 zeronosu77108zeronosu77108
提出日時 2020-08-14 23:31:48
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,468 bytes
コンパイル時間 3,599 ms
コンパイル使用メモリ 130,136 KB
実行使用メモリ 13,984 KB
最終ジャッジ日時 2024-04-18 23:16:58
合計ジャッジ時間 10,230 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

struct unionfind {
    vector<long long> par,_size;
    unionfind(long n) : par(n+1), _size(n+1,1) {
        for(long long i=0; i<n; i++) par[i]=i;
    }
    void init(long long n) {
        par = vector<long long>(n);
        _size = vector<long long>(n);
        for(long long i=0; i<n; i++) par[i]=i;
    }
    long long root(long long x) {
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }
    bool merge(long long x, long long y) {
        x = root(x);
        y = root(y);
        if (x==y) return false;
        if(_size[x]<_size[y]) swap(x,y);
        _size[x] += _size[y];
        par[y] = x;
        return true;
    }
    bool issame(long long x, long long y) { return root(x) == root(y); }
    long long size(long long x) { return _size[root(x)]; }
};

int main() {
    int n,a,b;
    cin >> n >> a >> b;
    vector x(n,0);
    for (int i=0; i<n; i++) cin >> x[i];
    for (int i=0; i<n; i++) cerr<<x[i]<<" ";cerr<<endl;
    unionfind uni(n);

    for (int i=0; i<n-1; i++) {
        auto l = lower_bound(x.begin(), x.end(), x[i]+a);
        if (l == x.end()) continue;
        auto u = upper_bound(x.begin(), x.end(), x[i]+b);
        if (l >= u) continue;
        uni.merge(i,l-x.begin());
        for (int j=l-x.begin(); j<u-x.begin()-1; j++) uni.merge(j,j+1);
    }

    for (int i=0; i<n; i++) {
        cout << uni.size(i) << endl;
    }
}
0