結果

問題 No.284 門松と魔法(2)
ユーザー hirokazu1020hirokazu1020
提出日時 2015-09-18 22:59:25
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,640 bytes
コンパイル時間 1,214 ms
コンパイル使用メモリ 115,728 KB
実行使用メモリ 20,072 KB
最終ジャッジ日時 2023-09-26 12:41:16
合計ジャッジ時間 4,397 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 9 ms
19,416 KB
testcase_01 AC 9 ms
19,496 KB
testcase_02 AC 9 ms
19,420 KB
testcase_03 AC 9 ms
19,432 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 9 ms
19,416 KB
testcase_10 AC 9 ms
19,492 KB
testcase_11 AC 9 ms
19,412 KB
testcase_12 AC 10 ms
19,508 KB
testcase_13 AC 10 ms
19,560 KB
testcase_14 WA -
testcase_15 AC 9 ms
19,476 KB
testcase_16 AC 10 ms
19,560 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 10 ms
19,432 KB
testcase_20 AC 10 ms
19,436 KB
testcase_21 AC 10 ms
19,416 KB
testcase_22 AC 10 ms
19,580 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 9 ms
19,420 KB
testcase_27 AC 9 ms
19,516 KB
testcase_28 AC 10 ms
19,432 KB
testcase_29 AC 167 ms
19,792 KB
testcase_30 WA -
testcase_31 WA -
testcase_32 AC 166 ms
19,740 KB
testcase_33 AC 90 ms
20,072 KB
testcase_34 AC 88 ms
19,792 KB
testcase_35 AC 10 ms
19,496 KB
testcase_36 AC 9 ms
19,420 KB
testcase_37 AC 70 ms
19,864 KB
testcase_38 WA -
testcase_39 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _CRT_SECURE_NO_WARNINGS
#include<sstream>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<climits>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<random>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())
#define indexOf(v,x) (find(all(v),x)-v.begin())



template<class S=int, S nil=INT_MAX, class T=std::less<S> >
class RMQ{//RangeMinimum(Maximum)Query
	int n;
	S *dat;
	S query(int a,int b,int k,int l,int r)const{
		if(r<=a||b<=l)return nil;
		if(a<=l&&r<=b)return dat[k];
		return std::min(query(a,b,k*2+1,l,(l+r)/2),query(a,b,k*2+2,(l+r)/2,r),T());
	}
public:
	RMQ(int n=1<<20):n(n){
		dat=new S[2*n-1];
		for(int i=0;i<2*n-1;i++)dat[i]=nil;
	}
	~RMQ(){
		delete[] dat;
	}
	void update(int k,S a){//k番目をaに変更
		k+=n-1;
		dat[k]=a;
		while(k>0){
			k=(k-1)/2;
			dat[k]=std::min(dat[k*2+1],dat[k*2+2],T());
		}
	}
	S query(int a,int b)const{//[a,b)の最小(大)値
		return query(a,b,0,0,n);
	}
};



int main() {
	RMQ<int,0,greater<int>> rmq1,rmq2;
	int n;	
	cin>>n;
	vector<int> a(n);
	rep(i,n)cin>>a[i];
	rep(i,n){
		int v;
		v=max(rmq1.query(a[i],a[i+1]),rmq2.query(0,a[i])+1);
		rmq1.update(a[i],v);
		v=max(rmq2.query(a[i],a[i+1]),rmq1.query(a[i]+1,1<<20)+1);
		rmq2.update(a[i],v);
	}
	int ans=max(rmq1.query(0,1<<20),rmq2.query(0,1<<20));
	if(ans<3)ans=0;
	cout<<ans<<endl;
	return 0;
}
0