結果

問題 No.1085 桁和の桁和
ユーザー ks2mks2m
提出日時 2020-06-19 22:58:55
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 875 bytes
コンパイル時間 4,906 ms
コンパイル使用メモリ 73,516 KB
実行使用メモリ 63,776 KB
最終ジャッジ日時 2023-09-30 06:25:42
合計ジャッジ時間 11,529 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 129 ms
55,728 KB
testcase_01 AC 128 ms
55,740 KB
testcase_02 AC 130 ms
55,924 KB
testcase_03 AC 129 ms
55,520 KB
testcase_04 AC 221 ms
56,728 KB
testcase_05 AC 129 ms
56,076 KB
testcase_06 AC 128 ms
55,900 KB
testcase_07 AC 129 ms
55,412 KB
testcase_08 AC 129 ms
55,924 KB
testcase_09 WA -
testcase_10 AC 126 ms
55,732 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 216 ms
56,724 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
権限があれば一括ダウンロードができます

ソースコード

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;
		int[][] dp = new int[cnt + 1][10];
		dp[0][0] = 1;
		for (int i = 0; i < cnt; i++) {
			for (int j = 0; j < 10; j++) {
				for (int j2 = 0; j2 < 10; j2++) {
					dp[i + 1][(j + j2) % 9] += dp[i][j];
				}
			}
			for (int j = 0; j < 10; j++) {
				dp[i + 1][j] %= mod;
			}
		}
		sum %= 9;
		int c = (d - sum + 9) % 9;
		System.out.println(dp[cnt][c]);
	}
}
0