QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#384407#464. 前缀函数 / KMPucup-team004WA 5ms3852kbC++20610b2024-04-09 23:06:302024-04-09 23:06:30

Judging History

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

  • [2024-04-09 23:06:30]
  • 评测
  • 测评结果:WA
  • 用时:5ms
  • 内存:3852kb
  • [2024-04-09 23:06:30]
  • 提交

answer

#include <bits/stdc++.h>

using i64 = long long;

std::vector<int> KMP(const std::string &s) {
    int n = s.size();
    std::vector<int> f(n + 1);
    for (int i = 1, j = 0; i < n; i++) {
        while (j && s[i] != s[j]) {
            j = f[j];
        }
        j += (s[i] == s[j]);
        f[i + 1] = j;
    }
    return f;
}
int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    
    std::string s;
    std::cin >> s;
    
    auto z = KMP(s);
    for (auto x : z) {
        std::cout << x << " ";
    }
    std::cout << "\n";
    
    return 0;
}

详细

Test #1:

score: 0
Wrong Answer
time: 5ms
memory: 3852kb

input:

mencimencimencimencimencimencimencimenciyvdfitnmencimencimencimencimencimencimencimenciyvdfitnmencimencimencimencimencimencimencimenciyvdfitnmencimencimencimencimencimencimencimenciyvdfitnmencimencimencimencimencimencimencimenciyvdfitnmencimencimencimencimencimencimencimenciyvdfitnmencimencimencimen...

output:

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

result:

wrong answer 6th numbers differ - expected: '1', found: '0'