QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#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;
}
详细
Test #1:
score: 0
Time Limit Exceeded
input:
mencimencimencimencimencimencimencimenciyvdfitnmencimencimencimencimencimencimencimenciyvdfitnmencimencimencimencimencimencimencimenciyvdfitnmencimencimencimencimencimencimencimenciyvdfitnmencimencimencimencimencimencimencimenciyvdfitnmencimencimencimencimencimencimencimenciyvdfitnmencimencimencimen...