QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#340826 | #464. 前缀函数 / KMP | KevinLikesCoding# | WA | 5ms | 4280kb | C++14 | 851b | 2024-02-29 13:01:48 | 2024-02-29 13:01:48 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i,n,m) for(int i=(n);i<=(m);i++)
#define ROF(i,n,m) for(int i=(n);i>=(m);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define SZ(v) v.size()
#define pb push_back
template < typename A , typename B>
inline bool chmax(A &x, B y) { return (x < y ? (x = y, true) : false); }
template < typename A , typename B>
inline bool chmin(A &x, B y) { return (x > y ? (x = y, true) : false); }
const int N = 1e5 + 5;
int n, p[N];
string s;
void solve() {
cin >> s; n = SZ(s); s = ' ' + s;
FOR(i, 2, n) {
int j = p[i - 1];
while(j && s[j + 1] != s[i]) j = p[j - 1];
if(s[j + 1] == s[i]) j++;
p[i] = j;
}
FOR(i, 1, n) cout << p[i] << " ";
cout << endl;
}
int main() {
ios :: sync_with_stdio(0);
cin.tie(0); cout.tie(0);
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 5ms
memory: 4280kb
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:
wrong answer 753rd numbers differ - expected: '0', found: '466'