結果
問題 | No.1368 サイクルの中に眠る門松列 |
ユーザー | kotatsugame |
提出日時 | 2021-01-29 21:37:28 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 71 ms / 2,000 ms |
コード長 | 470 bytes |
コンパイル時間 | 490 ms |
コンパイル使用メモリ | 66,892 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-06-27 07:48:25 |
合計ジャッジ時間 | 2,061 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 15 |
コンパイルメッセージ
main.cpp:6:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type] 6 | main() | ^~~~
ソースコード
#include<iostream> #include<algorithm> using namespace std; int T,N; int A[2<<17]; main() { cin>>T; for(;T--;) { cin>>N; for(int i=0;i<N;i++)cin>>A[i]; long ans=0; for(int i=0;i<3;i++) { long dp[3]={}; for(int j=0;j<N;j++) { dp[(j+1)%3]=max(dp[(j+1)%3],dp[j%3]); if(j+3<=N) { int x=A[i+j],y=A[(i+j+1)%N],z=A[(i+j+2)%N]; if((x<y&&y>z||x>y&&y<z)&&x!=z)dp[j%3]+=x; } } ans=max(ans,dp[N%3]); } cout<<ans<<endl; } }