結果

問題 No.1170 Never Want to Walk
ユーザー NNMochiNNMochi
提出日時 2020-08-14 22:00:58
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 2,096 bytes
コンパイル時間 1,813 ms
コンパイル使用メモリ 168,708 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-18 21:48:14
合計ジャッジ時間 5,496 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 1 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 4 ms
5,376 KB
testcase_23 AC 3 ms
5,376 KB
testcase_24 AC 4 ms
5,376 KB
testcase_25 AC 4 ms
5,376 KB
testcase_26 AC 3 ms
5,376 KB
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
testcase_33 RE -
testcase_34 RE -
testcase_35 RE -
testcase_36 RE -
testcase_37 RE -
testcase_38 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
#define ROF(i,a,b) for(int i=a;i>=b;i--)
#define per(i,a) ROF(i,a,0)
#define pb push_back
using namespace std;
using ll=long long;
using ld=long double;
using ch=char;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
typedef vector<ch> vc;
typedef vector<vc> vvc;
const ll MOD=1000000007;
const ll MOD2=998244353;
const ld PI=acos(-1);
const ll INF=1e18;
struct edge{ll to,cost;};
struct edge2{ll from,to,cost;};

template <typename T>
bool chmax(T &a, const T& b) {
    if (a < b) {
      a = b;
        return true;
    }
    return false;
}

template <typename T>
bool chmin(T &a, const T& b) {
    if (a > b) {
      a = b;
      return true;
    }
    return false;
}

//union_find(親par,深さrnk)
const int MXV=100000;
int par[MXV],rnk[MXV],siz[MXV];
void union_init(int n){
    for(int i=0;i<n;i++){
        par[i]=i;
        rnk[i]=0;
        siz[i]=1;
    }
}
//根を探す
int find(int x){
    if(par[x]==x){
        return x;
    }
    else{
        return par[x]=find(par[x]);
    }
}

void unite(int x,int y){
    x=find(x);
    y=find(y);
    if(x==y){
        return;
    }
    if(rnk[x]<rnk[y]){
        par[x]=y;
        siz[y]+=siz[x];
        siz[x]=0;
    }
    else{
        par[y]=x;
        siz[x]+=siz[y];
        siz[y]=0;
        if(rnk[x]==rnk[y]){
            rnk[x]++;
        }
    }
}
//集合が同じか
bool same(int x,int y){
    return find(x)==find(y);
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N,A,B;
    cin >> N >> A >> B;
    union_init(N);
    vl X(N);
    set<int> st;
    rep(i,N){
        cin >> X[i];
    }
    X.pb(INF);
    rep(i,N){
        auto itr1=lower_bound(X.begin(),X.end(),X[i]+A);
        while(*itr1<=X[i]+B){
            unite(i,itr1-X.begin());
            itr1++;
        }
    }
    rep(i,N){
        cout << siz[find(i)] << '\n';
    }
}
/*
overflow checked?
corner case checked?
boundary checked?
not TLE in worst case checked?
*/
0