結果

問題 No.2019 Digits Filling for All Substrings
ユーザー tentententen
提出日時 2023-02-07 16:46:06
言語 Java21
(openjdk 21)
結果
AC  
実行時間 204 ms / 2,000 ms
コード長 2,080 bytes
コンパイル時間 4,282 ms
コンパイル使用メモリ 93,588 KB
実行使用メモリ 62,628 KB
最終ジャッジ日時 2023-09-18 23:39:09
合計ジャッジ時間 9,546 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
49,472 KB
testcase_01 AC 45 ms
49,508 KB
testcase_02 AC 42 ms
49,508 KB
testcase_03 AC 43 ms
49,264 KB
testcase_04 AC 138 ms
57,340 KB
testcase_05 AC 125 ms
56,508 KB
testcase_06 AC 110 ms
54,272 KB
testcase_07 AC 101 ms
53,832 KB
testcase_08 AC 188 ms
62,172 KB
testcase_09 AC 196 ms
62,628 KB
testcase_10 AC 201 ms
62,428 KB
testcase_11 AC 203 ms
62,580 KB
testcase_12 AC 204 ms
62,584 KB
testcase_13 AC 196 ms
62,416 KB
testcase_14 AC 48 ms
49,816 KB
testcase_15 AC 50 ms
49,596 KB
testcase_16 AC 69 ms
51,836 KB
testcase_17 AC 54 ms
49,332 KB
testcase_18 AC 51 ms
49,508 KB
testcase_19 AC 45 ms
49,496 KB
testcase_20 AC 45 ms
49,736 KB
testcase_21 AC 46 ms
49,856 KB
testcase_22 AC 44 ms
49,392 KB
testcase_23 AC 46 ms
49,336 KB
testcase_24 AC 109 ms
56,608 KB
testcase_25 AC 147 ms
56,936 KB
testcase_26 AC 104 ms
53,524 KB
testcase_27 AC 63 ms
51,672 KB
testcase_28 AC 62 ms
51,704 KB
testcase_29 AC 138 ms
56,476 KB
testcase_30 AC 180 ms
58,500 KB
testcase_31 AC 186 ms
58,140 KB
testcase_32 AC 84 ms
54,044 KB
testcase_33 AC 141 ms
56,856 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;
import java.util.stream.*;

public class Main {
    static final int MOD = 998244353;
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        char[] s = sc.next().toCharArray();
        int[][] dp = new int[n + 1][3];
        int ans = 0;
        for (int i = 1; i <= n; i++) {
            dp[i - 1][0]++;
            for (int j = 0; j < 3; j++) {
                for (int k = 0; k < 10; k++) {
                    if (s[i - 1] == '?' || s[i - 1] - '0' == k) {
                        dp[i][(j * 10 + k) % 3] += dp[i - 1][j];
                        dp[i][(j * 10 + k) % 3] %= MOD;
                    }
                }
            }
            ans += dp[i][0];
            ans %= MOD;
        }
        System.out.println(ans);
    }
}
class Utilities {
    static String arrayToLineString(Object[] arr) {
        return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n"));
    }
    
    static String arrayToLineString(int[] arr) {
        return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new));
    }
}
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    StringBuilder sb = new StringBuilder();
    
    public Scanner() throws Exception {
        
    }
    
    public int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    
    public long nextLong() throws Exception {
        return Long.parseLong(next());
    }
    
    public double nextDouble() throws Exception {
        return Double.parseDouble(next());
    }
    
    public int[] nextIntArray() throws Exception {
        return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
    }
    
    public String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
    
}
0