結果

問題 No.1827 最長部分スーパーリッチ門松列列
ユーザー 沙耶花沙耶花
提出日時 2022-01-28 22:24:10
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,177 bytes
コンパイル時間 4,649 ms
コンパイル使用メモリ 278,860 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-28 20:30:00
合計ジャッジ時間 16,692 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 193 ms
4,376 KB
testcase_04 TLE -
testcase_05 TLE -
testcase_06 TLE -
testcase_07 TLE -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using mint = modint998244353;
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define Inf 1000000001

struct Data{
	vector<vector<int>> v;
	Data(){
		v.resize(2,vector<int>(2,-Inf));
	}
};

Data op(Data a,Data b){
	Data ret;
	rep(i,2){
		rep(j,2){
			ret.v[i][j] = max(ret.v[i][j],a.v[i][j]);
			ret.v[i][j] = max(ret.v[i][j],b.v[i][j]);
			rep(k,2){
				rep(l,2){
					if(j==k)continue;
					ret.v[i][l] = max(ret.v[i][l], a.v[i][j] + b.v[k][l]);
				}
			}
		}
	}
	return ret;
}

Data e(){
	return Data();
}

int main(){
	
	int _t;
	cin>>_t;
	
	rep(_,_t){
		int n;
		cin>>n;
		vector<int> pos(n);
		rep(i,n){
			int p;
			cin>>p;
			p--;
			pos[p] = i;
		}
		segtree<Data,op,e> seg(n);
		rep(i,n){
			Data t;
			t.v[0][0] = 1;
			seg.set(i,t);
		}
		int ans = 0;
		rep(i,n){
			Data t;
			t.v[1][1] = 1;
			auto x = seg.prod(0,pos[i]);
			auto y = seg.prod(pos[i]+1,n);
			int z = 1;
			z += max({0,x.v[0][0] , x.v[1][0]});
			z += max({0,y.v[0][0] , y.v[0][1]});
		//	cout<<z<<endl;
			ans = max(ans,z);
			seg.set(pos[i],t);
		}
		
		cout<<ans<<endl;
	}
	
	return 0;
}
0