結果

問題 No.1827 最長部分スーパーリッチ門松列列
ユーザー 沙耶花沙耶花
提出日時 2022-01-28 22:25:27
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 955 ms / 2,000 ms
コード長 1,206 bytes
コンパイル時間 4,388 ms
コンパイル使用メモリ 263,520 KB
実行使用メモリ 29,660 KB
最終ジャッジ日時 2023-08-28 20:31:16
合計ジャッジ時間 20,730 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 22 ms
4,380 KB
testcase_04 AC 175 ms
4,376 KB
testcase_05 AC 175 ms
4,380 KB
testcase_06 AC 177 ms
4,376 KB
testcase_07 AC 732 ms
29,240 KB
testcase_08 AC 727 ms
29,352 KB
testcase_09 AC 731 ms
29,208 KB
testcase_10 AC 732 ms
29,368 KB
testcase_11 AC 733 ms
29,512 KB
testcase_12 AC 729 ms
29,440 KB
testcase_13 AC 729 ms
29,504 KB
testcase_14 AC 730 ms
29,484 KB
testcase_15 AC 729 ms
29,496 KB
testcase_16 AC 732 ms
29,484 KB
testcase_17 AC 955 ms
29,500 KB
testcase_18 AC 931 ms
29,404 KB
testcase_19 AC 730 ms
29,432 KB
testcase_20 AC 727 ms
29,436 KB
testcase_21 AC 727 ms
29,356 KB
testcase_22 AC 756 ms
29,272 KB
testcase_23 AC 756 ms
29,660 KB
testcase_24 AC 753 ms
29,408 KB
権限があれば一括ダウンロードができます

ソースコード

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{
	array<array<int,2>,2> v;
	Data(){
		rep(i,2){
			rep(j,2){
				v[i][j] = -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;
			scanf("%d",&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