結果

問題 No.1950 片道きゃっちぼーる
ユーザー take000take000
提出日時 2022-05-20 23:22:55
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,081 bytes
コンパイル時間 2,028 ms
コンパイル使用メモリ 206,488 KB
実行使用メモリ 26,652 KB
最終ジャッジ日時 2023-10-20 14:15:06
合計ジャッジ時間 6,084 ms
ジャッジサーバーID
(参考情報)
judge15 / 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 97 ms
26,652 KB
testcase_04 WA -
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 89 ms
26,652 KB
testcase_07 AC 74 ms
7,908 KB
testcase_08 AC 75 ms
7,908 KB
testcase_09 WA -
testcase_10 AC 81 ms
7,908 KB
testcase_11 AC 77 ms
7,908 KB
testcase_12 AC 76 ms
7,908 KB
testcase_13 AC 86 ms
7,908 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 91 ms
17,148 KB
testcase_17 AC 1 ms
4,348 KB
testcase_18 AC 81 ms
7,908 KB
testcase_19 WA -
testcase_20 AC 77 ms
7,908 KB
testcase_21 WA -
testcase_22 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
typedef long long ll;
using namespace std;

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

    int N;
    cin >> N;
    vector<ll> X(N + 1), A(N + 1);
    rep(i, N) cin >> X[i];
    rep(i, N) cin >> A[i];
    X[N] = 1e18, A[N] = 0;

    vector<bool> seen(N);
    vector<ll> ans(N);
    rep(i, N) {
        auto calc = [&](auto &&self, int idx) -> ll {
            if (seen[idx]) return ans[idx];

            seen[idx] = true;

            ans[idx] = A[idx];
            auto rid = lower_bound(X.begin(), X.end(), X[idx] + A[idx]) - X.begin();
            if (X[rid] == X[idx] + A[idx])
                ans[idx] = max(ans[idx], A[idx] + self(self, rid));

            auto lid = lower_bound(X.begin(), X.end(), X[idx] - A[idx]) - X.begin();
            if (X[lid] == X[idx] - A[idx])
                ans[idx] = max(ans[idx], -A[idx] + self(self, lid));

            return ans[idx];
        };

        calc(calc, i);
    }
    for (ll a : ans)
        cout << a << "\n";

    return 0;
}
0