結果

問題 No.127 門松もどき
ユーザー chocoruskchocorusk
提出日時 2019-05-24 00:03:18
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,342 bytes
コンパイル時間 835 ms
コンパイル使用メモリ 98,940 KB
実行使用メモリ 101,464 KB
最終ジャッジ日時 2023-10-17 11:41:46
合計ジャッジ時間 3,147 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,720 KB
testcase_01 AC 2 ms
5,728 KB
testcase_02 AC 3 ms
5,752 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 WA -
testcase_05 AC 1 ms
4,348 KB
testcase_06 WA -
testcase_07 AC 3 ms
8,268 KB
testcase_08 WA -
testcase_09 AC 2 ms
7,880 KB
testcase_10 AC 2 ms
5,884 KB
testcase_11 AC 4 ms
8,832 KB
testcase_12 AC 64 ms
75,100 KB
testcase_13 AC 80 ms
87,336 KB
testcase_14 AC 75 ms
82,192 KB
testcase_15 AC 97 ms
99,164 KB
testcase_16 AC 72 ms
81,536 KB
testcase_17 AC 78 ms
87,864 KB
testcase_18 AC 70 ms
80,784 KB
testcase_19 AC 46 ms
62,624 KB
testcase_20 AC 47 ms
63,024 KB
testcase_21 AC 28 ms
43,152 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 101 ms
97,676 KB
testcase_26 WA -
権限があれば一括ダウンロードができます

ソースコード

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+1][r];
        mx[1][l][r]=mx[1][l+1][r];
    }else if(a[l]<a[r]){
        dp[l][r]=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]=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);
    cout<<1+max(mx[0][0][n-1], mx[1][0][n-1])<<endl;
    return 0;
}
0