結果

問題 No.1085 桁和の桁和
ユーザー ks2mks2m
提出日時 2020-06-19 23:12:02
言語 Java21
(openjdk 21)
結果
RE  
実行時間 -
コード長 920 bytes
コンパイル時間 2,016 ms
コンパイル使用メモリ 73,936 KB
実行使用メモリ 65,092 KB
最終ジャッジ日時 2023-09-30 06:27:34
合計ジャッジ時間 11,134 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 123 ms
55,572 KB
testcase_01 AC 122 ms
53,312 KB
testcase_02 AC 120 ms
55,656 KB
testcase_03 RE -
testcase_04 AC 203 ms
56,340 KB
testcase_05 AC 122 ms
55,576 KB
testcase_06 AC 122 ms
55,720 KB
testcase_07 AC 124 ms
56,592 KB
testcase_08 AC 121 ms
55,556 KB
testcase_09 RE -
testcase_10 AC 121 ms
56,544 KB
testcase_11 RE -
testcase_12 RE -
testcase_13 AC 162 ms
56,024 KB
testcase_14 AC 171 ms
57,948 KB
testcase_15 AC 258 ms
61,140 KB
testcase_16 AC 250 ms
61,176 KB
testcase_17 AC 203 ms
58,500 KB
testcase_18 AC 164 ms
57,948 KB
testcase_19 AC 260 ms
61,076 KB
testcase_20 AC 208 ms
56,792 KB
testcase_21 AC 224 ms
59,088 KB
testcase_22 AC 260 ms
61,008 KB
testcase_23 AC 153 ms
55,700 KB
testcase_24 AC 127 ms
55,908 KB
testcase_25 AC 196 ms
58,692 KB
testcase_26 RE -
testcase_27 AC 253 ms
61,332 KB
testcase_28 AC 248 ms
61,184 KB
testcase_29 AC 218 ms
58,752 KB
testcase_30 AC 199 ms
58,800 KB
testcase_31 AC 244 ms
60,688 KB
testcase_32 AC 222 ms
61,060 KB
testcase_33 AC 272 ms
63,672 KB
testcase_34 AC 275 ms
63,660 KB
testcase_35 AC 276 ms
62,968 KB
testcase_36 AC 281 ms
63,556 KB
testcase_37 AC 280 ms
65,092 KB
testcase_38 AC 272 ms
63,632 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 == 9) {
			throw new Exception();
		}

		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;
		int c = (d - sum + 9) % 9;
		System.out.println(dp[cnt][c]);
	}
}
0