QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#368546#850. Edit Distance Yet AgainJerryTclWA 1ms3788kbC++202.4kb2024-03-27 12:07:442024-03-27 12:07:46

Judging History

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

  • [2024-03-27 12:07:46]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3788kb
  • [2024-03-27 12:07:44]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
using uint64 = unsigned long long;
void Solve() {
    int n, m, k; cin >> n >> m >> k;
    if(abs(n - m) > k) return puts("NO"), void();
    string s, t; cin >> s >> t;
    vector<uint64> hshs(n + 1), hsht(m + 1);
    vector<uint64> pw(max(n, m) + 1); pw[0] = 1;
    const int B = 137; const uint64 Mod = 1e17l + 7;
    const auto Hsh = [&](const vector<uint64> &h, int p, int q)
        { return (h[p + q] + (__uint128_t)(Mod - h[p]) * pw[q]) % Mod; };
    for(int i = 0; i < max(n, m); ++i) pw[i + 1] = pw[i] * B % Mod;
    for(int i = 0; i < n; ++i) hshs[i + 1] = (hshs[i] * B + s[i] - 'a') % Mod;
    for(int i = 0; i < m; ++i) hsht[i + 1] = (hsht[i] * B + t[i] - 'a') % Mod;
    const auto &match = [&](int x, int ofs) {
        const int y = x + ofs; int A = x;
        if(x > n || y > m) return 0;
        for(int L = x + 1, R = n; L <= R; ) {
            const int M = (L + R) >> 1, e = M - x;
            const uint64 u = Hsh(hshs, x, e), v = Hsh(hsht, y, e);
            if(u == v) L = M + 1, A = M; else R = M - 1;
        }
        return A;
    };
    using pii = pair<int, int>; vector<vector<pii>> f;
    f.emplace_back(1, pii(match(0, 0), 0));
    const auto &Cmax = [](pii &x, pii y) { x = max(x, y); };
    const auto &check = [&](int p) {
        if(f[p][m - n + p].first != n) return 0;
        printf("YES\n%d\n", p);
        for(int w = m - n; p > 0; --p) {
            const int V = f[p][w + p].second;
            const int u = V >> 2, v = u + 1, ofs = V & 3;
            switch(ofs) {
                case 0: printf("DELETE %d\n", v), ++w; break;
                case 1: printf("REPLACE %d %c\n", v, t[u + w]); break;
                case 2: printf("INSERT %d %c\n", v, t[u + --w]); break;
            }
        }
        return 1;
    };
    for(int p = 0, q = 1;; ++p, ++q) {
        if(abs(n - m) <= p && check(p)) return;
        if(p == k) return puts("NO"), void();
        f.emplace_back(q << 1 | 1, pii(0, 0));
        for(int i = 0; i <= p * 2; ++i) {
            const int s = f[p][i].first, t = s << 2;
            Cmax(f[q][i + 0], {match(s + 1, i - q), t | 0});
            Cmax(f[q][i + 1], {match(s + 1, i - p), t | 1});
            Cmax(f[q][i + 2], {match(s, i - p + 1), t | 2});
        }
    }
}
int main() {
    cin.tie(0)->sync_with_stdio(0);
    int T; cin >> T; while(T--) Solve();
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 3788kb

input:

2
3 4 3
kot
plot
5 7 3
zycie
porazka

output:

YES
2
INSERT 2 l
REPLACE 1 p
NO

result:

ok OK!

Test #2:

score: -100
Wrong Answer
time: 1ms
memory: 3748kb

input:

100
100 100 0
mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm
mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm
16 7 100
vvvvvvvvvvvvvvvv
qydopaq
37 33 43
ggggggggggggggggggggggggggggggggggggg
osk...

output:

YES
0
YES
16
REPLACE 16 q
REPLACE 15 a
REPLACE 14 p
REPLACE 13 o
REPLACE 12 d
REPLACE 11 y
REPLACE 10 q
DELETE 9
DELETE 8
DELETE 7
DELETE 6
DELETE 5
DELETE 4
DELETE 3
DELETE 2
DELETE 1
YES
28
REPLACE 37 o
REPLACE 36 o
REPLACE 35 a
REPLACE 34 a
DELETE 33
DELETE 32
DELETE 31
DELETE 30
REPLACE 27 p
REP...

result:

wrong answer At test 6 expected YES got NO