結果

問題 No.2772 Appearing Even Times
ユーザー hiromi_ayasehiromi_ayase
提出日時 2024-05-31 23:51:10
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 363 ms / 4,000 ms
コード長 1,143 bytes
コンパイル時間 5,677 ms
コンパイル使用メモリ 315,972 KB
実行使用メモリ 84,480 KB
最終ジャッジ日時 2024-05-31 23:51:21
合計ジャッジ時間 10,259 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,816 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 3 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 246 ms
84,480 KB
testcase_09 AC 363 ms
84,480 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 3 ms
6,944 KB
testcase_12 AC 305 ms
84,352 KB
testcase_13 AC 308 ms
83,968 KB
testcase_14 AC 304 ms
84,224 KB
testcase_15 AC 301 ms
83,968 KB
testcase_16 AC 302 ms
84,352 KB
testcase_17 AC 305 ms
84,352 KB
testcase_18 AC 303 ms
84,224 KB
testcase_19 AC 302 ms
84,096 KB
testcase_20 AC 298 ms
82,944 KB
testcase_21 AC 299 ms
83,456 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#include <atcoder/all>
using namespace std;
using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;
#define FAST_IO                \
  ios::sync_with_stdio(false); \
  cin.tie(0);
const i64 INF = 1001001001001001001;
using Modint = atcoder::static_modint<998244353>;

int main() {
  FAST_IO


  string N;
  cin >> N;

  int m = N.size();
  int d = 10;
  vector dp(m + 1, vector(2, vector(1 << d, Modint(0))));

  for (int i = 0; i < m; i++) {
    int c = N[i] - '0';
    for (int x = 1; x < d; x++) {
      if (i == 0) {
        if (x < c) {
          dp[i + 1][1][1 << x]++;
        } else if (x == c) {
          dp[i + 1][0][1 << x]++;
        }
      } else {
        dp[i + 1][1][1 << c]++;
      }
    }

    for (int k = 0; k < (1 << d); k++) {
      for (int x = 0; x < c; x++) {
        dp[i + 1][1][k ^ (1 << x)] += dp[i][0][k];
      }
      for (int x = 0; x < d; x++) {
        dp[i + 1][1][k ^ (1 << x)] += dp[i][1][k];
      }
      dp[i + 1][0][k ^ (1 << c)] += dp[i][0][k];
    }
  }

  Modint ans = dp[m][0][0] + dp[m][1][0];
  cout << ans.val() << endl;
}
0