結果

問題 No.127 門松もどき
ユーザー omochana1omochana1
提出日時 2015-01-19 12:02:53
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 108 ms / 5,000 ms
コード長 1,564 bytes
コンパイル時間 604 ms
コンパイル使用メモリ 83,204 KB
実行使用メモリ 74,700 KB
最終ジャッジ日時 2023-08-25 13:54:11
合計ジャッジ時間 3,120 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 20 ms
74,344 KB
testcase_01 AC 21 ms
74,428 KB
testcase_02 AC 21 ms
74,324 KB
testcase_03 AC 21 ms
74,396 KB
testcase_04 AC 108 ms
74,524 KB
testcase_05 AC 21 ms
74,336 KB
testcase_06 AC 27 ms
74,284 KB
testcase_07 AC 20 ms
74,364 KB
testcase_08 AC 21 ms
74,336 KB
testcase_09 AC 21 ms
74,268 KB
testcase_10 AC 20 ms
74,268 KB
testcase_11 AC 21 ms
74,240 KB
testcase_12 AC 62 ms
74,476 KB
testcase_13 AC 75 ms
74,464 KB
testcase_14 AC 70 ms
74,472 KB
testcase_15 AC 95 ms
74,520 KB
testcase_16 AC 67 ms
74,476 KB
testcase_17 AC 73 ms
74,500 KB
testcase_18 AC 63 ms
74,552 KB
testcase_19 AC 46 ms
74,672 KB
testcase_20 AC 46 ms
74,700 KB
testcase_21 AC 32 ms
74,400 KB
testcase_22 AC 107 ms
74,580 KB
testcase_23 AC 95 ms
74,500 KB
testcase_24 AC 85 ms
74,496 KB
testcase_25 AC 99 ms
74,460 KB
testcase_26 AC 59 ms
74,444 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <string.h>
#include <map>
#include <fstream>
#include <functional>
#include <bitset>
#include <stack>
#include <set>
#include <climits>
#define MAX_N 3010
#define LOG 21
#define PI 3.141592653589
#define EPS 1e-6
#define MOD 1000000007
#define YJSNPI 810
#define INF (1 << 30)
#define ADD(a, b) a = (a + (ll)b) % MOD
#define MUL(a, b) a = (a * (ll)b) % MOD
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define REP(i, a, b) for(int i = a; i < b; i++)
#define RER(i, a, b) for(int i = a - 1; i >= b; i--)

using namespace std;

typedef long long ll;
typedef pair<ll, int> pi;

void debug() {cout << endl; }

template<class FIRST, class... REST>
void debug(FIRST arg, REST... rest) { cout << arg << " "; debug(rest...); }

template<class T>
void showary(T begin, T end) { 
	while(begin != end) { cout << *begin << " "; begin++; } cout << endl; }

int N;
int A[MAX_N];
int dp[MAX_N][MAX_N][2];

int loop(int l, int r, int k) {
	if(dp[l][r][k] != -1) return dp[l][r][k];
	if(l == r) return 0;
	int res = 0;
	if(k == 0) {
		MAX(res, loop(l, r - 1, 0));
		if(A[l] < A[r]) MAX(res, loop(l + 1, r, 1) + 1);
	}
	else {
		MAX(res, loop(l + 1, r, 1));
		if(A[l] > A[r]) MAX(res, loop(l, r - 1, 0) + 1);
	}
	//debug(l, r, k, res);
	return dp[l][r][k] = res;
}

int main() {
	scanf("%d", &N);
	REP(i, 0, N) scanf("%d", &A[i + 1]);
	memset(dp, -1, sizeof(dp));
	printf("%d\n", max(loop(0, N + 1, 0), loop(0, N + 1, 1)));
}
0