結果

問題 No.2019 Digits Filling for All Substrings
ユーザー ShirotsumeShirotsume
提出日時 2022-02-25 13:19:57
言語 Java21
(openjdk 21)
結果
AC  
実行時間 343 ms / 2,000 ms
コード長 1,120 bytes
コンパイル時間 2,110 ms
コンパイル使用メモリ 74,108 KB
実行使用メモリ 59,360 KB
最終ジャッジ日時 2023-09-16 05:25:45
合計ジャッジ時間 10,729 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 123 ms
56,164 KB
testcase_01 AC 127 ms
56,108 KB
testcase_02 AC 124 ms
55,820 KB
testcase_03 AC 127 ms
55,936 KB
testcase_04 AC 277 ms
58,940 KB
testcase_05 AC 257 ms
56,816 KB
testcase_06 AC 249 ms
56,748 KB
testcase_07 AC 220 ms
56,820 KB
testcase_08 AC 319 ms
58,744 KB
testcase_09 AC 306 ms
58,940 KB
testcase_10 AC 343 ms
58,716 KB
testcase_11 AC 309 ms
58,716 KB
testcase_12 AC 329 ms
56,704 KB
testcase_13 AC 311 ms
59,360 KB
testcase_14 AC 129 ms
55,796 KB
testcase_15 AC 130 ms
55,844 KB
testcase_16 AC 172 ms
56,348 KB
testcase_17 AC 143 ms
55,848 KB
testcase_18 AC 142 ms
55,756 KB
testcase_19 AC 122 ms
55,716 KB
testcase_20 AC 124 ms
55,896 KB
testcase_21 AC 122 ms
55,700 KB
testcase_22 AC 122 ms
55,896 KB
testcase_23 AC 126 ms
55,636 KB
testcase_24 AC 273 ms
56,748 KB
testcase_25 AC 291 ms
56,576 KB
testcase_26 AC 222 ms
56,684 KB
testcase_27 AC 144 ms
55,724 KB
testcase_28 AC 148 ms
55,940 KB
testcase_29 AC 318 ms
56,664 KB
testcase_30 AC 324 ms
58,832 KB
testcase_31 AC 325 ms
59,052 KB
testcase_32 AC 243 ms
56,760 KB
testcase_33 AC 294 ms
54,848 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {
	  public static void main(String[] args) {
	        Scanner sc = new Scanner(System.in);
	        int n = sc.nextInt();
	        char[] s = sc.next().toCharArray();
	        long[] dp = new long[3];
	        long[] e = new long[3];
	        long ans = 0;
	        long mod = 998244353;
	        for(int i = 0; i < n; i++){
	        	if(s[i] == '?'){
	        		for(int j = 0; j < 3; j++){
	        			for(int k = 0; k < 10; k++){
	        				e[(j + k) % 3] += dp[j];
	        				e[(j + k) % 3] %= mod;
	        			}
	        		}
	        		for(int k = 0; k < 10; k++){
	        			e[k % 3] += 1;
	        		}
	        	}
	        	else{
	        		int now = s[i] - '0';
	        		for(int j = 0; j < 3; j++){
	        			e[(j + now) % 3] += dp[j];
	        			e[(j + now) % 3] %= mod;
	        		}
	        		e[now % 3] += 1;
	        	}
	        	ans += e[0];
	        	ans %= mod;
	        	dp[0] = e[0];
	        	dp[1] = e[1];
	        	dp[2] = e[2];
	        	e[0] = 0;
	        	e[1] = 0;
	        	e[2] = 0;
	        }
	        System.out.println(ans);

	    }
}
0