結果

問題 No.2437 Fragile Multiples of 11
ユーザー Nzt3Nzt3
提出日時 2023-08-11 16:08:41
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 205 ms / 2,000 ms
コード長 1,483 bytes
コンパイル時間 2,396 ms
コンパイル使用メモリ 209,696 KB
実行使用メモリ 38,784 KB
最終ジャッジ日時 2024-04-29 09:34:21
合計ジャッジ時間 6,306 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
5,248 KB
testcase_01 AC 6 ms
5,376 KB
testcase_02 AC 19 ms
7,424 KB
testcase_03 AC 205 ms
38,656 KB
testcase_04 AC 138 ms
38,784 KB
testcase_05 AC 165 ms
38,656 KB
testcase_06 AC 173 ms
38,656 KB
testcase_07 AC 173 ms
38,656 KB
testcase_08 AC 176 ms
38,784 KB
testcase_09 AC 163 ms
38,656 KB
testcase_10 AC 167 ms
38,656 KB
testcase_11 AC 171 ms
38,656 KB
testcase_12 AC 173 ms
38,656 KB
testcase_13 AC 171 ms
38,784 KB
testcase_14 AC 164 ms
38,656 KB
testcase_15 AC 3 ms
5,376 KB
testcase_16 AC 3 ms
5,376 KB
testcase_17 AC 3 ms
5,376 KB
testcase_18 AC 4 ms
5,376 KB
testcase_19 AC 3 ms
5,376 KB
testcase_20 AC 3 ms
5,376 KB
testcase_21 AC 4 ms
5,376 KB
testcase_22 AC 3 ms
5,376 KB
testcase_23 AC 3 ms
5,376 KB
testcase_24 AC 37 ms
11,264 KB
testcase_25 AC 21 ms
7,552 KB
testcase_26 AC 18 ms
7,040 KB
testcase_27 AC 34 ms
11,008 KB
testcase_28 AC 164 ms
37,248 KB
testcase_29 AC 148 ms
33,408 KB
testcase_30 AC 145 ms
33,536 KB
testcase_31 AC 126 ms
29,952 KB
testcase_32 AC 103 ms
24,960 KB
testcase_33 AC 38 ms
10,880 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

constexpr int mod = 998244353;

void ch(int& a, int b) {
  a = a + b;
  if (a >= mod) a -= mod;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N;
  string X;
  cin >> N >> X;
  for (auto& i : X) i -= '0';
  vector dp0(N, vector(1 << 11, vector(11, 0)));
  auto dp1 = dp0;
  vector chbit(1 << 11, vector(10, 0));
  for (int i = 0; i < 1 << 11; i++) {
    for (int j = 0; j < 10; j++) {
      int t = 0;
      for (int k = 0; k < 11; k++) {
        if (i >> k & 1) t |= 1 << ((k * 10 + j) % 11);
      }
      chbit[i][j] = t;
    }
  }

  for (int i = 1; i < X[0]; i++) {
    ch(dp0[0][1][i], 1);
  }
  ch(dp1[0][1][X[0]], 1);

  for (int i = 1; i < N; i++) {
    for (int j = 0; j < 1 << 11; j++) {
      for (int k = 0; k < 11; k++) {
        for (int l = 0; l < 10; l++) {
          int t = chbit[j][l] | (1 << k);
          ch(dp0[i][t][(k * 10 + l) % 11], dp0[i - 1][j][k]);
        }

        for (int l = 0; l < X[i]; l++) {
          int t = chbit[j][l] | (1 << k);
          ch(dp0[i][t][(k * 10 + l) % 11], dp1[i - 1][j][k]);
        }

        ch(dp1[i][chbit[j][X[i]] | (1 << k)][(k * 10 + X[i]) % 11],
           dp1[i - 1][j][k]);
      }
    }

    for (int j = 1; j < 10; j++) {
      ch(dp0[i][1][j], 1);
    }
  }

  int ans = 0;
  for (int i = 0; i < 1 << 11; i++) {
    if ((i & 1) == 0) {
      ch(ans, dp0[N - 1][i][0]);
      ch(ans, dp1[N - 1][i][0]);
    }
  }
  cout << ans << '\n';
}
0