UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#210915#2067. 肉夹馍mygr6018ms2028kbC++710b2024-08-08 10:13:462024-08-08 14:28:18

answer

#include<bits/stdc++.h>
using namespace std;
const int Max=3e5+5;

int fail[Max],now,pre[Max];
char ch[Max];
int n;
char getc()
{
	char c=getchar();
	while(c<'a' or 'z'<c)
		c=getchar();
	return c;
}
int main()
{
	ch[1]=getchar();
	while('a'<=ch[n+1] and ch[n+1]<='z')
	{
		n++;
		ch[n+1]=getchar();
	}
	now=0;
	for(int i=2;i<=n;i++)
	{
		while(now and ch[now+1]!=ch[i])
			now=pre[now];
		if(ch[now+1]==ch[i])
			now++;
		pre[i]=now;
	}
	
	printf("0 ");now=0;
	fail[1]=0;
	for(int i=2;i<=n;i++)
	{
		while(now and ((ch[now+1]!=ch[i]) or !(now+1<=(i-1)/2)))
			now=pre[now];
		if(ch[now+1]==ch[i] and now+1<=(i-1)/2)
			now++;
		fail[i]=now;
		printf("%d ",now);
	}
}

详细

小提示:点击横条可展开更详细的信息

Subtask #1:

score: 10
Accepted

Test #1:

score: 10
Accepted
time: 0ms
memory: 1152kb

input:

qpbvqpbvqpbvavdqpbvqpbvqpbvavdqpbvqpbvqpbvavdfnfninqpbvqpbvqpbvavdqpbvqpbvqpbvavdqpbvqpbvqpbvavd

output:

0 0 0 0 1 2 3 0 1 2 3 4 0 0 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15...

result:

ok 96 tokens

Test #2:

score: 0
Accepted
time: 0ms
memory: 1156kb

input:

wfalgbgweavpwhfahfewhavweahuwbvbqvuivhuiaehufuaeuvdafuivjafislfhbibcuuiabcuibsv

output:

0 0 0 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

result:

ok 79 tokens

Test #3:

score: 0
Accepted
time: 0ms
memory: 1152kb

input:

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

output:

0 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 16 17 17 18 18 19 19 ...

result:

ok 100 tokens

Subtask #2:

score: 20
Accepted

Test #4:

score: 20
Accepted
time: 0ms
memory: 1176kb

input:

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...

output:

0 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 16 17 17 18 18 19 19 ...

result:

ok 3000 tokens

Test #5:

score: 0
Accepted
time: 0ms
memory: 1180kb

input:

cjcjcjcjcjcjcjcjcjcjcjcjcjcjcjcjcjcjcjcjcjcjcjcjcjcjcjcjcjcjcjcjcjcjcjcjcjcjcjcjcjcjcjcjcjcjcjcjcjcj...

output:

0 0 1 0 1 2 3 2 3 4 5 4 5 6 7 6 7 8 9 8 9 10 11 10 11 12 13 12 13 14 15 14 15 16 17 16 17 18 19 18 1...

result:

ok 3000 tokens

Test #6:

score: 0
Accepted
time: 0ms
memory: 1180kb

input:

ckcckckcckcckckcckcckckcckcckckcsdvhckcckckcckcckckcckcckckcckcckckcsdvhckcckckcckcckckcckcckckcckcc...

output:

0 0 1 1 2 1 2 3 4 2 3 4 5 6 7 3 4 5 6 4 5 6 7 8 9 10 11 12 13 14 15 8 0 0 0 0 1 2 3 4 5 6 7 8 9 10 1...

result:

ok 2828 tokens

Subtask #3:

score: 30
Accepted

Test #7:

score: 30
Accepted
time: 3ms
memory: 2028kb

input:

aocnsaosashoicfaaocnsaosashoicfaqowfwpqgvqvhoabcdoawaocnsaosashoicfaaocnsaosashoicfaqowfwpqgvqvhoabc...

output:

0 0 0 0 0 1 2 0 1 0 0 0 0 0 0 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 ...

result:

ok 100000 tokens

Test #8:

score: 0
Accepted
time: 7ms
memory: 2024kb

input:

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...

output:

0 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 16 17 17 18 18 19 19 ...

result:

ok 100000 tokens

Test #9:

score: 0
Accepted
time: 8ms
memory: 2028kb

input:

vivivivivivivivivivivivivivivivivivivivivivivivivivivivivivivivivivivivivivivivivivivivivivivivivivi...

output:

0 0 1 0 1 2 3 2 3 4 5 4 5 6 7 6 7 8 9 8 9 10 11 10 11 12 13 12 13 14 15 14 15 16 17 16 17 18 19 18 1...

result:

ok 100000 tokens

Subtask #4:

score: 0
Runtime Error

Test #10:

score: 0
Runtime Error

input:

aoifcpiapdpsahfahiofhdiohraoifcpiapdpsahfahiofhdiohraoifcpiapdpsahfahiofhdiohraoifcpiapdpsahfahiofhd...

output:


result: