結果

問題 No.2019 Digits Filling for All Substrings
ユーザー tentententen
提出日時 2022-07-26 08:27:31
言語 Java21
(openjdk 21)
結果
AC  
実行時間 170 ms / 2,000 ms
コード長 1,810 bytes
コンパイル時間 2,219 ms
コンパイル使用メモリ 74,256 KB
実行使用メモリ 56,024 KB
最終ジャッジ日時 2023-09-23 00:07:23
合計ジャッジ時間 7,679 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
49,352 KB
testcase_01 AC 42 ms
49,704 KB
testcase_02 AC 42 ms
49,712 KB
testcase_03 AC 42 ms
49,352 KB
testcase_04 AC 123 ms
55,064 KB
testcase_05 AC 121 ms
54,876 KB
testcase_06 AC 119 ms
54,812 KB
testcase_07 AC 91 ms
54,484 KB
testcase_08 AC 151 ms
55,112 KB
testcase_09 AC 162 ms
55,236 KB
testcase_10 AC 161 ms
55,672 KB
testcase_11 AC 143 ms
55,280 KB
testcase_12 AC 147 ms
54,880 KB
testcase_13 AC 170 ms
55,404 KB
testcase_14 AC 48 ms
49,948 KB
testcase_15 AC 48 ms
49,376 KB
testcase_16 AC 73 ms
51,676 KB
testcase_17 AC 49 ms
49,720 KB
testcase_18 AC 49 ms
49,504 KB
testcase_19 AC 43 ms
50,048 KB
testcase_20 AC 43 ms
49,504 KB
testcase_21 AC 43 ms
49,440 KB
testcase_22 AC 43 ms
49,548 KB
testcase_23 AC 46 ms
49,452 KB
testcase_24 AC 133 ms
54,464 KB
testcase_25 AC 169 ms
56,024 KB
testcase_26 AC 116 ms
54,464 KB
testcase_27 AC 54 ms
49,512 KB
testcase_28 AC 52 ms
49,564 KB
testcase_29 AC 136 ms
54,668 KB
testcase_30 AC 168 ms
55,424 KB
testcase_31 AC 144 ms
55,120 KB
testcase_32 AC 84 ms
54,176 KB
testcase_33 AC 128 ms
54,832 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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[] values = sc.next().toCharArray();
        int[] dp = new int[3];
        int ans = 0;
        for (int i = 0; i < n; i++) {
            int[] next = new int[3];
            if (values[i] == '?') {
                for (int j = 0; j < 10; j++) {
                    for (int k = 0; k < 3; k++) {
                        next[(k * 10 + j) % 3] += dp[k];
                        next[(k * 10 + j) % 3] %= MOD;
                    }
                    next[j % 3]++;
                }
            } else {
                for (int j = 0; j < 3; j++) {
                    next[(j * 10 + values[i] - '0') % 3] += dp[j];
                    next[(j * 10 + values[i] - '0') % 3] %= MOD;
                }
                next[(values[i] - '0') % 3]++;
            }
            ans += next[0];
            ans %= MOD;
            dp = next;
        }
        System.out.println(ans);
    }
}
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    
    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 String next() throws Exception {
        if (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
}
0