結果

問題 No.1188 レベルX門松列
ユーザー onsen_manjuuuonsen_manjuuu
提出日時 2020-09-01 01:39:03
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 70 ms / 2,000 ms
コード長 1,437 bytes
コンパイル時間 1,703 ms
コンパイル使用メモリ 170,768 KB
実行使用メモリ 5,976 KB
最終ジャッジ日時 2024-11-17 03:03:08
合計ジャッジ時間 3,304 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>

using namespace std;
using ll = long long;
const int INF = 1e9;
int n;

/*********************************/
template<class T> inline ostream& operator<<(ostream& os,vector<T> arr) {os << "["; for(int i = 0; i < (int)arr.size(); i++)os << arr[i] << (i == (int)arr.size() - 1 ? "]" : ",");os << endl;return os;}
template<typename A, typename B> ostream& operator<<(ostream& os, const pair<A,B>& p){os << "{" << p.first << "," << p.second << "}";return os; }
#define prvec(v) cerr<<#v<<": [";for(int __i = 0;__i < (int)(v).size(); __i++)cerr<<((v)[__i])<<(__i+1==(int)(v).size()?"]\n":",");
#define print(x) cerr<<#x<<": "<<(x)<<endl
/*********************************/


vector<int> LIS(vector<int> a) {
	vector<int> dp(n, INF);
	vector<int> f(n);
	for(int i = 0; i < n; i++) {
		auto itr = lower_bound(dp.begin(), dp.end(), a[i]);
		f[i] = itr - dp.begin();
		*itr = a[i];
		// f[i] = lower_bound(dp.begin(), dp.end(), a[i]) - dp.begin();
	}
	return f;

}

int f(vector<int> a, int cof) {
	for(auto &i: a) i *= cof;
	vector<int> frot = LIS(a);
	reverse(a.begin(), a.end());
	vector<int> back = LIS(a);
	reverse(back.begin(), back.end());

	int nax = 0;
	/*

	print(frot);
	print(back);
	*/

	for(int i = 1; i < n - 1; i++) {
		nax = max(nax, min(frot[i], back[i]));
	}

	return nax;



}

int main()
{
	cin >> n;
	vector<int> a(n);
	for(int i = 0; i < n; i++)cin >> a[i];
	cout << max(f(a, 1), f(a,-1)) << endl;
}
0