結果

問題 No.1950 片道きゃっちぼーる
ユーザー ruthenruthen
提出日時 2022-05-21 01:23:42
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 436 ms / 3,000 ms
コード長 1,484 bytes
コンパイル時間 2,833 ms
コンパイル使用メモリ 223,728 KB
実行使用メモリ 33,164 KB
最終ジャッジ日時 2023-10-20 15:25:47
合計ジャッジ時間 10,108 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 209 ms
32,900 KB
testcase_04 AC 208 ms
32,900 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 229 ms
32,900 KB
testcase_07 AC 177 ms
26,564 KB
testcase_08 AC 218 ms
26,564 KB
testcase_09 AC 218 ms
32,900 KB
testcase_10 AC 199 ms
27,868 KB
testcase_11 AC 222 ms
28,272 KB
testcase_12 AC 179 ms
28,272 KB
testcase_13 AC 235 ms
31,052 KB
testcase_14 AC 251 ms
32,900 KB
testcase_15 AC 418 ms
32,900 KB
testcase_16 AC 237 ms
32,900 KB
testcase_17 AC 2 ms
4,348 KB
testcase_18 AC 207 ms
29,732 KB
testcase_19 AC 436 ms
32,900 KB
testcase_20 AC 188 ms
26,564 KB
testcase_21 AC 248 ms
33,164 KB
testcase_22 AC 241 ms
32,900 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#ifdef _RUTHEN
#include "debug.hpp"
#else
#define show(...) true
#endif

using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
template <class T> using V = vector<T>;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;
    cin >> N;
    V<ll> X(N), A(N);
    rep(i, N) cin >> X[i];
    rep(i, N) cin >> A[i];
    map<ll, int> mp;
    rep(i, N) mp[X[i]] = i;
    V<V<int>> G(N);
    rep(i, N) {
        if (mp.count(X[i] + A[i])) {
            // i -> mp[X[i] + A[i]] に行ける
            G[mp[X[i] + A[i]]].push_back(i);
        }
        if (mp.count(X[i] - A[i])) {
            G[mp[X[i] - A[i]]].push_back(i);
        }
    }
    V<ll> ans(N);
    rep(i, N) ans[i] = X[i] + A[i];
    V<int> seen(N, 0);
    V<int> ind(N);
    iota(ind.begin(), ind.end(), 0);
    sort(ind.begin(), ind.end(), [&](int i, int j) { return ans[i] < ans[j]; });
    for (int i = N - 1; i >= 0; i--) {
        int cv = ind[i];
        if (seen[cv]) continue;
        queue<int> que;
        que.push(cv);
        while (!que.empty()) {
            int v = que.front();
            que.pop();
            if (seen[v]) continue;
            seen[v] = 1;
            for (auto nx : G[v]) {
                ans[nx] = max(ans[nx], ans[v]);
                if (seen[nx] == 0) {
                    que.push(nx);
                }
            }
        }
    }
    rep(i, N) cout << ans[i] - X[i] << '\n';
    return 0;
}
0