QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#333270#7877. Balanced Arrayyz_lyWA 0ms3832kbC++141.6kb2024-02-19 19:23:162024-02-19 19:23:16

Judging History

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

  • [2024-02-19 19:23:16]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3832kb
  • [2024-02-19 19:23:16]
  • 提交

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;
int n;
ll h[2000005],pn[2000005];
int p1[6];
ll Hash(int l,int r){
	return h[r]-h[l-1]*pn[r-l+1];
}
char s[6];
int main(){
	n=read();
	pn[0]=p1[0]=1;
	for(int i=1;i<=5;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;
		h[i]=h[i-1]*p+val;
	}
	int l=1,r=0;
	for(int i=1;i<=n;i++){
		while(l<=(i-1)/2&&Hash(1,i-2*l)+Hash(2*l+1,i)!=2*Hash(l+1,i-l)){
			l++;
		}
		if(r<l)
			r=l-1;
		while(r+1<=(i-1)/2&&Hash(1,i-2*(r+1))+Hash(2*(r+1)+1,i)==2*Hash(r+1+1,i-(r+1))){
			r++;
		}
		if(l<=r)
			work(1);
		else
			work(0);
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3608kb

input:

3
1 2 3

output:

001

result:

ok single line: '001'

Test #2:

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

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: 3832kb

input:

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

output:

001010111

result:

ok single line: '001010111'

Test #4:

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

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:

0000111111001000000000001000000000110000100000001

result:

ok single line: '0000111111001000000000001000000000110000100000001'

Test #5:

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

input:

48
4LZe2 4LZt4 4LZI6 4LZX8 4LZtY 4LZe2 4LZtX 4LZe2 4LYYd 4LYZ2 4LYZy 4LZe2 4LZtG 4LZtT 4LZe2 4LYtm 6g6ce 4LZe2 4LYYI 8MRDV 4LZu3 6tLzK 4WUft 7EU0p 5FVal 4LZe2 4LZe2 4LZu8 4LZe2 4LXtE 7KcGm 4LYXX 4LYYn 5v3aX 4LZtC 4LZu3 4LZe2 4LYYI 4LZtQ 4TSBp 4LYYB 4LZe2 4MatY 4LYYi 57PgU axOxK 6zQCA 4LZe2

output:

001100000000001100000000000011100000000000000000

result:

wrong answer 1st lines differ - expected: '001100000000001100000000000011100000000000001110', found: '001100000000001100000000000011100000000000000000'