結果
問題 | No.1368 サイクルの中に眠る門松列 |
ユーザー |
![]() |
提出日時 | 2021-01-29 21:50:52 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 74 ms / 2,000 ms |
コード長 | 922 bytes |
コンパイル時間 | 1,607 ms |
コンパイル使用メモリ | 168,532 KB |
実行使用メモリ | 9,600 KB |
最終ジャッジ日時 | 2024-06-27 08:04:20 |
合計ジャッジ時間 | 3,064 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 15 |
ソースコード
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef pair<ll,ll> P; typedef vector<ll> VI; typedef vector<VI> VVI; #define REP(i,n) for(int i=0;i<(n);i++) #define ALL(v) v.begin(),v.end() constexpr ll MOD=1000000007; constexpr ll INF=1e18; bool kad(int a, int b, int c){ if(a==c) return 0; if(a>b&&b<c) return 1; if(a<b&&b>c) return 1; return 0; } int main(){ int t; cin >> t; while(t--){ int n; cin >> n; VI a(n); REP(i,n) cin >> a[i]; ll ans=0; REP(k,3){ VI dp(n*3,0); REP(i,n-2){ dp[k+i+3]=max(dp[k+i+3],dp[k+i+2]); if(kad(a[(k+i)%n],a[(k+i+1)%n],a[(k+i+2)%n])){ dp[k+i+3]=max(dp[k+i+3],dp[k+i]+a[(k+i)%n]); } } ans=max(ans,dp[k+n]); } cout << ans << endl; } return 0; }