QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#721638#5312. Levenshtein DistancemasonpopWA 3295ms16272kbC++142.6kb2024-11-07 16:30:252024-11-07 16:30:26

Judging History

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

  • [2024-11-07 16:30:26]
  • 评测
  • 测评结果:WA
  • 用时:3295ms
  • 内存:16272kb
  • [2024-11-07 16:30:25]
  • 提交

answer

// ubsan: undefined
// accoders
#include <bits/stdc++.h>
using namespace std;
#define ull unsigned long long
const int maxn = 5e4 + 10;
const int maxm = 65;
const int D = 30;
const ull B = 131;
int lim, n, m, f[maxm][maxm], ans[maxm], M, L[maxn][maxm];
char s[maxn], t[maxn], tmp[maxn];
ull pw[maxn], H[2][maxn];
inline ull get(int l, int r, int id) { return H[id][r] - H[id][l - 1] * pw[r - l + 1]; }
inline int LCP(int x, int y) {
    if (x < 0 || x > n || y < 0 || y > m)
        return 0;
    int l = 1, r = min(n - x + 1, m - y + 1), res = 0;
    while (l <= r) {
        int mid = (l + r) >> 1;
        if (get(x, x + mid - 1, 0) == get(y, y + mid - 1, 1))
            res = mid, l = mid + 1;
        else
            r = mid - 1;
    }
    return res;
}
inline void chkmax(int &a, int b) { a = max(a, b); }
int main() {
    scanf("%d", &lim);
    scanf("%s", s + 1);
    scanf("%s", t + 1);
    n = strlen(s + 1);
    m = strlen(t + 1);
    pw[0] = 1;
    for (int i = 1; i <= max(n, m); i++) pw[i] = pw[i - 1] * B;
    for (int i = 1; i <= n; i++) H[0][i] = H[0][i - 1] * B + s[i] - 'a' + 1;
    for (int i = 1; i <= m; i++) H[1][i] = H[1][i - 1] * B + t[i] - 'a' + 1;
    for (int i = 0; i <= n; i++) {
        for (int j = max(i - D, 0); j <= min(i + D, m); j++) L[i][j - i + D] = LCP(i + 1, j + 1);
    }
    for (int st = 1; st <= m; st++) {
        // printf("st %d\n",st);
        M = m - st + 1;
        for (int j = st; j <= m; j++) tmp[j - st + 1] = t[j];
        memset(f, 0xcf, sizeof(f));
        f[0][D] = 0;
        for (int i = 0; i <= lim; i++) {
            for (int j = -D; j <= D; j++) {
                if (f[i][j + D] < 0)
                    continue;
                int pos = f[i][j + D];
                // printf("pos1:%d,pos2:%d,lcp:%d\n",pos,pos+j+st-1,L[pos][j+(st-1)+D]);
                f[i][j + D] += LCP(pos + 1, pos + st + j);
                if (i != lim) {
                    chkmax(f[i + 1][j - 1 + D], f[i][j + D] + 1);
                    chkmax(f[i + 1][j + 1 + D], f[i][j + D]);
                    chkmax(f[i + 1][j + D], f[i][j + D] + 1);
                }
            }
        }
        // printf("f:%d\n",f[1][-1+D]);
        for (int j = -D; j <= D; j++) {
            for (int i = 0; i <= lim; i++) {
                if (n + j <= 0 || n + j > (m - st + 1) || f[i][j + D] < n)
                    continue;
                // printf("i %d,j %d\n",i,j);
                ans[i]++;
                break;
            }
        }
    }
    for (int i = 0; i <= lim; i++) printf("%d\n", ans[i]);
    return 0;
}

詳細信息

Test #1:

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

input:

4
aaa
aabbaab

output:

0
5
15
7
1

result:

ok 5 number(s): "0 5 15 7 1"

Test #2:

score: 0
Accepted
time: 1956ms
memory: 16244kb

input:

30
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA...

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
0
0
0
0
0
0

result:

ok 31 numbers

Test #3:

score: -100
Wrong Answer
time: 3295ms
memory: 16272kb

input:

30
BBAAABAABBBA
ABBABBBBAABAAAABABBBAABAABBAABAAAAAABAABABBAAAABAAAAABABAABAABBABBAAAABBBBAABBABAAABAABAABBBBBABBABABBBBABBBBAAABBABABBBBAAABBBBAAAABABABABABABABAAABBBBBAABAABAABBAABBBAABBBBBBBABAABAABAABABAABAAABAABBBAABABBABBAAABAAAABABABBABBBAAABBBAAAABBBBABABABAABAABBBBBBBBBAABBBABABBBABAABBABBA...

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
0
0
0
0
0
0

result:

wrong answer 1st numbers differ - expected: '17', found: '0'