結果

問題 No.1085 桁和の桁和
ユーザー ks2mks2m
提出日時 2020-06-19 23:14:12
言語 Java21
(openjdk 21)
結果
RE  
実行時間 -
コード長 922 bytes
コンパイル時間 2,326 ms
コンパイル使用メモリ 74,376 KB
実行使用メモリ 64,388 KB
最終ジャッジ日時 2023-09-30 06:27:46
合計ジャッジ時間 10,197 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 109 ms
55,880 KB
testcase_01 AC 115 ms
55,832 KB
testcase_02 AC 110 ms
54,144 KB
testcase_03 RE -
testcase_04 AC 180 ms
58,736 KB
testcase_05 AC 106 ms
56,028 KB
testcase_06 AC 108 ms
55,836 KB
testcase_07 AC 114 ms
55,892 KB
testcase_08 RE -
testcase_09 RE -
testcase_10 AC 112 ms
55,980 KB
testcase_11 RE -
testcase_12 RE -
testcase_13 AC 153 ms
55,864 KB
testcase_14 AC 151 ms
57,732 KB
testcase_15 AC 218 ms
61,144 KB
testcase_16 RE -
testcase_17 AC 170 ms
56,576 KB
testcase_18 AC 147 ms
57,976 KB
testcase_19 AC 220 ms
61,004 KB
testcase_20 AC 179 ms
56,640 KB
testcase_21 AC 198 ms
58,436 KB
testcase_22 AC 217 ms
61,340 KB
testcase_23 AC 137 ms
55,808 KB
testcase_24 AC 113 ms
56,040 KB
testcase_25 AC 163 ms
58,076 KB
testcase_26 AC 214 ms
60,948 KB
testcase_27 AC 214 ms
60,880 KB
testcase_28 AC 228 ms
60,868 KB
testcase_29 AC 201 ms
58,576 KB
testcase_30 AC 204 ms
58,148 KB
testcase_31 AC 219 ms
61,308 KB
testcase_32 AC 224 ms
60,948 KB
testcase_33 RE -
testcase_34 AC 240 ms
62,872 KB
testcase_35 AC 228 ms
63,756 KB
testcase_36 AC 253 ms
64,076 KB
testcase_37 AC 258 ms
63,024 KB
testcase_38 AC 243 ms
63,152 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		char[] t = sc.next().toCharArray();
		int d = sc.nextInt();
		sc.close();

		int sum = 0;
		int cnt = 0;
		for (int i = 0; i < t.length; i++) {
			if (t[i] == '?') {
				cnt++;
			} else {
				sum += t[i] - '0';
			}
		}

		if (d == 0) {
			if (sum == 0) {
				System.out.println(1);
			} else {
				System.out.println(0);
			}
			return;
		}

		int mod = 1000000007;
		long[][] dp = new long[cnt + 1][9];
		dp[0][0] = 1;
		for (int i = 0; i < cnt; i++) {
			for (int j = 0; j < 9; j++) {
				for (int j2 = 0; j2 < 10; j2++) {
					dp[i + 1][(j + j2) % 9] += dp[i][j];
				}
			}
			for (int j = 0; j < 9; j++) {
				dp[i + 1][j] %= mod;
			}
		}
		sum %= 9;
		if (sum == 0) {
			throw new Exception();
		}
		int c = (d - sum + 9) % 9;
		System.out.println(dp[cnt][c]);
	}
}
0