QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#130239 | #464. 前缀函数 / KMP | cn_ryh# | WA | 5ms | 4016kb | C++14 | 1.2kb | 2023-07-23 18:43:19 | 2023-07-23 18:43:22 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define max_n 210101
void read(int &p)
{
p = 0;
int k = 1;
char c = getchar();
while(c < '0' || c > '9')
{
if(c == '-')
{
k = -1;
}
c = getchar();
}
while(c >= '0' && c<= '9')
{
p = p * 10 + c - '0';
c = getchar();
}
return ;
}
void write_(int x)
{
if(x < 0)
{
putchar('-');
x = -x;
}
if(x > 9)
{
write_(x / 10);
}
putchar(x % 10 + '0');
}
void writesp(int x)
{
write_(x);
putchar(' ');
}
void writeln(int x)
{
write_(x);
puts("");
}
char s[max_n];
vector<int> ans;
void solution()
{
int n = strlen(s);
ans.push_back(0);
for(int i = 1;i <= n;i++)
{
ans.push_back(0);
}
for(int i = 1;i < n;i++)
{
int j = ans[i - 1];
while(j && s[i] != s[j])
{
j = ans[j - 1];
}
if(s[i] == s[j])
{
++j;
}
ans[i] = j;
}
for(int i = 1;i <= n;i++)
{
writesp(ans[i]);
}
puts("");
}
signed main()
{
scanf("%s",s);
solution();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 5ms
memory: 4016kb
input:
mencimencimencimencimencimencimencimenciyvdfitnmencimencimencimencimencimencimencimenciyvdfitnmencimencimencimencimencimencimencimenciyvdfitnmencimencimencimencimencimencimencimenciyvdfitnmencimencimencimencimencimencimencimenciyvdfitnmencimencimencimencimencimencimencimenciyvdfitnmencimencimencimen...
output:
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 64...
result:
wrong answer 5th numbers differ - expected: '0', found: '1'