結果
問題 | No.1085 桁和の桁和 |
ユーザー |
![]() |
提出日時 | 2020-06-19 23:08:07 |
言語 | Java (openjdk 23) |
結果 |
WA
|
実行時間 | - |
コード長 | 874 bytes |
コンパイル時間 | 3,014 ms |
コンパイル使用メモリ | 77,116 KB |
実行使用メモリ | 63,848 KB |
最終ジャッジ日時 | 2024-07-23 00:39:39 |
合計ジャッジ時間 | 11,319 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 32 WA * 3 |
ソースコード
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;int c = (d - sum + 9) % 9;System.out.println(dp[cnt][c]);}}