結果

問題 No.1170 Never Want to Walk
ユーザー hamrayhamray
提出日時 2020-08-15 11:17:32
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 605 ms / 2,000 ms
コード長 2,490 bytes
コンパイル時間 1,858 ms
コンパイル使用メモリ 177,232 KB
実行使用メモリ 47,104 KB
最終ジャッジ日時 2024-04-18 23:55:37
合計ジャッジ時間 10,480 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 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 4 ms
5,376 KB
testcase_13 AC 4 ms
5,376 KB
testcase_14 AC 4 ms
5,376 KB
testcase_15 AC 4 ms
5,376 KB
testcase_16 AC 4 ms
5,376 KB
testcase_17 AC 4 ms
5,376 KB
testcase_18 AC 4 ms
5,376 KB
testcase_19 AC 4 ms
5,376 KB
testcase_20 AC 4 ms
5,376 KB
testcase_21 AC 4 ms
5,376 KB
testcase_22 AC 4 ms
5,376 KB
testcase_23 AC 4 ms
5,376 KB
testcase_24 AC 4 ms
5,376 KB
testcase_25 AC 4 ms
5,376 KB
testcase_26 AC 4 ms
5,376 KB
testcase_27 AC 542 ms
25,344 KB
testcase_28 AC 531 ms
24,832 KB
testcase_29 AC 556 ms
25,216 KB
testcase_30 AC 544 ms
25,088 KB
testcase_31 AC 545 ms
24,960 KB
testcase_32 AC 533 ms
45,056 KB
testcase_33 AC 508 ms
44,928 KB
testcase_34 AC 605 ms
46,080 KB
testcase_35 AC 529 ms
46,336 KB
testcase_36 AC 541 ms
45,056 KB
testcase_37 AC 584 ms
45,312 KB
testcase_38 AC 569 ms
47,104 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
 
const double pi = 3.141592653589793238462643383279;
using namespace std;
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
 
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SQ(a) ((a)*(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
 
 
//repetition
//------------------------------------------
#define FOR(i,s,n) for(int i=s;i<(int)n;++i)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007
 
 
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
 
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
 
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)

#define EPS 1e-10
//ここから編集
int N, A, B; 
bool visited[200010];
vector<ll> x;
int group[200010];
map<int, int> mp;
vector<int> ababa;
int ans[200010];
int cnt = 0;
set<int> st;
void dfs(int v, int p, int k){
  group[v] = k;
  cnt++;
  visited[v] = true;
  st.erase(x[v]);
  
  {
    auto itr = st.upper_bound(x[v]+A-1);

    while((itr = st.upper_bound(x[v]+A-1)) != st.end() && x[mp[*itr]] - x[v] <= B){
      int idx = mp[*itr];
      dfs(idx, v, k);
    }  
  }

  {
    auto itr = st.upper_bound(x[v]-B-1);
    while((itr = st.upper_bound(x[v]-B-1)) != st.end() && A<=abs(x[mp[*itr]]-x[v]) && abs(x[mp[*itr]] - x[v]) <= B){
      int idx = mp[*itr];
      dfs(idx, v, k);
    }  
  }
  
  
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(6);

  cin >> N >> A >> B;

  x.resize(N);
  REP(i,N) cin >> x[i], mp[x[i]] = i;
  REP(i,N) st.insert(x[i]);

  int k = 0;
  for(int i=0; i<N; i++){
    if(visited[i]) continue;
    dfs(i, -1, k);
    ababa.push_back(cnt);
    //cout << i << " " << cnt << endl;
    k++;
    cnt = 0;
  }
  
  for(int i=0; i<N; i++) ans[i] = ababa[group[i]];

  for(int i=0; i<N; i++) cout << ans[i] << endl;
  return 0;
}
0