結果

問題 No.127 門松もどき
ユーザー sugim48sugim48
提出日時 2015-01-14 00:13:44
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 936 ms / 5,000 ms
コード長 1,883 bytes
コンパイル時間 2,215 ms
コンパイル使用メモリ 98,688 KB
実行使用メモリ 86,600 KB
最終ジャッジ日時 2023-08-25 13:39:34
合計ジャッジ時間 12,656 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 936 ms
86,600 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 44 ms
9,592 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 442 ms
57,148 KB
testcase_13 AC 666 ms
68,896 KB
testcase_14 AC 602 ms
64,932 KB
testcase_15 AC 809 ms
80,408 KB
testcase_16 AC 521 ms
63,512 KB
testcase_17 AC 674 ms
70,064 KB
testcase_18 AC 549 ms
61,892 KB
testcase_19 AC 262 ms
31,020 KB
testcase_20 AC 269 ms
31,648 KB
testcase_21 AC 114 ms
19,496 KB
testcase_22 AC 920 ms
86,588 KB
testcase_23 AC 920 ms
86,528 KB
testcase_24 AC 728 ms
72,600 KB
testcase_25 AC 852 ms
80,936 KB
testcase_26 AC 317 ms
35,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v, w; };

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;
int INF = INT_MAX / 2;

struct segment_tree_max {
	int n; vector<short> v;
	segment_tree_max(int _n) {
		for (n = 1; n < _n; n *= 2);
		v = vector<short>(n * 2 - 1, 0);
	}
	void set(int i, short x) {
		int k = i + n - 1;
		v[k] = x;
		while (k > 0) {
			k = (k - 1) / 2;
			v[k] = max(v[k * 2 + 1], v[k * 2 + 2]);
		}
	}
	short _get(int i, int j, int k, int l, int r) {
		if (r <= i || j <= l) return 0;
		if (i <= l && r <= j) return v[k];
		short vl = _get(i, j, k * 2 + 1, l, (l + r) / 2);
		short vr = _get(i, j, k * 2 + 2, (l + r) / 2, r);
		return max(vl, vr);
	}
	short get(int i, int j) { return _get(i, j, 0, 0, n); }
};

int main() {
	int N; cin >> N;
	vector<int> A(N);
	for (int i = 0; i < N; i++)
		cin >> A[i];
	vector<segment_tree_max> st(N, segment_tree_max(N));
	vector< vector<short> > dp(N, vector<short>(N)), _dp = dp;
	for (int i = 0; i < N; i++)
		for (int j = N - 1; j > i; j--) {
			if (A[i] < A[j]) {
				dp[i][j] = st[i].get(j + 1, N) + 1;
				st[j].set(i, dp[i][j]);
			}
			if (A[i] > A[j]) {
				_dp[i][j] = st[j].get(0, i) + 1;
				st[i].set(j, _dp[i][j]);
			}
		}
	short maxi = 0;
	for (int i = 0; i < N; i++)
		for (int j = 0; j < N; j++)
			maxi = max(maxi, max(dp[i][j], _dp[i][j]));
	cout << maxi + 1 << endl;
}
0