結果

問題 No.127 門松もどき
ユーザー chocoruskchocorusk
提出日時 2019-05-24 00:02:20
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,322 bytes
コンパイル時間 810 ms
コンパイル使用メモリ 99,020 KB
実行使用メモリ 101,416 KB
最終ジャッジ日時 2023-10-17 11:41:43
合計ジャッジ時間 3,641 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,720 KB
testcase_01 AC 2 ms
5,728 KB
testcase_02 AC 2 ms
5,752 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 WA -
testcase_05 AC 2 ms
4,348 KB
testcase_06 WA -
testcase_07 AC 4 ms
8,268 KB
testcase_08 WA -
testcase_09 AC 3 ms
7,880 KB
testcase_10 AC 3 ms
5,884 KB
testcase_11 AC 4 ms
8,828 KB
testcase_12 AC 61 ms
75,064 KB
testcase_13 AC 77 ms
87,296 KB
testcase_14 AC 71 ms
82,156 KB
testcase_15 AC 94 ms
99,120 KB
testcase_16 AC 70 ms
81,500 KB
testcase_17 AC 74 ms
87,824 KB
testcase_18 AC 66 ms
80,748 KB
testcase_19 AC 45 ms
62,596 KB
testcase_20 AC 45 ms
62,992 KB
testcase_21 AC 26 ms
43,132 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 97 ms
97,632 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]){
        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