結果

問題 No.1170 Never Want to Walk
ユーザー totori_nyaatotori_nyaa
提出日時 2020-10-07 20:24:21
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 42 ms / 2,000 ms
コード長 1,509 bytes
コンパイル時間 2,649 ms
コンパイル使用メモリ 202,984 KB
実行使用メモリ 4,688 KB
最終ジャッジ日時 2023-09-27 09:55:58
合計ジャッジ時間 5,221 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<bits/stdc++.h> 
using namespace std;
typedef long long ll;
#define totori signed
template<typename T1,typename T2> bool chmin(T1 &a,T2 b){if(a<=b)return 0; a=b; return 1;}
template<typename T1,typename T2> bool chmax(T1 &a,T2 b){if(a>=b)return 0; a=b; return 1;}
ll dx[4]={0,1,-1,0};
ll dy[4]={1,0,0,-1};


class UnionFind{
    public:
    //親の番号を格納する。親だった場合は-(その集合のサイズ)
    vector<int> parent;

    UnionFind(int N){
        parent = vector<int>(N,-1);
    }

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

    int size(int A){
        return -parent[root(A)];
    }

    bool unite(int A, int B) {
        A = root(A), B = root(B);
        if(A == B) return false; 

        if(size(A) < size(B)) swap(A,B);
        parent[A] += parent[B];
        parent[B] = A;
        return true;
    }

    bool same(int A, int B){
        return root(A)==root(B);
    } 
};

totori main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);
    
    int n,a,b;
    cin>>n>>a>>b;
    int x[n];
    for(int i=0;i<n;i++)cin>>x[i];
    UnionFind uni(n);
    int r = 0;
    for(int i=0;i<n;i++){
        chmax(r,i);
        if(r>i && x[r-1]-x[i]>=a && x[r-1]-x[i]>=a)uni.unite(r-1,i);
        while(r<n && x[r]-x[i]<=b){
            if(x[r]-x[i]>=a)uni.unite(i,r);
            r++;
        }
    }
    for(int i=0;i<n;i++){
        cout << uni.size(i) << "\n";
    }
}
0