結果
問題 | No.209 Longest Mountain Subsequence |
ユーザー | kotatsugame |
提出日時 | 2020-03-04 15:10:34 |
言語 | C++14 (gcc 13.2.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 30 ms / 2,000 ms |
コード長 | 976 bytes |
コンパイル時間 | 513 ms |
コンパイル使用メモリ | 67,560 KB |
実行使用メモリ | 4,380 KB |
最終ジャッジ日時 | 2023-08-04 03:11:22 |
合計ジャッジ時間 | 1,220 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge14 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 12 ms
4,376 KB |
testcase_01 | AC | 11 ms
4,376 KB |
testcase_02 | AC | 11 ms
4,380 KB |
testcase_03 | AC | 30 ms
4,376 KB |
testcase_04 | AC | 30 ms
4,376 KB |
testcase_05 | AC | 6 ms
4,380 KB |
コンパイルメッセージ
main.cpp:9:1: 警告: ISO C++ では型の無い ‘main’ の宣言を禁止しています [-Wreturn-type] 9 | main() | ^~~~
ソースコード
#include<iostream> #include<algorithm> #include<utility> using namespace std; int T,N; int A[100]; int dpL[100][100],dpR[100][100]; int L[100],R[100]; main() { cin>>T; for(;T--;) { cin>>N; for(int i=0;i<N;i++)cin>>A[i]; for(int i=0;i<N;i++) { for(int j=0;j<=i;j++)dpL[i][j]=1.5e9; dpL[i][0]=0; int ret=0; for(int j=0;j<i;j++) { if(A[j]>=A[i])continue; for(int k=0;k<=j;k++) { if(dpL[j][k]<A[i]-A[j]) { dpL[i][k+1]=min(dpL[i][k+1],A[i]-A[j]); if(ret<k+1)ret=k+1; } } } L[i]=ret; } for(int i=N;i--;) { for(int j=0;j<=N-i-1;j++)dpR[i][j]=1.5e9; dpR[i][0]=0; int ret=0; for(int j=N;--j>i;) { if(A[j]>=A[i])continue; for(int k=0;k<=N-j-1;k++) { if(dpR[j][k]<A[i]-A[j]) { dpR[i][k+1]=min(dpR[i][k+1],A[i]-A[j]); if(ret<k+1)ret=k+1; } } } R[i]=ret; } int ans=0; for(int i=0;i<N;i++)ans=max(ans,L[i]+R[i]+1); cout<<ans<<endl; } }