結果

問題 No.1950 片道きゃっちぼーる
ユーザー MazesobaMazesoba
提出日時 2022-05-25 06:37:20
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,143 ms / 3,000 ms
コード長 1,640 bytes
コンパイル時間 4,892 ms
コンパイル使用メモリ 274,460 KB
実行使用メモリ 65,804 KB
最終ジャッジ日時 2023-10-20 19:05:44
合計ジャッジ時間 20,944 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 668 ms
65,804 KB
testcase_04 AC 651 ms
65,804 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 654 ms
65,804 KB
testcase_07 AC 634 ms
47,060 KB
testcase_08 AC 802 ms
47,060 KB
testcase_09 AC 662 ms
57,356 KB
testcase_10 AC 598 ms
39,464 KB
testcase_11 AC 598 ms
26,848 KB
testcase_12 AC 583 ms
37,332 KB
testcase_13 AC 659 ms
51,548 KB
testcase_14 AC 683 ms
53,396 KB
testcase_15 AC 1,142 ms
61,580 KB
testcase_16 AC 678 ms
59,468 KB
testcase_17 AC 2 ms
4,372 KB
testcase_18 AC 673 ms
50,228 KB
testcase_19 AC 1,143 ms
58,412 KB
testcase_20 AC 544 ms
25,984 KB
testcase_21 AC 669 ms
51,284 KB
testcase_22 AC 644 ms
51,284 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>

using namespace std;

//#define DISABLE_PRINT

#if defined(ENABLE_PRINT) && !defined(DISABLE_PRINT)

#define P(...) fprintf(stderr, __VA_ARGS__)
#define P2(fmt) fprintf(stderr, fmt)
#define LP fprintf(stderr, "L: %d\n", __LINE__)

#else

#define P(...) ((void)0)
#define P2(fmt) ((void)0)
#define LP ((void)0)

#endif

#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define ALL(x) x.begin(),x.end()

using ll = long long;
using ull = unsigned long long;

int main(int, const char**)
{
    int N; cin >> N;
    vector<vector<int>> g(N);
    vector<ll> X(N), A(N);
    map<ll, int> posToIdx;
    map<ll, vector<int>> distToIdx;
    rep(i, N) {
        cin >> X[i];
        posToIdx[X[i]] = i;
    }
    rep(i, N) cin >> A[i];
    rep(i, N) {
        auto d0 = X[i] + A[i];
        if(posToIdx.find(d0) != posToIdx.end()) {
            g[posToIdx[d0]].push_back(i);
        }
        distToIdx[d0].push_back(i);

        auto d1 = X[i] - A[i];
        if(posToIdx.find(d1) != posToIdx.end()) {
            g[posToIdx[d1]].push_back(i);
        }
    }

    vector<ll> ans(N, -1);
    function<void(int, ll)> f = [&](int x, ll d) {
        if(ans[x] != -1) return;
        ans[x] = d;
        assert(ans[x] >= X[x]);
        for(auto nx : g[x]) {
            f(nx, d);
        }
    };

    for(auto itr = distToIdx.rbegin(); itr != distToIdx.rend(); ++itr) {
        auto& l = itr->second;
        for(auto idx : l) {
            f(idx, itr->first);
        }
    }

    rep(i, N) {
        auto a = ans[i] - X[i];
        assert(a >= 0);
        cout << a << endl;
    }

    return 0;
}
0