結果

問題 No.127 門松もどき
ユーザー omochana1
提出日時 2015-01-19 12:02:53
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 107 ms / 5,000 ms
コード長 1,564 bytes
コンパイル時間 1,037 ms
コンパイル使用メモリ 83,104 KB
実行使用メモリ 74,732 KB
最終ジャッジ日時 2024-12-23 22:14:59
合計ジャッジ時間 3,363 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 23
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:65:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   65 |         scanf("%d", &N);
      |         ~~~~~^~~~~~~~~~
main.cpp:66:27: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   66 |         REP(i, 0, N) scanf("%d", &A[i + 1]);
      |                      ~~~~~^~~~~~~~~~~~~~~~~

ソースコード

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