結果
| 問題 |
No.1368 サイクルの中に眠る門松列
|
| コンテスト | |
| ユーザー |
ocvret_
|
| 提出日時 | 2021-01-29 22:09:41 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 961 bytes |
| コンパイル時間 | 1,544 ms |
| コンパイル使用メモリ | 171,620 KB |
| 実行使用メモリ | 5,720 KB |
| 最終ジャッジ日時 | 2024-06-27 08:21:45 |
| 合計ジャッジ時間 | 3,001 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 12 WA * 3 |
ソースコード
#include<bits/stdc++.h>
// #include<atcoder/all>
using namespace std;
// using namespace atcoder;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
#define rep(i,n) for(ll i = 0;i < (ll)n;i++)
#define ALL(x) (x).begin(),(x).end()
#define MOD 1000000007
int main(){
int T;
cin >> T;
while(T--){
int n;cin >> n;
vector<int> a(n);
rep(i,n)cin >> a[i];
rep(i,3)a.push_back(a[i]);
auto solve = [&](int s){
vector<ll> dp(n+10);
for(int i = s+2;i < n+s;i++){
dp[i] = max(dp[i],dp[i-1]);
int k = 0;
if(i-3 >= 0)k = dp[i-3];
if(a[i-2] != a[i-1] && a[i-1] != a[i] && a[i-2] != a[i] && (*min_element(a.begin()+i-2,a.begin()+i+1) == a[i-1] || *max_element(a.begin()+i-2,a.begin()+i+1) == a[i-1])){
dp[i] = max(dp[i],1ll*k + a[i-2]);
}
}
return dp[n+s-1];
};
cout << max({solve(0),solve(1),solve(2)}) << "\n";
}
return 0;
}
ocvret_