QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#140033#3169. Editing ExplosionKirill22#AC ✓447ms6784kbC++231.5kb2023-08-14 23:55:302023-08-14 23:55:34

Judging History

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

  • [2023-08-14 23:55:34]
  • 评测
  • 测评结果:AC
  • 用时:447ms
  • 内存:6784kb
  • [2023-08-14 23:55:30]
  • 提交

answer

#include "bits/stdc++.h"

using namespace std;

const int mod = 998244353;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    string s;
    int d;
    cin >> s >> d;
    map<char, int> cnt;
    for (auto c : s) {
        cnt[c] = 1;
    }
    {
        char z = 'A';
        while (cnt.find(z) != cnt.end()) {
            z++;
        }
        for (char c = 'A'; c <= 'Z'; c++) {
            if (cnt.find(c) == cnt.end()) {
                cnt[z]++;
            }
        }
    }
    int n = (int) s.size(), ans = 0;
    map<vector<int>, int> dp, dp2;
    {
        vector<int> f(n + 1);
        iota(f.begin(), f.end(), 0);
        dp[f]++;
        if (f.back() == d) {
            ans++;
        }
    }
    for (int l = 1; l <= n + d; l++) {
        dp2.clear();
        for (auto& [c, y] : cnt){
            for (auto& [arr, x] : dp) {
                vector<int> f(n + 1, (int) 1e9);
                f[0] = l;
                for (int i = 1; i <= n; i++) {
                    f[i] = min(f[i], f[i - 1] + 1);
                    f[i] = min(f[i], arr[i] + 1);
                    f[i] = min(f[i], arr[i - 1] + (int) (s[i - 1] != c));
                }
                dp2[f] = (dp2[f] + x * 1ll * y % mod) % mod;
            }
        }
        dp = dp2;
        for (auto& [arr, x] : dp) {
            if (arr.back() == d) {
                ans = (ans + x) % mod;
            }
        }
    }
    cout << ans << '\n';
}

详细

Test #1:

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

input:

ICPC 1

output:

230

result:

ok single line: '230'

Test #2:

score: 0
Accepted
time: 187ms
memory: 5548kb

input:

PROGRAMMER 10

output:

110123966

result:

ok single line: '110123966'

Test #3:

score: 0
Accepted
time: 447ms
memory: 6784kb

input:

ABCDEFGHIJ 10

output:

258519532

result:

ok single line: '258519532'

Test #4:

score: 0
Accepted
time: 6ms
memory: 3688kb

input:

AAAAABBBBB 10

output:

877770338

result:

ok single line: '877770338'

Test #5:

score: 0
Accepted
time: 9ms
memory: 3952kb

input:

NOWISTHE 0

output:

1

result:

ok single line: '1'

Test #6:

score: 0
Accepted
time: 12ms
memory: 3956kb

input:

NOWISTHE 1

output:

434

result:

ok single line: '434'

Test #7:

score: 0
Accepted
time: 2ms
memory: 3512kb

input:

ABABABABAB 10

output:

555168781

result:

ok single line: '555168781'

Test #8:

score: 0
Accepted
time: 169ms
memory: 6520kb

input:

ABCDDEFGHI 3

output:

21580956

result:

ok single line: '21580956'

Test #9:

score: 0
Accepted
time: 304ms
memory: 6544kb

input:

ABCDDEFGHI 8

output:

49338700

result:

ok single line: '49338700'

Test #10:

score: 0
Accepted
time: 1ms
memory: 3508kb

input:

A 10

output:

864056661

result:

ok single line: '864056661'