結果
問題 | No.1085 桁和の桁和 |
ユーザー |
![]() |
提出日時 | 2020-06-19 23:12:02 |
言語 | Java (openjdk 23) |
結果 |
RE
|
実行時間 | - |
コード長 | 920 bytes |
コンパイル時間 | 2,232 ms |
コンパイル使用メモリ | 77,772 KB |
実行使用メモリ | 63,728 KB |
最終ジャッジ日時 | 2024-07-23 00:40:38 |
合計ジャッジ時間 | 11,742 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 RE * 1 |
other | AC * 31 RE * 4 |
ソースコード
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]);}}