Submission #60081369


Source Code Expand

Copy
#include<bits/stdc++.h>
using namespace std;
namespace SOLUTION{
const int maxn=2e5+5,maxstate=(1<<20)+5;
int a[maxn],vec[23][maxn],cnt[23],f[maxstate];
inline int main(){
int n;
cin>>n;
for(int i=1;i<=n;++i){
cin>>a[i];
vec[a[i]][++cnt[a[i]]]=i;
}
memset(f,0x3f,sizeof(f));
f[0]=0;
for(int i=1;i<(1<<20);++i){
for(int j=1;j<=20;++j){
if(i&(1<<(j-1))){
int tmp=f[i^(1<<(j-1))];
int it=upper_bound(vec[j],vec[j]+cnt[j]+1,tmp)-vec[j];
if(it+1<=cnt[j]){
f[i]=min(f[i],vec[j][it+1]);
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
#include<bits/stdc++.h>
using namespace std;
namespace SOLUTION{
	const int maxn=2e5+5,maxstate=(1<<20)+5;
	int a[maxn],vec[23][maxn],cnt[23],f[maxstate];
	inline int main(){
		int n;
		cin>>n;
		for(int i=1;i<=n;++i){
			cin>>a[i];
			vec[a[i]][++cnt[a[i]]]=i;
		}
		memset(f,0x3f,sizeof(f));
		f[0]=0;
		for(int i=1;i<(1<<20);++i){
			for(int j=1;j<=20;++j){
				if(i&(1<<(j-1))){
					int tmp=f[i^(1<<(j-1))];
					int it=upper_bound(vec[j],vec[j]+cnt[j]+1,tmp)-vec[j];
					if(it+1<=cnt[j]){
						f[i]=min(f[i],vec[j][it+1]);
					}
				}
			}
		}
		int ans=0;
		for(int i=0;i<(1<<20);++i){
			if(f[i]<=n){
				int cnt=0;
				for(int j=1;j<=20;++j){
					if(i&(1<<(j-1))){
						++cnt;
					}
				}
				ans=max(ans,cnt);
			}
		}
		cout<<(ans<<1)<<"\n";
		return 0;
	}
}
int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	SOLUTION::main();
	return 0;
}
/*
12
1 1 2 2 3 3 20 20 19 19 18 18
*/

Submission Info

Submission Time
Task F - 1122 Subsequence
User sangshang
Language C++ 20 (gcc 12.2)
Score 525
Code Size 1020 Byte
Status AC
Exec Time 240 ms
Memory 9340 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 525 / 525
Status
AC × 2
AC × 46
Set Name Test Cases
Sample example_00.txt, example_01.txt
All example_00.txt, example_01.txt, hand_00.txt, hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, hand_06.txt, hand_07.txt, hand_08.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, random_27.txt, random_28.txt, random_29.txt, random_30.txt, random_31.txt, random_32.txt, random_33.txt, random_34.txt
Case Name Status Exec Time Memory
example_00.txt AC 81 ms 7588 KB
example_01.txt AC 79 ms 7528 KB
hand_00.txt AC 101 ms 7508 KB
hand_01.txt AC 131 ms 7720 KB
hand_02.txt AC 135 ms 7652 KB
hand_03.txt AC 134 ms 7576 KB
hand_04.txt AC 147 ms 7608 KB
hand_05.txt AC 92 ms 9200 KB
hand_06.txt AC 92 ms 9340 KB
hand_07.txt AC 80 ms 7632 KB
hand_08.txt AC 79 ms 7572 KB
random_00.txt AC 150 ms 7580 KB
random_01.txt AC 151 ms 7652 KB
random_02.txt AC 172 ms 7664 KB
random_03.txt AC 172 ms 7720 KB
random_04.txt AC 174 ms 7592 KB
random_05.txt AC 169 ms 7584 KB
random_06.txt AC 206 ms 8428 KB
random_07.txt AC 196 ms 8496 KB
random_08.txt AC 122 ms 8512 KB
random_09.txt AC 210 ms 8468 KB
random_10.txt AC 185 ms 8376 KB
random_11.txt AC 161 ms 8420 KB
random_12.txt AC 136 ms 8372 KB
random_13.txt AC 166 ms 8416 KB
random_14.txt AC 229 ms 8484 KB
random_15.txt AC 119 ms 8384 KB
random_16.txt AC 163 ms 8404 KB
random_17.txt AC 207 ms 8544 KB
random_18.txt AC 195 ms 8440 KB
random_19.txt AC 240 ms 8452 KB
random_20.txt AC 203 ms 8420 KB
random_21.txt AC 164 ms 8440 KB
random_22.txt AC 115 ms 8372 KB
random_23.txt AC 189 ms 8456 KB
random_24.txt AC 211 ms 8440 KB
random_25.txt AC 130 ms 8436 KB
random_26.txt AC 159 ms 8492 KB
random_27.txt AC 146 ms 8396 KB
random_28.txt AC 118 ms 8440 KB
random_29.txt AC 157 ms 8364 KB
random_30.txt AC 158 ms 8436 KB
random_31.txt AC 209 ms 8348 KB
random_32.txt AC 108 ms 8428 KB
random_33.txt AC 175 ms 8360 KB
random_34.txt AC 138 ms 8332 KB


2025-04-15 (Tue)
14:52:34 +00:00