QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#22530#2840. 绿绿与串串lindongli2004#WA 4ms7884kbC++171.4kb2022-03-09 19:38:092022-04-30 01:18:29

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-04-30 01:18:29]
  • 评测
  • 测评结果:WA
  • 用时:4ms
  • 内存:7884kb
  • [2022-03-09 19:38:09]
  • 提交

answer

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int seed=233,N=1002023;
int n,mod,vis[N],h[N],rh[N],pw[N]; char s[N];
//int h[N],rh[N],mod;
void init(int _mod){
	h[0]=rh[n+1]=0; mod=_mod;
	pw[0]=1;
	for(int i=1;i<=n;i++)pw[i]=1ll*pw[i-1]*seed%mod;
	for(int i=1;i<=n;i++)h[i]=(1ll*h[i-1]*seed%mod+s[i])%mod;
	for(int i=n;i>=1;i--)rh[i]=(1ll*rh[i+1]*seed%mod+s[i])%mod;
}
int get1(int l,int r){
	return ((1ll*h[r]-1ll*h[l-1]*pw[r-l+1]%mod)%mod+mod)%mod;
}
int get2(int l,int r){
	return ((1ll*rh[l]-1ll*rh[r+1]*pw[r-l+1]%mod)%mod+mod)%mod;
}
void check(int _mod){
	init(_mod); vis[1]=1;
	for(int i=2;i<=n;i++){
		if(vis[i])continue;
		int fl=0;
		for(int j=i;j<=n;j+=(j-1)){
			if(2*j-1<=n){
				if(get1(1,j-1)!=get2(j+1,2*j-1))
					{fl=1;break;}
			} else{
				if(get1(j-(n-j),j-1)!=get2(j+1,n))
					{fl=1;break;}
			}
		}
		vis[i]=fl;
	}
}
int read(){
	int x=0,f=1; char ch=getchar();
	while(ch<'0' || ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0' && ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int main()
{
	int aq=read();
	while(aq--){
		scanf("%s",s+1); n=strlen(s+1);
		for(int i=1;i<=n;i++)vis[i]=0;
		check(998244353); check(1e9+9);
		for(int i=1;i<=n;i++)
			if(!vis[i])printf("%d ",i);
		putchar('\n');
	}
//		H1.init(998244353); H2.init(1e9+9);
	return 0;
}
/*
4
abcdcb
qwqwq
qaqaqqq
carnation

*/

詳細信息

Test #1:

score: 0
Wrong Answer
time: 4ms
memory: 7884kb

input:

7
abcdcb
qwqwq
qaqaqqq
carnation
c
ab
aa

output:

4 6 
2 3 4 5 
6 7 
9 

2 
2 

result:

wrong answer 5th lines differ - expected: '1', found: ''