結果

問題 No.1950 片道きゃっちぼーる
ユーザー take000take000
提出日時 2022-05-20 23:54:36
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,232 bytes
コンパイル時間 2,141 ms
コンパイル使用メモリ 206,800 KB
実行使用メモリ 26,700 KB
最終ジャッジ日時 2023-10-20 14:51:16
合計ジャッジ時間 7,120 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 114 ms
26,700 KB
testcase_04 AC 115 ms
26,700 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 107 ms
26,700 KB
testcase_07 AC 84 ms
7,956 KB
testcase_08 AC 87 ms
7,956 KB
testcase_09 WA -
testcase_10 AC 95 ms
7,956 KB
testcase_11 AC 92 ms
7,956 KB
testcase_12 AC 90 ms
7,956 KB
testcase_13 AC 107 ms
7,956 KB
testcase_14 AC 104 ms
7,956 KB
testcase_15 WA -
testcase_16 AC 111 ms
17,196 KB
testcase_17 AC 2 ms
4,348 KB
testcase_18 AC 97 ms
7,956 KB
testcase_19 WA -
testcase_20 AC 89 ms
7,956 KB
testcase_21 WA -
testcase_22 AC 98 ms
7,956 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);
    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];
    };

    rep(i, N) calc(calc, i);
    rep(i, N) seen[i] = false;
    rep(i, N) calc(calc, N - i - 1);

    for (ll a : ans)
        cout << a << "\n";

    return 0;
}

0