結果
問題 | No.1368 サイクルの中に眠る門松列 |
ユーザー | shu8Cream |
提出日時 | 2021-01-30 00:36:49 |
言語 | C++17 (gcc 13.2.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 40 ms / 2,000 ms |
コード長 | 1,182 bytes |
コンパイル時間 | 1,952 ms |
コンパイル使用メモリ | 203,264 KB |
実行使用メモリ | 6,296 KB |
最終ジャッジ日時 | 2023-09-09 18:06:41 |
合計ジャッジ時間 | 3,685 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
4,376 KB |
testcase_01 | AC | 2 ms
4,380 KB |
testcase_02 | AC | 37 ms
4,380 KB |
testcase_03 | AC | 8 ms
4,376 KB |
testcase_04 | AC | 14 ms
4,376 KB |
testcase_05 | AC | 38 ms
6,184 KB |
testcase_06 | AC | 38 ms
6,112 KB |
testcase_07 | AC | 37 ms
6,220 KB |
testcase_08 | AC | 38 ms
6,180 KB |
testcase_09 | AC | 40 ms
6,284 KB |
testcase_10 | AC | 40 ms
6,244 KB |
testcase_11 | AC | 40 ms
6,204 KB |
testcase_12 | AC | 40 ms
6,220 KB |
testcase_13 | AC | 39 ms
6,296 KB |
testcase_14 | AC | 39 ms
6,212 KB |
testcase_15 | AC | 39 ms
6,120 KB |
ソースコード
/** * author: shu8Cream * created: 29.01.2021 20:56:35 **/ #include <bits/stdc++.h> using namespace std; #define rep(i,n) for (int i=0; i<(n); i++) #define all(x) (x).begin(), (x).end() using ll = long long; using P = pair<int,int>; using vi = vector<int>; using vvi = vector<vi>; bool isKM(vector<ll> a){ if(a[0]==a[1] || a[1]==a[2] || a[2]==a[0]) return false; if(max({a[0],a[1],a[2]})==a[1] || min({a[0],a[1],a[2]})==a[1]){ return true; } return false; } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int t; cin >> t; while(t--){ int n; cin >> n; vector<ll> a(n); rep(i,n) cin >> a[i]; ll ans = 0; rep(i,3){ vector<ll> dp(n+1); rep(j,n){ dp[j+1]=max(dp[j+1],dp[j]); if(j+3<n+1){ if(isKM({a[j],a[j+1],a[j+2]})){ dp[j+3]=max(dp[j+1],dp[j]+a[j]); } } } ans=max(ans, dp.back()); ll t = a.back(); a.pop_back(); a.insert(a.begin(),t); } cout << ans << endl; } }