QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#333231#7877. Balanced Arrayyz_lyWA 1ms3836kbC++141.9kb2024-02-19 18:53:212024-02-19 18:53:22

Judging History

你现在查看的是最新测评结果

  • [2024-02-19 18:53:22]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3836kb
  • [2024-02-19 18:53:21]
  • 提交

answer

#include<bits/stdc++.h>
#define ll unsigned long long
using namespace std;
inline int read(){
	char ch=getchar();
	int f=1,x=0;
	while(ch<'0'||ch>'9'){
		if(ch=='-')
			f=-f;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9'){
		x=x*10+ch-'0';
		ch=getchar();
	}
	return f*x;
}
inline void work(ll k){
	if(k<0){
		putchar('-');
		k=-k;
	}
	if(k>9)
		work(k/10);
	putchar(k%10+'0');
}
/*
如果不考虑第一个1<=k<=(i-1)/2的限制,对于一个固定的k,满足条件的i一定是一个前缀,考虑二分这个前缀
那么加上这个限制之后满足条件的就是一个区间
判定可以用字符串Hash,如果满足h(1,i-2*k)+h(2*k+1,i)=2*h(k+1,l-k)就是满足条件的
这个单Hash不会被卡吧
O(nlogn)不太行
从小到大跑i,双指针维护k
*/
const ll p=1e9+9843,mod=1e9+7;
int n,ans[2000005];
ll h[2000005],pn[2000005],p1[2000005];
long long pn1[2000005],h1[2000005];
ll Hash(int l,int r){
	return h[r]-h[l-1]*pn[r-l+1];
}
long long Hash1(int l,int r){
	return (h1[r]-h1[l-1]*pn1[r-l+1]%mod+mod)%mod;
}
char s[25];
int main(){
	n=read();
	pn[0]=p1[0]=pn1[0]=1;
	for(int i=1;i<=15;i++){
		p1[i]=p1[i-1]*62;
	}
	for(int i=1;i<=n;i++){
		ll val=0;
		scanf("%s",s+1);
		int len=strlen(s+1);
		for(int j=len,now=0;j;j--,now++){
			ll id=s[j];
			if(id>='a'&&id<='z')
				id=id-'a'+1+9;
			else if(id>='A'&&id<='Z')
				id=id-'A'+1+35;
			else
				id=id-'0';
			val=val+p1[now]*id;
		}
		pn[i]=pn[i-1]*p;
		pn1[i]=pn1[i-1]*p%mod;
		h[i]=h[i-1]*p+val;
		h1[i]=(h1[i-1]*p%mod+val)%mod;
	}
	int l=1,r=1;
	work(0);
	work(0);
	for(int i=3;i<=n;i++){
		if(Hash(1,i-2*r)+Hash(2*r+1,i)!=2*Hash(r+1,i-r)||(Hash(1,i-2*r)+Hash(2*r+1,i))%mod!=2*Hash(r+1,i-r)%mod){
			l=r+1;
			r++;
			work(0);
			continue;
		}
		while(Hash(1,i-2*l)+Hash(2*l+1,i)!=2*Hash(l+1,i-l)||(Hash(1,i-2*l)+Hash(2*l+1,i))%mod!=2*Hash(l+1,i-l)%mod){
			l++;
		}
		work(1);
	}
	
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3768kb

input:

3
1 2 3

output:

001

result:

ok single line: '001'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3836kb

input:

9
1 2 3 2 5 4 3 8 5

output:

001010111

result:

ok single line: '001010111'

Test #3:

score: 0
Accepted
time: 0ms
memory: 3676kb

input:

9
1C 3f 4S 3h 88 6x 4W d1 8c

output:

001010111

result:

ok single line: '001010111'

Test #4:

score: -100
Wrong Answer
time: 0ms
memory: 3816kb

input:

49
71FjQ 71FzG 71FjR 71FjG 71FjS 71F3G 71FjT 71ENG 71FjU 71ExG 71FzG 71Fko 71FjW 71FOM 71FPm 71FzG 71FPO 71FP9 71FzG 71Fkc 71FzG 7AXBr 71FPH 8nKLh 71Fk2 71FzG 71FkK 4AGIE 71Fk9 6EfCL 71FPN 71FjJ 71FPb 7H3TC 71Gks 71FzG 71FPI 71FzG 6Oayg 71FPc 71FPw 71FPN 71Fkm 71FPK 71FPK 6Az4J 71FPI 71FzG 71Fke

output:

0001111111000000010101011001010101110001100101011

result:

wrong answer 1st lines differ - expected: '0000111111001000000000001000000000110000100000001', found: '0001111111000000010101011001010101110001100101011'