Submission #60048271


Source Code Expand

#include<bits/stdc++.h>
#define fo(i,l,r) for(int i=l;i<=r;++i)
#define fd(i,r,l) for(int i=r;i>=l;--i)
#define ll long long
#define I inline int
#define V inline void
#define B inline bool
#define L inline ll
#define pi pair<int,int>
#define mk make_pair
#define fi first
#define se second
#define pb push_back
#define vi vector<int>
#define vii vector<pi>
using namespace std;
const int N=1e6+10,mod=998244353;
char St;
I read() {
	int x=0,y=1;char c=getchar();
	while(c<48||c>57) {if(c==45)y=-y;c=getchar();}
	while(c>=48&&c<=57) x=(x<<1)+(x<<3)+(c^48),c=getchar();
	return x*y;
}
int n,a[N],cnt[N];
L ksm(ll x,int y) {ll t(1);for(;y;y>>=1,x=x*x%mod)if(y&1)t=t*x%mod;return t;}
char Ed;
int main() {
	cerr<<"memory:"<<(&St-&Ed)/1024.0<<endl;
	n=read();
	fo(i,1,n) a[i]=read();
	int ans(0),r(0);
	for(int l=1;l<=n;l+=2) {
		r=max(r,l-1);
		while(r+2<=n&&a[r+1]==a[r+2]&&cnt[a[r+1]]==0) cnt[a[r+1]]+=2,r+=2;
		ans=max(ans,r-l+1);
		if(l<=r) cnt[a[l]]--,cnt[a[l+1]]--;
	}
	memset(cnt,0,sizeof(cnt));
	r=0;
	for(int l=2;l<=n;l+=2) {
		r=max(r,l-1);
		while(r+2<=n&&a[r+1]==a[r+2]&&cnt[a[r+1]]==0) cnt[a[r+1]]+=2,r+=2;
		ans=max(ans,r-l+1);
		if(l<=r) cnt[a[l]]--,cnt[a[l+1]]--;
	}
	printf("%d\n",ans);
	cerr<<"time:"<<clock()<<endl;
	return 0;
}

Submission Info

Submission Time
Task D - 1122 Substring
User OIer2008
Language C++ 20 (gcc 12.2)
Score 425
Code Size 1297 Byte
Status AC
Exec Time 9 ms
Memory 8572 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 425 / 425
Status
AC × 3
AC × 39
Set Name Test Cases
Sample example_00.txt, example_01.txt, example_02.txt
All example_00.txt, example_01.txt, example_02.txt, hand_00.txt, hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.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
Case Name Status Exec Time Memory
example_00.txt AC 2 ms 7688 KiB
example_01.txt AC 2 ms 7756 KiB
example_02.txt AC 2 ms 7660 KiB
hand_00.txt AC 7 ms 8500 KiB
hand_01.txt AC 8 ms 8424 KiB
hand_02.txt AC 8 ms 8504 KiB
hand_03.txt AC 8 ms 8468 KiB
hand_04.txt AC 7 ms 8408 KiB
hand_05.txt AC 2 ms 7720 KiB
random_00.txt AC 8 ms 8376 KiB
random_01.txt AC 8 ms 8568 KiB
random_02.txt AC 8 ms 8564 KiB
random_03.txt AC 8 ms 8568 KiB
random_04.txt AC 8 ms 8380 KiB
random_05.txt AC 8 ms 8560 KiB
random_06.txt AC 8 ms 8504 KiB
random_07.txt AC 8 ms 8400 KiB
random_08.txt AC 8 ms 8512 KiB
random_09.txt AC 9 ms 8568 KiB
random_10.txt AC 8 ms 8564 KiB
random_11.txt AC 8 ms 8568 KiB
random_12.txt AC 8 ms 8512 KiB
random_13.txt AC 8 ms 8564 KiB
random_14.txt AC 8 ms 8504 KiB
random_15.txt AC 8 ms 8540 KiB
random_16.txt AC 8 ms 8464 KiB
random_17.txt AC 8 ms 8460 KiB
random_18.txt AC 8 ms 8404 KiB
random_19.txt AC 8 ms 8440 KiB
random_20.txt AC 8 ms 8512 KiB
random_21.txt AC 8 ms 8540 KiB
random_22.txt AC 8 ms 8540 KiB
random_23.txt AC 8 ms 8488 KiB
random_24.txt AC 8 ms 8572 KiB
random_25.txt AC 8 ms 8420 KiB
random_26.txt AC 8 ms 8504 KiB
random_27.txt AC 8 ms 8460 KiB
random_28.txt AC 8 ms 8492 KiB
random_29.txt AC 8 ms 8516 KiB