QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#128991#464. 前缀函数 / KMPyoungsystem#TL 0ms0kbC++20532b2023-07-21 18:32:162023-07-21 18:32:19

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-21 18:32:19]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:0kb
  • [2023-07-21 18:32:16]
  • 提交

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...

output:


result: