結果

問題 No.1188 レベルX門松列
ユーザー seven_threeseven_three
提出日時 2020-08-01 20:49:45
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 58 ms / 2,000 ms
コード長 1,640 bytes
コンパイル時間 884 ms
コンパイル使用メモリ 95,828 KB
実行使用メモリ 6,040 KB
最終ジャッジ日時 2023-09-22 15:42:06
合計ジャッジ時間 4,590 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
5,268 KB
testcase_01 AC 43 ms
5,000 KB
testcase_02 AC 39 ms
4,876 KB
testcase_03 AC 52 ms
5,236 KB
testcase_04 AC 40 ms
5,800 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 17 ms
5,272 KB
testcase_07 AC 38 ms
6,040 KB
testcase_08 AC 38 ms
5,884 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 5 ms
4,376 KB
testcase_12 AC 5 ms
4,380 KB
testcase_13 AC 5 ms
4,376 KB
testcase_14 AC 35 ms
4,540 KB
testcase_15 AC 58 ms
5,348 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 45 ms
4,944 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 42 ms
4,736 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma warning (disable: 4996)
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
int l1[100010], r1[100010], l2[100010], r2[100010];
int a[100010];
int main() {
	int n;
	cin >> n;
	vector<int> dp, dp1, dp2, dp3;
	dp.emplace_back(1000000007);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		auto it = lower_bound(dp.begin(), dp.end(), a[i]);
		if (it == dp.end()) {
			dp.emplace_back(a[i]);
		}
		else {
			*it = a[i];
		}
		l1[i] = dp.size();
	}
	dp1.emplace_back(1000000007);
	for (int i = n - 1; i >= 0; i--) {
		auto it = lower_bound(dp1.begin(), dp1.end(), a[i]);
		if (it == dp1.end()) {
			dp1.emplace_back(a[i]);
		}
		else {
			*it = a[i];
		}
		r1[i] = dp1.size();
	}
	for (int i = 0; i < n; i++) {
		a[i] *= -1;
	}
	dp2.emplace_back(1000000007);
	for (int i = 0; i < n; i++) {
		auto it = lower_bound(dp2.begin(), dp2.end(), a[i]);
		if (it == dp2.end()) {
			dp2.emplace_back(a[i]);
		}
		else {
			*it = a[i];
		}
		l2[i] = dp2.size();
	}
	dp3.emplace_back(1000000007);
	for (int i = n - 1; i >= 0; i--) {
		auto it = lower_bound(dp3.begin(), dp3.end(), a[i]);
		if (it == dp3.end()) {
			dp3.emplace_back(a[i]);
		}
		else {
			*it = a[i];
		}
		r2[i] = dp3.size();
	}
	int ans = 0;
	for (int i = 0; i < n; i++) {
		if (min(l1[i], r1[i]) > ans) {
			ans = min(l1[i], r1[i]);
		}
		if (min(l2[i], r2[i]) > ans) {
			ans = min(l2[i], r2[i]);
		}
	}
	cout << ans - 1 << endl;
	return 0;
}

0