結果

問題 No.1950 片道きゃっちぼーる
ユーザー umimelumimel
提出日時 2022-05-21 00:55:55
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,645 bytes
コンパイル時間 1,753 ms
コンパイル使用メモリ 181,280 KB
実行使用メモリ 25,188 KB
最終ジャッジ日時 2023-10-20 15:21:41
合計ジャッジ時間 13,734 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 497 ms
25,188 KB
testcase_04 AC 495 ms
25,188 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 479 ms
25,188 KB
testcase_07 AC 494 ms
25,188 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 545 ms
25,188 KB
testcase_12 AC 514 ms
25,188 KB
testcase_13 AC 489 ms
25,188 KB
testcase_14 AC 508 ms
25,188 KB
testcase_15 WA -
testcase_16 AC 501 ms
25,188 KB
testcase_17 WA -
testcase_18 AC 497 ms
25,188 KB
testcase_19 WA -
testcase_20 AC 501 ms
25,188 KB
testcase_21 AC 521 ms
25,188 KB
testcase_22 AC 502 ms
25,188 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
#define drep(i, cc, n) for (ll i = (cc); i <= (n); ++i)
#define rep(i, n) drep(i, 0, n - 1)
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define fi first
#define se second

const ll MOD = 1000000007;
const ll MOD2 = 998244353;
const ll INF = 1LL << 60;
const ll N_MAX = 2e5;

struct UnionFind{
    vector<ll> parent;
    vector<ll> sizes;
    
    UnionFind(ll N) : parent(N), sizes(N, 1){
        rep(i, N) parent[i] = i;
    }
    
    ll root(ll x){
        if (parent[x] == x) return x;
        return parent[x] = root(parent[x]);
    }

    void unite(ll x, ll y){
        ll rx = root(x);
        ll ry = root(y);
        if (rx == ry) return;
        if (sizes[rx] < sizes[ry]) swap(rx, ry);
        sizes[rx] += sizes[ry];
        parent[ry] = rx;
    }

    bool same(ll x, ll y){
        ll rx = root(x);
        ll ry = root(y);
        return rx == ry;
    }

    ll size(ll x){
        return sizes[root(x)];
    }
};

int main(){
    ll n;
    cin >> n;

    vector<ll> x(n), a(n);
    rep(i, n) cin >> x[i];
    rep(i, n) cin >> a[i];

    map<ll, ll> mp;
    UnionFind UT(n);
    rep(i, n) mp[x[i]] = i;
    rep(i, n){
        if(mp.find(x[i]-a[i]) != mp.end()){
            UT.unite(i, mp[x[i]-a[i]]);
        }

        if(mp.find(x[i]+a[i]) != mp.end()){
            UT.unite(i, mp[x[i]+a[i]]);
        }
    }

    vector<ll> d(n, 0);
    rep(i, n){
        d[UT.root(i)] = max(d[UT.root(i)], x[i]+a[i]);
    }

    vector<ll> ans(n);
    rep(i, n) ans[i] = d[UT.root(i)]-x[i];
    rep(i, n) cout << ans[i] << endl;
}
0