QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#102974#2831. Game Theorykkkgjyismine4WA 4ms11756kbC++141.2kb2023-05-03 20:56:022023-05-03 20:56:09

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-05-03 20:56:09]
  • 评测
  • 测评结果:WA
  • 用时:4ms
  • 内存:11756kb
  • [2023-05-03 20:56:02]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
char s[1000006],t[1000006];
int N,M,fail[1000006],fail1[1000006];
bool vis[1000006];
int Res[1000006],Mx[1000006];
void solve() {
    N=strlen(s+1),M=strlen(t+1); fail[0]=fail1[0]=0;
    for(int i=1;i<=N;++i) vis[i]=false,Mx[i]=0; fail[1]=0; Mx[0]=0;
    for(int i=2;i<=N;++i) {
        int j=fail[i-1];
        while(j && s[j+1]!=s[i]) j=fail[j];
        if(s[j+1]==s[i]) fail[i]=j+1; else fail[i]=0;
    }
    fail1[1]=0;
    for(int i=2;i<=M;++i){
        int j=fail1[i-1];
        while(j && t[j+1]!=t[i]) j=fail1[j];
        if(t[j+1]==t[i]) fail1[i]=j+1; else fail1[i]=0;
    }
    int len=0;
    for(int i=1;i<=N;++i) {
        while(len && t[len+1]!=s[i]) len=fail1[len];
        if(t[len+1]==s[i]) ++len;
        if(len==M) vis[i]=true,len=fail1[len];
    }
    int mx=0;
    len=0;
    for(int i=1;i<=M;++i) {
    	while(len && s[len+1]!=t[i]) len=fail[len];
    	if(s[len+1]==t[i]) ++len;
    	if(i==M) { if(len==N) mx=fail[len]; else mx=len; }
 		if(len==N) len=fail[len];	
	}
	for(int i=0;i<N;++i) {
		Mx[i]=Mx[fail[i]]; if(i+M<N&&vis[i+M])Mx[i]=i+M;
		printf("%d ",max(Mx[i],mx));
	}
    puts("");
}
int main(){
    while(scanf("%s%s",s+1,t+1)!=EOF) solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3 2
010
1 2
2 3
5 1
00000
1 5

output:

0 
0 2 0 
0 
0 
0 
0 

result:

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