QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#232520 | #3169. Editing Explosion | 8BQube# | AC ✓ | 200ms | 6936kb | C++20 | 2.0kb | 2023-10-30 15:55:56 | 2023-10-30 15:55:56 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define X first
#define Y second
#define pb push_back
#define SZ(a) ((int)a.size())
#define ALL(v) v.begin(), v.end()
const int N = 2e5 + 5;
const ll M = 998244353;
void add(ll &a, ll b) {
a = (a + b);
if (a >= M)
a -= M;
}
ll dp[2][N];
int hs(vector<int> &v) {
int res = 0;
for (int i = 1, bs = 1; i < SZ(v); i++, bs *= 3) {
assert(abs(v[i] - v[i - 1]) <= 1);
if (v[i] < v[i - 1])
res += 0 * bs;
else if (v[i] == v[i - 1])
res += 1 * bs;
else
res += 2 * bs;
}
return res;
}
vector<int> rhs(int now, int n, int I) {
vector<int> res;
res.pb(now);
for (int i = 1; i <= n; i++) {
int x = I % 3;
I /= 3;
if (x == 0)
--now;
else if (x == 1)
;
else
++now;
res.pb(now);
}
return res;
}
int main() {
ios::sync_with_stdio(0), cin.tie(0);
string s;
int d;
cin >> s >> d;
int n = SZ(s);
ll ans = 0;
int fg = 0;
{
vector<int> tmp;
for (int i = 0; i <= n; i++)
tmp.pb(i);
dp[0][hs(tmp)] = 1;
}
int C = 1;
for (int i = 1; i <= n; i++)
C *= 3;
for (int kz = 1; kz <= 21; kz++) {
fg = !fg;
memset(dp[fg], 0, sizeof(dp[fg]));
for (int I = 0; I < C; I++)
if (dp[!fg][I]) {
vector<int> cur = rhs(kz - 1, n, I);
if (cur.back() == d)
add(ans, dp[!fg][I]);
for (int j = 0; j < 26; j++) {
vector<int> nxt(n + 1);
nxt[0] = kz;
for (int k = 1; k <= n; k++)
nxt[k] = min({nxt[k - 1] + 1, cur[k] + 1, cur[k - 1] + (j != (s[k - 1] - 'A'))});
add(dp[fg][hs(nxt)], dp[!fg][I]);
}
}
}
cout << ans << endl;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 6692kb
input:
ICPC 1
output:
230
result:
ok single line: '230'
Test #2:
score: 0
Accepted
time: 121ms
memory: 6860kb
input:
PROGRAMMER 10
output:
110123966
result:
ok single line: '110123966'
Test #3:
score: 0
Accepted
time: 200ms
memory: 6708kb
input:
ABCDEFGHIJ 10
output:
258519532
result:
ok single line: '258519532'
Test #4:
score: 0
Accepted
time: 7ms
memory: 6732kb
input:
AAAAABBBBB 10
output:
877770338
result:
ok single line: '877770338'
Test #5:
score: 0
Accepted
time: 30ms
memory: 6636kb
input:
NOWISTHE 0
output:
1
result:
ok single line: '1'
Test #6:
score: 0
Accepted
time: 30ms
memory: 6708kb
input:
NOWISTHE 1
output:
434
result:
ok single line: '434'
Test #7:
score: 0
Accepted
time: 7ms
memory: 6888kb
input:
ABABABABAB 10
output:
555168781
result:
ok single line: '555168781'
Test #8:
score: 0
Accepted
time: 182ms
memory: 6936kb
input:
ABCDDEFGHI 3
output:
21580956
result:
ok single line: '21580956'
Test #9:
score: 0
Accepted
time: 183ms
memory: 6924kb
input:
ABCDDEFGHI 8
output:
49338700
result:
ok single line: '49338700'
Test #10:
score: 0
Accepted
time: 0ms
memory: 6676kb
input:
A 10
output:
864056661
result:
ok single line: '864056661'