結果
| 問題 |
No.2889 Rusk
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-07-03 14:37:53 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 282 ms / 2,000 ms |
| コード長 | 1,156 bytes |
| コンパイル時間 | 3,368 ms |
| コンパイル使用メモリ | 247,460 KB |
| 実行使用メモリ | 7,936 KB |
| 最終ジャッジ日時 | 2024-07-05 21:12:11 |
| 合計ジャッジ時間 | 12,385 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 52 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1LL << 60;
int main() {
ll n; cin >> n;
vector<ll> a(n), b(n), c(n);
for (size_t i=0; i<n; i++) cin >> a[i];
for (size_t i=0; i<n; i++) cin >> b[i];
for (size_t i=0; i<n; i++) cin >> c[i];
vector<ll> dp(9, -INF);
dp[0] = 0;
for (size_t i=0; i<n; i++) {
vector<ll> dpn(9, -INF);
for (size_t j=0; j<9; j++) {
if (dp[j] == -INF) continue;
ll t1 = j / 3;
ll t2 = j % 3;
for (ll add1=0; add1<2; add1++) for (ll add2=0; add2<2; add2++) {
if (t1+add1 > 2 || t2+add2 > 2) continue;
ll t1n = t1 + add1;
ll t2n = t2 + add2;
ll taste;
if (t1n == 1 && t2n == 1) taste = c[i];
else if (t1n != 1 && t2n != 1) taste = a[i];
else taste = b[i];
dpn[t1n*3+t2n] = max(dpn[t1n*3+t2n], dp[j] + taste);
}
}
swap(dp, dpn);
}
ll ans = -INF;
for (size_t i=0; i<9; i++) ans = max(ans, dp[i]);
cout << ans << endl;
return 0;
}