結果
問題 | No.1368 サイクルの中に眠る門松列 |
ユーザー | shu8Cream |
提出日時 | 2021-01-30 09:23:45 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 33 ms / 2,000 ms |
コード長 | 1,134 bytes |
コンパイル時間 | 2,347 ms |
コンパイル使用メモリ | 202,788 KB |
実行使用メモリ | 6,280 KB |
最終ジャッジ日時 | 2023-09-10 05:34:41 |
合計ジャッジ時間 | 3,590 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,380 KB |
testcase_01 | AC | 2 ms
4,376 KB |
testcase_02 | AC | 33 ms
4,380 KB |
testcase_03 | AC | 7 ms
4,376 KB |
testcase_04 | AC | 12 ms
4,376 KB |
testcase_05 | AC | 28 ms
6,248 KB |
testcase_06 | AC | 27 ms
6,132 KB |
testcase_07 | AC | 27 ms
6,148 KB |
testcase_08 | AC | 27 ms
6,252 KB |
testcase_09 | AC | 27 ms
6,260 KB |
testcase_10 | AC | 27 ms
6,244 KB |
testcase_11 | AC | 27 ms
6,168 KB |
testcase_12 | AC | 27 ms
6,164 KB |
testcase_13 | AC | 27 ms
6,244 KB |
testcase_14 | AC | 27 ms
6,252 KB |
testcase_15 | AC | 27 ms
6,280 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(ll a, ll b, ll c){ if(a==b || b==c || c==a) return false; if(max({a,b,c})==b || min({a,b,c})==b){ 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<n-2){ 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[n]); ll t = a[n-1]; a.pop_back(); a.insert(a.begin(),t); } cout << ans << endl; } }