結果

問題 No.1170 Never Want to Walk
ユーザー monnumonnu
提出日時 2021-07-10 19:54:56
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 354 ms / 2,000 ms
コード長 1,182 bytes
コンパイル時間 1,556 ms
コンパイル使用メモリ 170,020 KB
実行使用メモリ 6,528 KB
最終ジャッジ日時 2023-09-14 19:52:00
合計ジャッジ時間 8,695 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 3 ms
4,380 KB
testcase_13 AC 3 ms
4,376 KB
testcase_14 AC 3 ms
4,380 KB
testcase_15 AC 3 ms
4,380 KB
testcase_16 AC 3 ms
4,376 KB
testcase_17 AC 3 ms
4,380 KB
testcase_18 AC 3 ms
4,380 KB
testcase_19 AC 3 ms
4,380 KB
testcase_20 AC 3 ms
4,376 KB
testcase_21 AC 3 ms
4,376 KB
testcase_22 AC 3 ms
4,376 KB
testcase_23 AC 3 ms
4,376 KB
testcase_24 AC 3 ms
4,376 KB
testcase_25 AC 3 ms
4,376 KB
testcase_26 AC 3 ms
4,380 KB
testcase_27 AC 333 ms
5,912 KB
testcase_28 AC 330 ms
5,904 KB
testcase_29 AC 353 ms
6,340 KB
testcase_30 AC 346 ms
6,172 KB
testcase_31 AC 331 ms
5,952 KB
testcase_32 AC 332 ms
6,208 KB
testcase_33 AC 330 ms
6,160 KB
testcase_34 AC 344 ms
6,156 KB
testcase_35 AC 344 ms
6,528 KB
testcase_36 AC 331 ms
6,216 KB
testcase_37 AC 341 ms
6,012 KB
testcase_38 AC 354 ms
6,488 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
//#include <atcoder/all>
//using namespace atcoder;
using ll=long long;
using Graph=vector<vector<int>>;
#define MAX 1000000
#define MOD 1000000007
//#define INF 1000000000
#define INF 1000000000000000000

vector<int> parent;
int find(int x){
  int y=parent[x];
  if(y!=parent[y]){
    y=find(y);
  }
  return parent[x]=y;
}
void unite(int a,int b){
  int x=find(a);
  int y=find(b);
  if(x!=y){
    parent[y]=x;
  }
}

int main(){
  int N,A,B;
  cin>>N>>A>>B;
  vector<int> x(N);
  for(int i=0;i<N;i++){
    cin>>x[i];
  }
  vector<int> sum(N+1,0);
  parent.resize(N);
  iota(parent.begin(),parent.end(),0);
  for(int i=0;i<N;i++){
    int k=lower_bound(x.begin(),x.end(),x[i]+A)-x.begin();
    if(k==N){
      continue;
    }
    if(x[k]-x[i]<=B){
      unite(i,k);
      sum[k]++;
      k=upper_bound(x.begin(),x.end(),x[i]+B)-x.begin();
      k--;
      sum[k]--;
    }
  }

  for(int i=1;i<N;i++){
    sum[i]+=sum[i-1];
  }
  for(int i=0;i<N-1;i++){
    if(sum[i]>0){
      unite(i,i+1);
    }
  }

  vector<int> cnt(N,0);
  for(int i=0;i<N;i++){
    cnt[find(i)]++;
  }
  for(int i=0;i<N;i++){
    cout<<cnt[find(i)]<<endl;
  }
}
0