結果

問題 No.2019 Digits Filling for All Substrings
ユーザー tentententen
提出日時 2023-04-13 14:40:39
言語 Java21
(openjdk 21)
結果
AC  
実行時間 166 ms / 2,000 ms
コード長 2,095 bytes
コンパイル時間 3,646 ms
コンパイル使用メモリ 91,604 KB
実行使用メモリ 55,984 KB
最終ジャッジ日時 2024-04-17 18:28:19
合計ジャッジ時間 6,915 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 48 ms
50,388 KB
testcase_01 AC 47 ms
50,188 KB
testcase_02 AC 48 ms
49,948 KB
testcase_03 AC 50 ms
50,220 KB
testcase_04 AC 137 ms
54,880 KB
testcase_05 AC 100 ms
54,164 KB
testcase_06 AC 112 ms
54,052 KB
testcase_07 AC 89 ms
53,932 KB
testcase_08 AC 152 ms
55,560 KB
testcase_09 AC 148 ms
54,936 KB
testcase_10 AC 163 ms
55,984 KB
testcase_11 AC 131 ms
55,076 KB
testcase_12 AC 152 ms
54,768 KB
testcase_13 AC 166 ms
55,876 KB
testcase_14 AC 51 ms
50,112 KB
testcase_15 AC 52 ms
50,568 KB
testcase_16 AC 65 ms
50,912 KB
testcase_17 AC 54 ms
50,508 KB
testcase_18 AC 54 ms
50,560 KB
testcase_19 AC 48 ms
50,464 KB
testcase_20 AC 47 ms
50,592 KB
testcase_21 AC 49 ms
50,420 KB
testcase_22 AC 49 ms
50,168 KB
testcase_23 AC 51 ms
50,388 KB
testcase_24 AC 120 ms
54,304 KB
testcase_25 AC 130 ms
54,552 KB
testcase_26 AC 110 ms
54,128 KB
testcase_27 AC 63 ms
50,780 KB
testcase_28 AC 63 ms
50,572 KB
testcase_29 AC 123 ms
54,572 KB
testcase_30 AC 142 ms
55,056 KB
testcase_31 AC 156 ms
54,908 KB
testcase_32 AC 98 ms
51,640 KB
testcase_33 AC 120 ms
54,580 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();
        int[] current = new int[3];
        int ans = 0;
        for (char c : sc.next().toCharArray()) {
            int[] next = new int[3];
            for (int i = 0; i <= 9; i++) {
                if (c - '0' == i || c == '?') {
                    for (int j = 0; j < 3; j++) {
                        next[(j * 10 + i) % 3] += current[j];
                        next[(j * 10 + i) % 3] %= MOD;
                    }
                    next[i % 3]++;
                }
            }
            ans += next[0];
            ans %= MOD;
            current = next;
        }
        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