QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#278546 | #3169. Editing Explosion | ddl_VS_pigeon# | AC ✓ | 111ms | 17056kb | C++20 | 1.9kb | 2023-12-07 17:05:50 | 2023-12-07 17:05:51 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
const int M = 998244353;
int main(void) {
ios::sync_with_stdio(false);
cin.tie(nullptr), cout.tie(nullptr);
string st;
int d;
cin >> st >> d;
int n = st.length();
map<char, int> id;
for (auto c : st) {
id[c] = 0;
}
vector<int> cnt(min(26, (int)id.size() + 1));
int idc = 0;
if ((int)id.size() < 26) {
cnt[idc++] = 26 - id.size();
}
for (auto &[c, i] : id) {
i = idc;
cnt[idc++] = 1;
}
vector<int> f(n + 1), s(n + 1);
for (int i = 0; i < n; i++) {
s[i + 1] = id[st[i]];
}
for (int i = 0; i <= n; i++) {
f[i] = i;
}
auto trans = [&](vector<int> f, int x) {
for (int i = n; i >= 0; i--) {
int val = f[i] + 1;
if (i > 0) {
val = min(val, f[i - 1] + (s[i] == x ? 0 : 1));
}
f[i] = min(val, d + 1);
}
for (int i = 1; i <= n; i++) {
f[i] = min({f[i], f[i - 1] + 1, d + 1});
}
return f;
};
map<vector<int>, int> idx;
vector<vector<int>> vec;
auto getid = [&](const vector<int> &f) {
int &res = idx[f];
if (res == 0) {
res = vec.size();
vec.emplace_back(f);
}
return res;
};
auto getmin = [&](const vector<int> &f) {
int x = d + 1;
for (auto v : f) {
x = min(x, v);
}
return x;
};
vector<int> g(1);
g[getid(f)] = 1;
int ans = (f[n] == d) ? 1 : 0;
for (int i = 0; i < n + d; i++) {
vector<int> ng(vec.size());
for (int j = 0; j < (int)g.size(); j++) {
if (g[j]) {
for (int x = 0; x < idc; x++) {
auto nf = trans(vec[j], x);
if (getmin(nf) > d) {
continue;
}
int k = getid(nf);
if (k == (int)ng.size()) {
ng.emplace_back(0);
}
ng[k] = (ng[k] + 1ll * g[j] * cnt[x]) % M;
}
}
}
swap(ng, g);
for (int i = 0; i < (int)vec.size(); i++) {
if (vec[i][n] == d) {
ans = (ans + g[i]) % M;
}
}
}
cout << ans << '\n';
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3896kb
input:
ICPC 1
output:
230
result:
ok single line: '230'
Test #2:
score: 0
Accepted
time: 57ms
memory: 11780kb
input:
PROGRAMMER 10
output:
110123966
result:
ok single line: '110123966'
Test #3:
score: 0
Accepted
time: 111ms
memory: 17056kb
input:
ABCDEFGHIJ 10
output:
258519532
result:
ok single line: '258519532'
Test #4:
score: 0
Accepted
time: 3ms
memory: 4552kb
input:
AAAAABBBBB 10
output:
877770338
result:
ok single line: '877770338'
Test #5:
score: 0
Accepted
time: 0ms
memory: 3604kb
input:
NOWISTHE 0
output:
1
result:
ok single line: '1'
Test #6:
score: 0
Accepted
time: 0ms
memory: 3644kb
input:
NOWISTHE 1
output:
434
result:
ok single line: '434'
Test #7:
score: 0
Accepted
time: 1ms
memory: 3972kb
input:
ABABABABAB 10
output:
555168781
result:
ok single line: '555168781'
Test #8:
score: 0
Accepted
time: 1ms
memory: 3796kb
input:
ABCDDEFGHI 3
output:
21580956
result:
ok single line: '21580956'
Test #9:
score: 0
Accepted
time: 61ms
memory: 10592kb
input:
ABCDDEFGHI 8
output:
49338700
result:
ok single line: '49338700'
Test #10:
score: 0
Accepted
time: 0ms
memory: 3604kb
input:
A 10
output:
864056661
result:
ok single line: '864056661'