結果

問題 No.2019 Digits Filling for All Substrings
ユーザー SSRSSSRS
提出日時 2022-07-22 21:39:06
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 37 ms / 2,000 ms
コード長 659 bytes
コンパイル時間 1,644 ms
コンパイル使用メモリ 169,700 KB
実行使用メモリ 14,252 KB
最終ジャッジ日時 2023-09-17 09:15:17
合計ジャッジ時間 3,271 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 24 ms
10,300 KB
testcase_05 AC 19 ms
8,020 KB
testcase_06 AC 16 ms
7,508 KB
testcase_07 AC 12 ms
6,168 KB
testcase_08 AC 35 ms
14,192 KB
testcase_09 AC 37 ms
14,076 KB
testcase_10 AC 36 ms
14,252 KB
testcase_11 AC 37 ms
14,120 KB
testcase_12 AC 37 ms
14,176 KB
testcase_13 AC 36 ms
14,172 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 3 ms
4,380 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 20 ms
7,880 KB
testcase_25 AC 27 ms
10,184 KB
testcase_26 AC 14 ms
6,448 KB
testcase_27 AC 3 ms
4,380 KB
testcase_28 AC 4 ms
4,380 KB
testcase_29 AC 25 ms
9,336 KB
testcase_30 AC 33 ms
12,036 KB
testcase_31 AC 33 ms
11,764 KB
testcase_32 AC 11 ms
5,668 KB
testcase_33 AC 27 ms
9,660 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
const long long MOD = 998244353;
int main(){
  int N;
  cin >> N;
  string S;
  cin >> S;
  vector<vector<long long>> dp(N + 1, vector<long long>(3, 0));
  for (int i = 0; i <= N; i++){
    dp[i][0] = 1;
  }
  for (int i = 0; i < N; i++){
    for (int j = 0; j < 3; j++){
      for (int k = 0; k < 10; k++){
        if (k == S[i] - '0' || S[i] == '?'){
          int j2 = (j * 10 + k) % 3;
          dp[i + 1][j2] += dp[i][j];
          dp[i + 1][j2] %= MOD;
        }
      }
    }
  }
  long long ans = 0;
  for (int i = 0; i <= N; i++){
    ans += dp[i][0] + MOD - 1;
  }
  ans %= MOD;
  cout << ans << endl;
}
0