結果

問題 No.1170 Never Want to Walk
ユーザー carrot46carrot46
提出日時 2020-08-14 22:12:37
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,167 bytes
コンパイル時間 1,954 ms
コンパイル使用メモリ 173,100 KB
実行使用メモリ 18,352 KB
最終ジャッジ日時 2024-04-18 22:03:27
合計ジャッジ時間 8,462 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 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 WA -
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 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 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 4 ms
5,376 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 AC 373 ms
16,756 KB
testcase_33 AC 376 ms
16,564 KB
testcase_34 AC 386 ms
17,248 KB
testcase_35 AC 380 ms
16,952 KB
testcase_36 AC 372 ms
16,716 KB
testcase_37 AC 389 ms
16,868 KB
testcase_38 AC 392 ms
17,308 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,Q,K,A,B;
string S;
//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
typedef pair<ll, ll> P;
const ll INF = (1LL<<58);


int main(){
    class union_find{
            vector<long> parent, tree_size;
    public:
            union_find(unsigned long _n) : parent(_n), tree_size(_n, 1){
                for(unsigned long i = 0; i < _n; ++i)parent[i] = i;
            }
            ll find(ll x){
                while(parent[x] != x)x = parent[x] = parent[parent[x]];
                return x;
            }
            void merge(ll a, ll b){
                a = find(a);
                b = find(b);
    	    if(a==b) return;
                if(tree_size[a] < tree_size[b])swap(a, b);
                tree_size[a] += tree_size[b];
                parent[b] = a;
                return;
            }
    	bool same(ll a, ll b){
    	    a = find(a);
    	    b = find(b);
    	    return a == b;
    	}
    	ll get_size(ll a){
                return tree_size[find(a)];
            }
        };
    //uf.mergeのように使う
    //ufはMAX_N+1でとるか、代入時に0-indexedにする
    cin>>N>>A>>B;
    union_find uf(N + 10);
    vec a(N);
    rep(i,N) cin>>a[i];
    a.push_back(ll(3e+9));
    set<int> valid;
    rep(i,N + 1) valid.insert(i);
    auto ite_l = valid.begin(), ite_r = valid.begin();
    ++ite_r;
    auto last = ite_r;
    while(*ite_l < N){
        //cout<<*ite_l<<' '<<*ite_r<<endl;
        if(a[*ite_r] - a[*ite_l] < A){
            last = ++ite_r;
        }else if(a[*ite_r] - a[*ite_l] <= B){
            uf.merge(*ite_l, *ite_r);
            if(last != ite_r) valid.erase(last);
            last = ite_r++;
        }else{
            ++ite_l;
            ite_r = ite_l;
            last = ++ite_r;
        }
    }
    rep(i,N){
        cout<<uf.get_size(i)<<endl;
    }
}
0