結果

問題 No.2019 Digits Filling for All Substrings
ユーザー tentententen
提出日時 2023-06-30 13:13:59
言語 Java21
(openjdk 21)
結果
AC  
実行時間 209 ms / 2,000 ms
コード長 2,144 bytes
コンパイル時間 3,695 ms
コンパイル使用メモリ 80,008 KB
実行使用メモリ 63,000 KB
最終ジャッジ日時 2023-09-21 06:51:50
合計ジャッジ時間 9,512 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
49,380 KB
testcase_01 AC 44 ms
49,840 KB
testcase_02 AC 44 ms
49,596 KB
testcase_03 AC 44 ms
49,420 KB
testcase_04 AC 131 ms
56,880 KB
testcase_05 AC 118 ms
56,816 KB
testcase_06 AC 119 ms
52,488 KB
testcase_07 AC 114 ms
52,184 KB
testcase_08 AC 209 ms
62,604 KB
testcase_09 AC 207 ms
62,324 KB
testcase_10 AC 202 ms
62,156 KB
testcase_11 AC 207 ms
62,504 KB
testcase_12 AC 204 ms
63,000 KB
testcase_13 AC 187 ms
62,684 KB
testcase_14 AC 47 ms
49,556 KB
testcase_15 AC 49 ms
49,572 KB
testcase_16 AC 72 ms
50,036 KB
testcase_17 AC 49 ms
49,540 KB
testcase_18 AC 52 ms
50,288 KB
testcase_19 AC 45 ms
49,344 KB
testcase_20 AC 43 ms
49,476 KB
testcase_21 AC 44 ms
49,372 KB
testcase_22 AC 44 ms
49,308 KB
testcase_23 AC 43 ms
49,764 KB
testcase_24 AC 158 ms
57,556 KB
testcase_25 AC 184 ms
57,368 KB
testcase_26 AC 138 ms
54,940 KB
testcase_27 AC 72 ms
51,852 KB
testcase_28 AC 73 ms
51,692 KB
testcase_29 AC 127 ms
56,964 KB
testcase_30 AC 188 ms
58,044 KB
testcase_31 AC 162 ms
56,860 KB
testcase_32 AC 86 ms
54,484 KB
testcase_33 AC 142 ms
56,516 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[] inputs = sc.next().toCharArray();
        int[][] dp = new int[n + 1][3];
        int ans = 0;
        for (int i = 1; i <= n; i++) {
            for (int j = 0; j < 10; j++) {
                if (inputs[i - 1] == '?' || inputs[i - 1] - '0' == j) {
                    for (int k = 0; k < 3; k++) {
                        dp[i][(k * 10 + j) % 3] += dp[i - 1][k];
                        dp[i][(k * 10 + j) % 3] %= MOD;
                    }
                    dp[i][j % 3]++;
                    dp[i][j % 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