QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#102974 | #2831. Game Theory | kkkgjyismine4 | WA | 4ms | 11756kb | C++14 | 1.2kb | 2023-05-03 20:56:02 | 2023-05-03 20:56:09 |
Judging History
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;
}
詳細信息
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 '