結果
| 問題 |
No.1368 サイクルの中に眠る門松列
|
| コンテスト | |
| ユーザー |
mmn15277198
|
| 提出日時 | 2021-01-31 13:50:56 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 959 bytes |
| コンパイル時間 | 813 ms |
| コンパイル使用メモリ | 73,984 KB |
| 実行使用メモリ | 7,940 KB |
| 最終ジャッジ日時 | 2024-06-28 22:35:35 |
| 合計ジャッジ時間 | 2,242 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 1 WA * 14 |
ソースコード
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long;
ll kado(int a , int b , int c){
if(a == b || b == c || c == a){
return 0;
}
if(b < a && b < c){
return a;
}
if(b > a && b > c){
return a;
}
return 0;
}
void solve(){
int n;
cin >> n;
vector<ll> a(n);
for(int i = 0; i < n; i++){
cin >> a[i];
}
a.push_back(a[0]);
a.push_back(a[1]);
vector<ll> KadoTable(n + 2 , 0);
KadoTable[0] = 0;
KadoTable[1] = 0;
for(int i = 2; i < n + 2; i++){
KadoTable[i] = kado(a[i - 2] , a[i - 1] , a[i]);
}
vector<ll> dp(n + 2 , 0);
dp[0] = KadoTable[0];
dp[1] = KadoTable[1];
dp[2] = KadoTable[2];
for(int i = 3; i < n + 2; i++){
dp[i] = max(KadoTable[i] + KadoTable[i - 3] , KadoTable[i - 1]);
}
cout << dp[n + 1] << endl;
}
int main() {
int t;
cin >> t;
for(int i = 0; i < t; i++)solve();
return 0;
}
mmn15277198