QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#106803 | #3169. Editing Explosion | skittles1412 | AC ✓ | 835ms | 26280kb | C++17 | 3.0kb | 2023-05-19 11:55:45 | 2023-05-19 11:55:48 |
Judging History
answer
#include "bits/extc++.h"
using namespace std;
template <typename T, typename... U>
void dbgh(const T& t, const U&... u) {
cerr << t;
((cerr << " | " << u), ...);
cerr << endl;
}
#ifdef DEBUG
#define dbg(...) \
cerr << "L" << __LINE__ << " [" << #__VA_ARGS__ << "]: "; \
dbgh(__VA_ARGS__)
#else
#define dbg(...)
#define cerr \
if (false) \
cerr
#endif
#define endl "\n"
#define long int64_t
#define sz(x) int(std::size(x))
struct mint {
static constexpr int MOD = 998244353;
static constexpr mint pow(mint base, long exp) {
mint ans = 1;
while (exp) {
if (exp & 1) {
ans *= base;
}
base *= base;
exp >>= 1;
}
return ans;
}
static constexpr int norm(long x) {
x %= MOD;
if (x < 0) {
x += MOD;
}
return int(x);
}
int x;
constexpr mint() : x(0) {}
constexpr mint(long x) : x(norm(x)) {}
static constexpr mint from_unchecked(int x) {
mint m;
m.x = x;
return m;
}
friend ostream& operator<<(ostream& out, mint m) {
return out << m.x;
}
mint operator-() const {
if (!x) {
return 0;
}
return from_unchecked(MOD - x);
}
mint& operator+=(const mint& m) {
x += m.x;
if (x >= MOD) {
x -= MOD;
}
return *this;
}
mint& operator-=(const mint& m) {
return *this += -m;
}
mint& operator*=(const mint& m) {
x = int(long(x) * m.x % MOD);
return *this;
}
friend mint operator+(mint a, const mint& b) {
return a += b;
}
friend mint operator-(mint a, const mint& b) {
return a -= b;
}
friend mint operator*(mint a, const mint& b) {
return a *= b;
}
};
int n, kv;
string s;
map<vector<int>, mint> memo[100];
mint dp(int ind, const vector<int>& state) {
if (ind > n + kv) {
return 0;
}
auto [it, inserted] = memo[ind].emplace(state, 0);
mint& ans = it->second;
if (!inserted) {
return ans;
}
if (state[n] == kv) {
ans += 1;
}
for (char c = 'A'; c <= 'Z'; c++) {
vector<int> ndp(n + 1);
for (int i = 0; i <= n; i++) {
ndp[i] = state[i] + 1;
if (i) {
ndp[i] = min(
{ndp[i], ndp[i - 1] + 1, state[i - 1] + 1 - (s[i - 1] == c)});
}
}
ans += dp(ind + 1, ndp);
}
return ans;
}
void solve() {
cin >> s >> kv;
n = sz(s);
cout << dp(0, ({
vector<int> v(n + 1);
iota(begin(v), end(v), 0);
v;
}))
<< endl;
}
int main() {
cin.tie(nullptr);
cin.exceptions(ios::failbit);
ios_base::sync_with_stdio(false);
solve();
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3428kb
input:
ICPC 1
output:
230
result:
ok single line: '230'
Test #2:
score: 0
Accepted
time: 467ms
memory: 16836kb
input:
PROGRAMMER 10
output:
110123966
result:
ok single line: '110123966'
Test #3:
score: 0
Accepted
time: 835ms
memory: 26280kb
input:
ABCDEFGHIJ 10
output:
258519532
result:
ok single line: '258519532'
Test #4:
score: 0
Accepted
time: 25ms
memory: 4312kb
input:
AAAAABBBBB 10
output:
877770338
result:
ok single line: '877770338'
Test #5:
score: 0
Accepted
time: 20ms
memory: 4144kb
input:
NOWISTHE 0
output:
1
result:
ok single line: '1'
Test #6:
score: 0
Accepted
time: 18ms
memory: 4360kb
input:
NOWISTHE 1
output:
434
result:
ok single line: '434'
Test #7:
score: 0
Accepted
time: 5ms
memory: 3760kb
input:
ABABABABAB 10
output:
555168781
result:
ok single line: '555168781'
Test #8:
score: 0
Accepted
time: 350ms
memory: 13832kb
input:
ABCDDEFGHI 3
output:
21580956
result:
ok single line: '21580956'
Test #9:
score: 0
Accepted
time: 652ms
memory: 21316kb
input:
ABCDDEFGHI 8
output:
49338700
result:
ok single line: '49338700'
Test #10:
score: 0
Accepted
time: 2ms
memory: 3412kb
input:
A 10
output:
864056661
result:
ok single line: '864056661'