結果

問題 No.1170 Never Want to Walk
ユーザー hedwig100hedwig100
提出日時 2020-08-14 21:54:48
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,475 bytes
コンパイル時間 1,685 ms
コンパイル使用メモリ 169,468 KB
実行使用メモリ 5,632 KB
最終ジャッジ日時 2024-04-18 21:39:39
合計ジャッジ時間 5,036 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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>
#define rep(i,n) for (int i = 0; i < (int)(n); i ++)
#define irep(i,n) for (int i = (int)(n) - 1;i >= 0;--i)
using namespace std;
using ll = long long;
using PL = pair<ll,ll>;
using P = pair<int,int>;
constexpr int INF = 1000000000;
constexpr long long HINF = 1000000000000000;
constexpr long long MOD = 1000000007;// = 998244353;
constexpr double EPS = 1e-4;
constexpr double PI = 3.14159265358979;

struct UnionFind {
    int N;
    vector<int> parents;

    UnionFind(int _N) : N(_N){
        parents.assign(N,-1);
    }

    int find(int x) { //xの親を返す
        if (parents[x] < 0) return x;
        return parents[x] = find(parents[x]);
    }
    
    void unite(int x, int y) {  //xとyの含むグループを併合
        int px = find(x);
        int py = find(y);
        if (parents[px] > parents[py]) swap(px,py); 
        if (px != py) {
            parents[px] += parents[py];
            parents[py] = px;
        }     
    }

    bool same(int x, int y) { //x,yが同じグループにいるか判定
        return find(x) == find(y);
    }

    int size(int x) { //xと同じグループのメンバーの個数
        return -parents[find(x)];
    }
    
    vector<int> root() {//ufの根を列挙
        vector<int> res;
        for (int i = 0; i < N; i ++) {
            if (parents[i] < 0) res.push_back(i);
        }
        return res;
    }

    int group_count() { //ufのグループの数を数える
        int cnt = 0;
        for (int i = 0; i < N; i ++) {
            if (parents[i] < 0) cnt ++;
        }
        return cnt;
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int N; 
    ll A,B; cin >> N >> B >> A;
    vector<ll> X(N);
    rep(i,N) cin >> X[i];
    
    UnionFind uf(N);
    rep(i,N) {
        int l = lower_bound(X.begin(),X.end(),X[i] - A) - X.begin();
        if (l < N && X[l] <= X[i] - B) uf.unite(i,l);
        int r = lower_bound(X.begin(),X.end(),X[i] + B) - X.begin();
        if (r < N && X[r] <= X[i] + A) uf.unite(i,r);
        cout << l << ' ' << r << '\n';
    }
    rep(i,N - 1) {
        int l = lower_bound(X.begin(),X.end(),X[i + 1] - A) - X.begin();
        if (l < N && X[l] <= X[i] - B) uf.unite(i,i + 1);
        int r = lower_bound(X.begin(),X.end(),X[i + 1] + B) - X.begin();
        if (r < N && X[r] <= X[i] + A) uf.unite(i,i + 1);
        cout << l << ' ' << r << '\n';
    }
    rep(i,N) cout << uf.size(i) << '\n';
    return 0;
}
0