QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#376687#3169. Editing Explosionckiseki#AC ✓778ms28096kbC++201.5kb2024-04-04 15:06:022024-04-04 15:06:03

Judging History

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

  • [2024-04-04 15:06:03]
  • 评测
  • 测评结果:AC
  • 用时:778ms
  • 内存:28096kb
  • [2024-04-04 15:06:02]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

#define all(x) begin(x), end(x)
#ifdef CKISEKI
#define safe cerr << __PRETTY_FUNCTION__ << " line " << __LINE__ << "\n";
#define debug(a...) debug_(#a, a)
#define orange(a...) orange_(#a, a)
void debug_(auto s, auto ...a) {
  cerr << "\e[1;32m(" << s << ") = (";
  int f = 0;
  (..., (cerr << (f++ ? ", " : "") << a));
  cerr << ")\e[0m\n";
}
#include <experimental/iterator>
void orange_(auto s, auto L, auto R) {
  cerr << "\e[1;33m[ " << s << " ] = [ ";
  using namespace experimental;
  copy(L, R, make_ostream_joiner(cerr, ", "));
  cerr << " ]\e[0m\n";
}
#else
#define safe ((void)0)
#define debug(...) safe
#define orange(...) safe
#endif

int main() {
  cin.tie(nullptr)->sync_with_stdio(false);
  string str;
  int d;
  cin >> str >> d;

  const int n = (int)str.size();

  vector<int> NDP(n + 1);

  vector<map<vector<int>, int>> dp(22);
  {
    vector<int> vv(n + 1);
    iota(all(vv), 0);
    dp[0][vv] = 1;
  }

  constexpr int mod = 998244353;
  int ans = 0;

  for (int t = 0; t <= 20; t++) {

    for (const auto &[DP, val] : dp[t]) {
      if (DP[n] == d)
        ans = (ans + val) % mod;

      for (char c = 'A'; c <= 'Z'; c++) {
        for (int i = 0; i <= n; i++) {
          NDP[i] = DP[i] + 1;
          if (i) NDP[i] = min(NDP[i], NDP[i - 1] + 1);
          if (i) {
            NDP[i] = min(NDP[i], DP[i - 1] + (c != str[i - 1]));
          }
        }

        dp[t + 1][NDP] += val;
        dp[t + 1][NDP] %= mod;
      }
    }
    debug(dp[t].size());
  }

  cout << ans << '\n';

  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

ICPC 1

output:

230

result:

ok single line: '230'

Test #2:

score: 0
Accepted
time: 442ms
memory: 17988kb

input:

PROGRAMMER 10

output:

110123966

result:

ok single line: '110123966'

Test #3:

score: 0
Accepted
time: 778ms
memory: 28096kb

input:

ABCDEFGHIJ 10

output:

258519532

result:

ok single line: '258519532'

Test #4:

score: 0
Accepted
time: 23ms
memory: 4560kb

input:

AAAAABBBBB 10

output:

877770338

result:

ok single line: '877770338'

Test #5:

score: 0
Accepted
time: 89ms
memory: 7056kb

input:

NOWISTHE 0

output:

1

result:

ok single line: '1'

Test #6:

score: 0
Accepted
time: 84ms
memory: 7192kb

input:

NOWISTHE 1

output:

434

result:

ok single line: '434'

Test #7:

score: 0
Accepted
time: 5ms
memory: 3820kb

input:

ABABABABAB 10

output:

555168781

result:

ok single line: '555168781'

Test #8:

score: 0
Accepted
time: 683ms
memory: 25904kb

input:

ABCDDEFGHI 3

output:

21580956

result:

ok single line: '21580956'

Test #9:

score: 0
Accepted
time: 706ms
memory: 25896kb

input:

ABCDDEFGHI 8

output:

49338700

result:

ok single line: '49338700'

Test #10:

score: 0
Accepted
time: 0ms
memory: 3840kb

input:

A 10

output:

864056661

result:

ok single line: '864056661'