QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#21516#2840. 绿绿与串串DaBenZhongXiaSongKuaiDi#AC ✓227ms32984kbC++201.1kb2022-03-07 14:23:232022-05-08 03:35: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-05-08 03:35:29]
  • 评测
  • 测评结果:AC
  • 用时:227ms
  • 内存:32984kb
  • [2022-03-07 14:23:23]
  • 提交

answer

#include<bits/stdc++.h>
#define ull unsigned long long
#define K1 32989ull
using namespace std;
const int N=1000005;
int T;
int n;
char s[N];
ull h[2][N],pw[N];
int ans[N],tot=0;
bool ok[N];
bool equal(int l1,int r1,int r2,int l2){
	ull hash1=h[0][r1]-h[0][l1-1]*pw[r1-l1+1];
	ull hash2=h[1][r2]-h[1][l2+1]*pw[l2-r2+1];
	//if(l1-1>n-l2) hash2*=pw[l1-1-n+l2];
	//else hash1*=pw[n-l2-l1+1];
	return (hash1==hash2);
}
int main(){
	scanf("%d",&T);
	while(T--){
		scanf("%s",s);
		n=strlen(s);
		if(n==1){
			printf("1\n");
			continue;
		}
		h[0][0]=0,pw[0]=1;
		for(int i=1;i<=n;i++){
			h[0][i]=h[0][i-1]*K1+(ull)(s[i-1]);
			pw[i]=pw[i-1]*K1;
		}
		h[1][n+1]=0;
		for(int i=n;i>=1;i--){
			h[1][i]=h[1][i+1]*K1+(ull)(s[i-1]);
		}
		//cout<<equal(1,2,3,4)<<endl;
		tot=0;
		for(int i=1;i<=n;i++) ok[i]=false;
		for(int i=n;i>=1;i--){
			if(2*i-1>n){
				if(equal(2*i-n,i,i,n)) ok[i]=true,ans[++tot]=i;
			}
			else{
				if(equal(1,i,i,2*i-1) && ok[2*i-1]) ok[i]=true,ans[++tot]=i;
			}
		}
		for(int i=tot;i>=1;i--) printf("%d ",ans[i]);
		printf("\n");
	}
}
/*
4
abababababababa
*/

詳細信息

Test #1:

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

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: 227ms
memory: 32984kb

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: 71ms
memory: 29936kb

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: 72ms
memory: 30032kb

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