結果
| 問題 |
No.2656 XOR Slimes
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-03-01 23:20:26 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,226 bytes |
| コンパイル時間 | 1,041 ms |
| コンパイル使用メモリ | 93,640 KB |
| 実行使用メモリ | 206,372 KB |
| 最終ジャッジ日時 | 2024-09-29 15:09:57 |
| 合計ジャッジ時間 | 4,567 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 4 TLE * 1 -- * 50 |
ソースコード
#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";
}