QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#106996#3169. Editing Explosionmarsxiang5902AC ✓84ms4260kbC++171.2kb2023-05-20 04:46:252023-05-20 04:46:28

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-05-20 04:46:28]
  • 评测
  • 测评结果:AC
  • 用时:84ms
  • 内存:4260kb
  • [2023-05-20 04:46:25]
  • 提交

answer

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

const int MN = 11, MOD = 119<<23|1, MC = 26, MD = 59049;
inline void add(int &x, int v) { x += v-MOD; x += x>>31 & MOD; }

int N, D, ar[MN], tmp[MN], tmpN[MN], dpPv[MD], dpCur[MD]; string s;

int main() {
  ios_base::sync_with_stdio(0); cin.tie(0);

  cin >> s >> D; N = s.size();
  for (int i = 0; i < N; i++)
    ar[i] = s[i]-'A';
  int pw = 1;
  for (int i = 0; i < N; i++)
    pw *= 3;
  dpPv[pw-1] = 1;
  int ans = 0;
  for (int l = 0; l <= N+D; l++) {
    tmp[0] = l; tmpN[0] = l+1;
    memset(dpCur, 0, sizeof dpCur);
    for (int msk = 0; msk < pw; msk++) {
      if (!dpPv[msk]) continue;
      for (int i = 1, m = msk; i <= N; i++)
        tmp[i] = tmp[i-1] + m%3 - 1,
        m /= 3;
      if (tmp[N] == D) add(ans, dpPv[msk]);
      for (int z = 0; z < MC; z++) {
        int m1 = 0;
        for (int i = 1, p = 1; i <= N; i++)
          tmpN[i] = min({tmp[i] + 1, tmpN[i-1] + 1, tmp[i-1] + (z != ar[i-1])}),
          m1 += p * (tmpN[i] - tmpN[i-1] + 1),
          p *= 3;
        add(dpCur[m1], dpPv[msk]);
      }
    }
    memcpy(dpPv, dpCur, sizeof dpPv);
  }
  printf("%d\n", ans);

  return 0;
}

详细

Test #1:

score: 100
Accepted
time: 2ms
memory: 4200kb

input:

ICPC 1

output:

230

result:

ok single line: '230'

Test #2:

score: 0
Accepted
time: 52ms
memory: 3992kb

input:

PROGRAMMER 10

output:

110123966

result:

ok single line: '110123966'

Test #3:

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

input:

ABCDEFGHIJ 10

output:

258519532

result:

ok single line: '258519532'

Test #4:

score: 0
Accepted
time: 4ms
memory: 4252kb

input:

AAAAABBBBB 10

output:

877770338

result:

ok single line: '877770338'

Test #5:

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

input:

NOWISTHE 0

output:

1

result:

ok single line: '1'

Test #6:

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

input:

NOWISTHE 1

output:

434

result:

ok single line: '434'

Test #7:

score: 0
Accepted
time: 3ms
memory: 3992kb

input:

ABABABABAB 10

output:

555168781

result:

ok single line: '555168781'

Test #8:

score: 0
Accepted
time: 36ms
memory: 4016kb

input:

ABCDDEFGHI 3

output:

21580956

result:

ok single line: '21580956'

Test #9:

score: 0
Accepted
time: 66ms
memory: 4016kb

input:

ABCDDEFGHI 8

output:

49338700

result:

ok single line: '49338700'

Test #10:

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

input:

A 10

output:

864056661

result:

ok single line: '864056661'