結果

問題 No.1170 Never Want to Walk
ユーザー tokusakuraitokusakurai
提出日時 2020-08-14 21:42:51
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 357 ms / 2,000 ms
コード長 2,342 bytes
コンパイル時間 2,225 ms
コンパイル使用メモリ 198,188 KB
実行使用メモリ 6,656 KB
最終ジャッジ日時 2024-04-18 21:20:04
合計ジャッジ時間 8,043 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 2 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 2 ms
5,376 KB
testcase_08 AC 1 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 3 ms
5,376 KB
testcase_13 AC 3 ms
5,376 KB
testcase_14 AC 3 ms
5,376 KB
testcase_15 AC 3 ms
5,376 KB
testcase_16 AC 3 ms
5,376 KB
testcase_17 AC 3 ms
5,376 KB
testcase_18 AC 4 ms
5,376 KB
testcase_19 AC 3 ms
5,376 KB
testcase_20 AC 3 ms
5,376 KB
testcase_21 AC 3 ms
5,376 KB
testcase_22 AC 4 ms
5,376 KB
testcase_23 AC 3 ms
5,376 KB
testcase_24 AC 3 ms
5,376 KB
testcase_25 AC 3 ms
5,376 KB
testcase_26 AC 3 ms
5,376 KB
testcase_27 AC 332 ms
6,272 KB
testcase_28 AC 330 ms
6,400 KB
testcase_29 AC 348 ms
6,400 KB
testcase_30 AC 350 ms
6,528 KB
testcase_31 AC 344 ms
6,144 KB
testcase_32 AC 335 ms
6,528 KB
testcase_33 AC 343 ms
6,400 KB
testcase_34 AC 351 ms
6,528 KB
testcase_35 AC 347 ms
6,272 KB
testcase_36 AC 340 ms
6,144 KB
testcase_37 AC 341 ms
6,400 KB
testcase_38 AC 357 ms
6,656 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
const ld EPS = 1e-10;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

struct Union_Find_Tree{
    vector<int> par, rank, num;
    
    Union_Find_Tree(int N){
        par.assign(N, -1);
        rank.assign(N, 0);
        num.assign(N, 1);
    }
    
    int root(int x){
        if(par[x] < 0 || par[x] == x) return x;
        return par[x] = root(par[x]);
    }
    
    bool unite(int x, int y){
        x = root(x), y = root(y);
        if(x == y) return false;
        if(rank[x] < rank[y]) swap(x, y);
        if(rank[x] == rank[y]) rank[x]++;
        par[y] = x, num[x] += num[y];
        return true;
    }
    
    int size(int x) {return num[root(x)];}
    
    bool same(int x, int y){
        return root(x) == root(y);
    }
    
    void clear(){
        fill(par.begin(), par.end(), -1);
        fill(rank.begin(), rank.end(), 0);
        fill(num.begin(), num.end(), 1);
    }
};

int main(){
    int N, A, B;
    cin >> N >> A >> B;
    int x[N];
    rep(i, N) cin >> x[i];
    int pos1 = 0, pos2 = 0;
    Union_Find_Tree uf(N);
    rep(i, N){
        int nxt1 = pos1, nxt2 = pos2;
        while(nxt1 < N && x[nxt1]-x[i] < A) nxt1++;
        while(nxt2 < N && x[nxt2]-x[i] <= B) nxt2++;
        if(nxt1 == nxt2){
            pos1 = nxt1, pos2 = nxt2;
            continue;
        }
        if(nxt1 < N) uf.unite(i, nxt1);
        if(nxt1 >= pos2){
            rep2(i, nxt1, nxt2-2) uf.unite(i, i+1);
        }
        else{
            rep2(i, pos2-1, nxt2-2) uf.unite(i, i+1);
        }
        pos1 = nxt1, pos2 = nxt2;
    }
    rep(i, N) cout << uf.size(i) << endl;
}
0