結果

問題 No.127 門松もどき
ユーザー chocoruskchocorusk
提出日時 2019-05-24 00:12:58
言語 C++11
(gcc 8.5.0)
結果
AC  
実行時間 121 ms / 5,000 ms
コード長 1,417 bytes
コンパイル時間 730 ms
コンパイル使用メモリ 95,824 KB
実行使用メモリ 100,680 KB
最終ジャッジ日時 2023-07-16 01:48:42
合計ジャッジ時間 3,314 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,456 KB
testcase_01 AC 2 ms
5,464 KB
testcase_02 AC 2 ms
5,568 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 121 ms
100,608 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 18 ms
29,444 KB
testcase_07 AC 3 ms
6,152 KB
testcase_08 AC 3 ms
5,668 KB
testcase_09 AC 3 ms
5,592 KB
testcase_10 AC 2 ms
5,692 KB
testcase_11 AC 4 ms
8,600 KB
testcase_12 AC 71 ms
73,072 KB
testcase_13 AC 86 ms
85,204 KB
testcase_14 AC 82 ms
82,084 KB
testcase_15 AC 106 ms
97,160 KB
testcase_16 AC 80 ms
79,452 KB
testcase_17 AC 86 ms
85,784 KB
testcase_18 AC 75 ms
78,668 KB
testcase_19 AC 50 ms
60,432 KB
testcase_20 AC 51 ms
60,952 KB
testcase_21 AC 29 ms
42,356 KB
testcase_22 AC 120 ms
100,680 KB
testcase_23 AC 113 ms
100,596 KB
testcase_24 AC 100 ms
90,276 KB
testcase_25 AC 111 ms
97,552 KB
testcase_26 AC 63 ms
66,928 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#define popcount __builtin_popcount
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
int n;
int a[3001];
int dp[3001][3001], mx[2][3001][3001];
void solve(int l, int r){
    if(l>=r) return;
    if(dp[l][r]>=0) return;
    solve(l+1, r);
    solve(l, r-1);
    if(a[l]==a[r]){
        dp[l][r]=0;
        mx[0][l][r]=mx[0][l][r-1];
        mx[1][l][r]=mx[1][l+1][r];
    }else if(a[l]<a[r]){
        dp[l][r]=max(2, 1+mx[1][l+1][r]);
        mx[0][l][r]=max(mx[0][l][r-1], dp[l][r]);
        mx[1][l][r]=mx[1][l+1][r];
    }else{
        dp[l][r]=max(2, 1+mx[0][l][r-1]);
        mx[0][l][r]=mx[0][l][r-1];
        mx[1][l][r]=max(mx[1][l+1][r], dp[l][r]);
    }
}
int main()
{
    cin>>n;
    bool nuo=1;
    for(int i=0; i<n; i++){
        cin>>a[i];
        if(i>0 && a[i]!=a[0]) nuo=0;
    }
    if(nuo){
        cout<<1<<endl; return 0;
    }
    for(int i=0; i<n; i++) for(int j=i+1; j<n; j++) dp[i][j]=-1;
    solve(0, n-1);
    int ans=2;
    for(int i=0; i<n; i++) for(int j=i+1; j<n; j++) ans=max(ans, dp[i][j]);
    cout<<ans<<endl;
    return 0;
}
0