結果

問題 No.1950 片道きゃっちぼーる
ユーザー take000take000
提出日時 2022-05-20 23:38:48
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,271 bytes
コンパイル時間 2,013 ms
コンパイル使用メモリ 206,532 KB
実行使用メモリ 26,712 KB
最終ジャッジ日時 2023-10-20 14:34:50
合計ジャッジ時間 6,648 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 114 ms
26,712 KB
testcase_04 AC 81 ms
7,968 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 112 ms
26,712 KB
testcase_07 AC 70 ms
7,968 KB
testcase_08 AC 73 ms
7,968 KB
testcase_09 WA -
testcase_10 AC 76 ms
7,968 KB
testcase_11 AC 72 ms
7,968 KB
testcase_12 AC 70 ms
7,968 KB
testcase_13 AC 94 ms
7,968 KB
testcase_14 AC 106 ms
7,968 KB
testcase_15 WA -
testcase_16 AC 111 ms
17,208 KB
testcase_17 AC 1 ms
4,372 KB
testcase_18 AC 77 ms
7,968 KB
testcase_19 WA -
testcase_20 AC 74 ms
7,968 KB
testcase_21 AC 103 ms
7,968 KB
testcase_22 AC 100 ms
7,968 KB
権限があれば一括ダウンロードができます

ソースコード

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];
        };

        seen[i] = false;
        calc(calc, i);
    }
    for (ll a : ans)
        cout << a << "\n";

    return 0;
}
0