QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#128991 | #464. 前缀函数 / KMP | youngsystem# | TL | 0ms | 0kb | C++20 | 532b | 2023-07-21 18:32:16 | 2023-07-21 18:32:19 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
inline int read()
{
int n=0,f=1,ch=getchar();
while(ch<'0'||ch>'9')
{
if(ch=='-')f=-1;
ch=getchar();
}
while(ch>='0'&&ch<='9')
{
n=n*10+ch-'0';
ch=getchar();
}
return n*f;
}
char s[100005];
int kmp[100005];
int main()
{
int n;
n=read();
scanf("%s",s+1);
int j=0;
for(int i=2;i<=n;i++)
{
while(j!=0&&s[j+1]!=s[i])j=kmp[j];
if(s[j+1]==s[i])j++;
kmp[i]=j;
}
for(int i=1;i<=n;i++)printf("%d ",kmp[i]);
return 0;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Time Limit Exceeded
input:
mencimencimencimencimencimencimencimenciyvdfitnmencimencimencimencimencimencimencimenciyvdfitnmencimencimencimencimencimencimencimenciyvdfitnmencimencimencimencimencimencimencimenciyvdfitnmencimencimencimencimencimencimencimenciyvdfitnmencimencimencimencimencimencimencimenciyvdfitnmencimencimencimen...