結果

問題 No.2656 XOR Slimes
ユーザー InTheBloomInTheBloom
提出日時 2024-03-01 23:20:26
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,226 bytes
コンパイル時間 1,000 ms
コンパイル使用メモリ 93,636 KB
実行使用メモリ 206,228 KB
最終ジャッジ日時 2024-03-01 23:20:31
合計ジャッジ時間 4,788 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
13,352 KB
testcase_01 AC 3 ms
6,548 KB
testcase_02 AC 2 ms
6,548 KB
testcase_03 AC 2 ms
6,548 KB
testcase_04 AC 2 ms
6,548 KB
testcase_05 AC 2 ms
6,548 KB
testcase_06 AC 2 ms
6,548 KB
testcase_07 AC 2 ms
6,548 KB
testcase_08 TLE -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
testcase_49 -- -
testcase_50 -- -
testcase_51 -- -
testcase_52 -- -
testcase_53 -- -
testcase_54 -- -
testcase_55 -- -
testcase_56 -- -
testcase_57 -- -
testcase_58 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>

using namespace std;
using ll = long long;

constexpr ll llINF = 1'000'000'000'000'000'000LL;

int main () {
    int N; cin >> N;
    vector<int> X(N);
    for (int i = 0; i < N; i++) cin >> X[i];

    vector<int> A(N);
    for (int i = 0; i < N; i++) cin >> A[i];
    vector<int> A_cum(N+1);
    for (int i = 1; i <= N; i++) {
        A_cum[i] = A_cum[i-1] ^ A[i-1];
    }

    // xorできるなら方がいい。
    // 併合する区間をdpで管理できませんか?

    vector<vector<ll>> dp(N, vector<ll>(N, llINF));
    // dp[l][r] := 区間[l, r]を最適にマージした結果の最小コスト(整数の総和 + 移動コスト総和)

    auto rec = [&](auto self, int l, int r) -> ll {
        if (dp[l][r] < llINF) return dp[l][r];
        if (l == r) return A[l];

        ll res = llINF;

        // どこかでカット
        for (int sp = l; sp <= r-1; sp++) {
            res = min(res, self(self, l, sp) + self(self, sp+1, r));
        }

        // どこにもカットを入れない
        res = min(res, (0LL + X[r] - X[l]) + (A_cum[r+1] ^ A_cum[l]));

        dp[l][r] = res;
        return dp[l][r];
    };

    cout << rec(rec, 0, N-1) << "\n";
}
0