QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#341073#464. 前缀函数 / KMPYansuan_HCl#WA 5ms3984kbC++14810b2024-02-29 15:27:292024-02-29 15:27:32

Judging History

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

  • [2024-02-29 15:27:32]
  • 评测
  • 测评结果:WA
  • 用时:5ms
  • 内存:3984kb
  • [2024-02-29 15:27:29]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define IC isdigit(c)
#define GC c=getchar()
void rd(auto &x) { char GC; x = 0; bool f = 0;
	for (; !IC; GC) if (c == '-') f = 1;
	for (; IC; GC) x = x * 10 + c - 48;
	if (f) x = -x;
}
void rd(auto &x, auto &...y) { rd(x); rd(y...); }
#define U(i,l,r) for(int i(l),END##i(r); i<=END##i; ++i)
#define D(i,l,r) for(int i(l),END##i(r); i>=END##i; --i)
#define ms(x, v) memset(x, v, sizeof(x))
#define meow(...) fprintf(stderr, __VA_ARGS__)
using ll = long long;

const int N = 100005;
char s[N]; int n;
int fail[N];

int main() {
	scanf("%s", s + 1); n = strlen(s + 1);
	for (int i = 1, j = 0; i <= n; ++i) {
		while (j && s[j + 1] != s[i])
			j = fail[j];
		if (j + 1 < i && s[j + 1] == s[i])
			++j;
		printf("%d ", j);
	}
	puts("");
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 3984kb

input:

mencimencimencimencimencimencimencimenciyvdfitnmencimencimencimencimencimencimencimenciyvdfitnmencimencimencimencimencimencimencimenciyvdfitnmencimencimencimencimencimencimencimenciyvdfitnmencimencimencimencimencimencimencimenciyvdfitnmencimencimencimencimencimencimencimenciyvdfitnmencimencimencimen...

output:

0 0 0 0 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 0 0 0 0 0 0 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 ...

result:

ok 100000 numbers

Test #2:

score: 0
Accepted
time: 2ms
memory: 3984kb

input:

hyaknoipnoizjoictsapioioihyaknoipnoizjoictsapioioihyaknoipnoizjoictsapioioihyaknoipnoizjoictsapioioihyaknoipnoizjoictsapioioihyaknoipnoizjoictsapioioihyaknoipnoizjoictsapioioihyaknoipnoizjoictsapioioihyaknoipnoizjoictsapioioihyaknoipnoizjoictsapioioihyaknoipnoizjoictsapioioihyaknoipnoizjoictsapioioi...

output:

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 8...

result:

ok 100000 numbers

Test #3:

score: -100
Wrong Answer
time: 5ms
memory: 3840kb

input:

dccdcbacdadaccadcbddcccadcbaccdcaacaacaacdddadddaccacbccdcdbcbccbabaacbdccadadaadcadadbcbbccabadcbdbbabaabdbdabdacbcadadccacaadddabadcabdbddadacdcdbddccbadccdbcadddbabcbddbadbdccbcabbbcacddbdbcbdabaaabcbcbcdccaabbbbddbcbdcbcacbbbdbdbdcccbcadadbcdabdaccbdaadadcdacabbdadababadccaddbcbacdddbdaddadcabaa...

output:

0 0 0 1 2 0 0 0 1 0 1 0 0 0 0 1 2 0 1 1 2 3 0 0 1 2 0 0 0 0 1 2 0 0 0 0 0 0 0 0 0 1 1 1 0 1 1 1 0 0 0 0 0 0 0 0 1 2 1 0 0 0 0 0 0 0 0 0 0 0 0 1 2 3 0 1 0 1 0 0 1 2 0 1 0 1 0 0 0 0 0 0 0 0 0 1 2 0 1 0 0 0 0 0 0 0 1 0 1 0 0 1 0 0 0 0 0 1 0 1 2 3 0 0 0 0 1 1 1 0 0 0 1 2 0 0 1 0 1 1 0 1 0 0 1 2 1 0 1 1 ...

result:

wrong answer 404th numbers differ - expected: '3', found: '0'