結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
権限があれば一括ダウンロードができます

ソースコード

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