QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#22540#2840. 绿绿与串串lindongli2004#AC ✓1563ms20404kbC++171.4kb2022-03-09 19:41:172022-04-30 01:18:53

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:53]
  • 评测
  • 测评结果:AC
  • 用时:1563ms
  • 内存:20404kb
  • [2022-03-09 19:41:17]
  • 提交

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); if(n!=1)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

*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 9908kb

input:

7
abcdcb
qwqwq
qaqaqqq
carnation
c
ab
aa

output:

4 6 
2 3 4 5 
6 7 
9 
1 
2 
2 

result:

ok 7 lines

Test #2:

score: 0
Accepted
time: 1563ms
memory: 20332kb

input:

5
cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc...

output:

2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 10...

result:

ok 5 lines

Test #3:

score: 0
Accepted
time: 1022ms
memory: 20332kb

input:

5
accabbaccabbaccabbaccabbaccabbaccabbaccabbaccabbaccabbaccabbaccabbaccabbaccabbaccabbaccabbaccabbaccabbaccabbaccabbaccabbaccabbaccabbaccabbaccabbaccabbaccabbaccabbaccabbaccabbaccabbaccabbaccabbaccabbaccabbaccabbaccabbaccabbaccabbaccabbaccabbaccabbaccabbaccabbaccabbaccabbaccabbaccabbaccabbaccabbacca...

output:

1000000 
500005 500012 500019 500026 500033 500040 500047 500054 500061 500068 500075 500082 500089 500096 500103 500110 500117 500124 500131 500138 500145 500152 500159 500166 500173 500180 500187 500194 500201 500208 500215 500222 500229 500236 500243 500250 500257 500264 500271 500278 500285 5002...

result:

ok 5 lines

Test #4:

score: 0
Accepted
time: 1112ms
memory: 20404kb

input:

5
wwcunkdbrnrbzqtgvzpnpyrpafjdnznmxpgkzlorbfsayoitnziexcuxhdaxeojdfrpfedyflshjgrewqmanowlybnvfdgkjxaqdfolqgsbpkfncunqimdinqdvujffihvonlzdrtfifmviglyrxdzktdfponuzurnhconwhuepgcxpnxgkafwvkenbrjalbpvfdkbmgidokadxzjjbphzblmccxeqytngyxhndrqrbtxauglwxtxzejbjgizhbmnclwrqojjrcguxnfvmaslhdpqlxruafjeqgvgwfppj...

output:

999995 
500500 501000 501500 502000 502500 503000 503500 504000 504500 505000 505500 506000 506500 507000 507500 508000 508500 509000 509500 510000 510500 511000 511500 512000 512500 513000 513500 514000 514500 515000 515500 516000 516500 517000 517500 518000 518500 519000 519500 520000 520500 52100...

result:

ok 5 lines