結果
| 問題 |
No.2889 Rusk
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-09-13 22:54:19 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 117 ms / 2,000 ms |
| コード長 | 1,629 bytes |
| コンパイル時間 | 2,906 ms |
| コンパイル使用メモリ | 203,136 KB |
| 最終ジャッジ日時 | 2025-02-24 08:07:43 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 52 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int N; cin >> N;
vector<long long> A(N),B = A,C = A;
for(auto &a : A) cin >> a;
for(auto &a : B) cin >> a;
for(auto &a : C) cin >> a;
long long inf = 1e18;
vector<vector<long long>> dp(3,vector<long long>(3,-inf));
dp.at(0).at(0) = 0;
auto chmax = [&](auto &a,auto b) -> void {a = max(a,b);};
for(int i=0; i<N; i++){
long long a = A.at(i),b = B.at(i),c = C.at(i);
vector<vector<long long>> next(3,vector<long long>(3,-inf));
for(int i=0; i<3; i++){
for(int k=0; k<3; k++){
if(dp.at(i).at(k) == inf) continue;
if(i == 0){
chmax(next.at(i).at(k),dp.at(i).at(k)+a);
if(k < 1) chmax(next.at(i+2).at(k+2),dp.at(i).at(k)+c);
if(k < 2) chmax(next.at(i+1).at(k+1),dp.at(i).at(k)+b);
}
else if(i == 1){
chmax(next.at(1).at(k),dp.at(i).at(k)+b);
chmax(next.at(0).at(k),dp.at(i).at(k)+a);
if(k < 2) chmax(next.at(2).at(k+1),dp.at(i).at(k)+c);
}
else{
chmax(next.at(2).at(k),dp.at(i).at(k)+c);
chmax(next.at(1).at(k),dp.at(i).at(k)+b);
chmax(next.at(0).at(k),dp.at(i).at(k)+a);
}
}
}
swap(dp,next);
}
long long answer = 0;
for(auto &h : dp) for(auto &w : h) answer = max(answer,w);
cout << answer << endl;
}