QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#432000 | #850. Edit Distance Yet Again | Made_in_Code | WA | 4ms | 15336kb | C++14 | 2.4kb | 2024-06-06 15:45:22 | 2024-06-06 15:45:22 |
Judging History
answer
#include <iostream>
#define ULL unsigned long long
using namespace std;
const int kMaxN = 1e6 + 1, kMaxM = 1001;
const int kInf = 1e9, kBase = 15553;
int o, n, m, k, f[kMaxM << 1][kMaxM];
ULL hs[kMaxN], ht[kMaxN], pw[kMaxN];
string s, t;
void Max(int &x, int y) { x = max(x, y); }
int W() {
for (int i = 0; i <= k; i++) {
if (f[n - m + kMaxM][i] == m) {
cout << "YES\n"
<< i << '\n';
return i;
}
}
cout << "NO\n";
return 0;
}
int Print(int n, int m, int x) {
if (x <= 0) {
return n + 1;
} else if (f[n - m + 1 + kMaxM][x - 1] >= m - 1) {
int w = Print(n, m - 1, x - 1);
cout << "INSERT " << w << ' ' << t[m] << '\n';
return w + 1;
} else if (f[n - m - 1 + kMaxM][x - 1] >= m) {
int w = Print(n - 1, m, x - 1);
cout << "DELETE " << w << '\n';
return w;
} else if (s[n] != t[m]) {
int w = Print(n - 1, m - 1, x - 1);
cout << "REPLACE " << w << ' ' << t[m] << '\n';
return w + 1;
}
return Print(n - 1, m - 1, x) + 1;
}
int main() {
cin.tie(0), cout.tie(0);
ios::sync_with_stdio(0);
pw[0] = 1;
for (int i = 1; i < kMaxN; i++) {
pw[i] = pw[i - 1] * kBase;
}
cin >> o;
while (o--) {
cin >> n >> m >> k >> s >> t;
if (abs(n - m) > k) {
cout << "NO\n";
continue;
}
s = '~' + s, t = '~' + t;
for (int i = 1; i <= n; i++) {
hs[i] = hs[i - 1] * kBase + s[i];
}
for (int i = 1; i <= m; i++) {
ht[i] = ht[i - 1] * kBase + t[i];
}
for (int i = max(-k, -m); i <= min(k, n); i++) {
f[i + kMaxM][0] = min(-i, 0);
}
for (int &i = f[kMaxM][0] = 0; i < n && i < m && s[i + 1] == t[i + 1]; i++) {
}
for (int x = 1; x <= k; x++) {
for (int i = max(-k, -m); i <= min(k, n); i++) {
int &p = f[i + kMaxM][x];
p = f[i + kMaxM][x - 1] + 1;
if (i > -k) {
p = max(p, f[i - 1 + kMaxM][x - 1]);
}
if (i < k) {
p = max(p, min(f[i + 1 + kMaxM][x - 1] + 1, m));
}
if (p >= max(-i, 0)) {
int l = p + 1, r = min(n - i, m);
while (l <= r) {
int mid = l + r >> 1;
ULL ws = hs[i + mid] - hs[i + p] * pw[mid - p];
ULL wt = ht[mid] - ht[p] * pw[mid - p];
ws == wt ? l = mid + 1 : r = mid - 1;
}
p = r;
}
}
}
Print(n, m, W());
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 4ms
memory: 14956kb
input:
2 3 4 3 kot plot 5 7 3 zycie porazka
output:
YES 2 REPLACE 1 p INSERT 2 l NO
result:
ok OK!
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 15336kb
input:
100 100 100 0 mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm 16 7 100 vvvvvvvvvvvvvvvv qydopaq 37 33 43 ggggggggggggggggggggggggggggggggggggg osk...
output:
YES 0 YES 8 INSERT 17 ~ INSERT 18 q INSERT 19 y INSERT 20 d INSERT 21 o INSERT 22 p INSERT 23 a INSERT 24 q YES 28 REPLACE 1 o REPLACE 2 s REPLACE 3 k REPLACE 5 m REPLACE 6 l REPLACE 8 j REPLACE 9 t REPLACE 10 u REPLACE 11 a REPLACE 13 s REPLACE 16 t REPLACE 17 a REPLACE 18 w REPLACE 19 f REPLACE 20...
result:
wrong answer At test 1 expected 16 got 8