QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#21509#2840. 绿绿与串串DaBenZhongXiaSongKuaiDi#WA 4ms9952kbC++201.0kb2022-03-07 14:18:362022-05-08 03:35:07

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:07]
  • 评测
  • 测评结果:WA
  • 用时:4ms
  • 内存:9952kb
  • [2022-03-07 14:18:36]
  • 提交

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);
		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
abba
*/

詳細信息

Test #1:

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

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: ''