結果

問題 No.1085 桁和の桁和
ユーザー tentententen
提出日時 2023-02-01 13:39:18
言語 Java21
(openjdk 21)
結果
AC  
実行時間 160 ms / 2,000 ms
コード長 2,365 bytes
コンパイル時間 2,080 ms
コンパイル使用メモリ 87,236 KB
実行使用メモリ 57,172 KB
最終ジャッジ日時 2023-09-14 01:42:56
合計ジャッジ時間 8,033 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
49,548 KB
testcase_01 AC 36 ms
49,528 KB
testcase_02 AC 35 ms
49,544 KB
testcase_03 AC 35 ms
49,464 KB
testcase_04 AC 132 ms
56,584 KB
testcase_05 AC 37 ms
49,420 KB
testcase_06 AC 36 ms
49,800 KB
testcase_07 AC 35 ms
49,968 KB
testcase_08 AC 36 ms
49,616 KB
testcase_09 AC 36 ms
49,536 KB
testcase_10 AC 35 ms
49,472 KB
testcase_11 AC 36 ms
49,432 KB
testcase_12 AC 37 ms
49,584 KB
testcase_13 AC 78 ms
51,348 KB
testcase_14 AC 85 ms
53,404 KB
testcase_15 AC 114 ms
56,308 KB
testcase_16 AC 115 ms
56,480 KB
testcase_17 AC 85 ms
53,680 KB
testcase_18 AC 75 ms
51,536 KB
testcase_19 AC 105 ms
57,120 KB
testcase_20 AC 105 ms
56,652 KB
testcase_21 AC 91 ms
53,836 KB
testcase_22 AC 101 ms
54,508 KB
testcase_23 AC 62 ms
51,532 KB
testcase_24 AC 44 ms
49,560 KB
testcase_25 AC 87 ms
53,596 KB
testcase_26 AC 124 ms
57,172 KB
testcase_27 AC 101 ms
56,728 KB
testcase_28 AC 132 ms
56,652 KB
testcase_29 AC 97 ms
54,348 KB
testcase_30 AC 91 ms
53,464 KB
testcase_31 AC 112 ms
56,492 KB
testcase_32 AC 95 ms
56,352 KB
testcase_33 AC 160 ms
57,096 KB
testcase_34 AC 145 ms
56,472 KB
testcase_35 AC 144 ms
57,016 KB
testcase_36 AC 148 ms
54,916 KB
testcase_37 AC 156 ms
57,048 KB
testcase_38 AC 155 ms
56,852 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;
import java.util.stream.*;

public class Main {
    static final int MOD = 1000000007;
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        char[] inputs = sc.next().toCharArray();
        int d = sc.nextInt();
        int length = inputs.length;
        int[][] dp = new int[length + 1][10];
        dp[0][0] = 1;
        for (int i = 1; i <= length; i++) {
            for (int j = 0; j < 10; j++) {
                for (int k = 0; k < 10; k++) {
                    if (inputs[i - 1] == '?' || inputs[i - 1] - '0' == k) {
                        int sum = getSum(j + k);
                        dp[i][sum] += dp[i - 1][j];
                        dp[i][sum] %= MOD;
                    }
                }
            }
        }
        System.out.println(dp[length][d]);
    }
    
    static int getSum(int x) {
        if (x < 10) {
            return x;
        } else {
            int sum = 0;
            while (x > 0) {
                sum += x % 10;
                x /= 10;
            }
            return getSum(sum);
        }
    }
}
class Utilities {
    static String arrayToLineString(Object[] arr) {
        return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n"));
    }
    
    static String arrayToLineString(int[] arr) {
        return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new));
    }
}
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    StringBuilder sb = new StringBuilder();
    
    public Scanner() throws Exception {
        
    }
    
    public int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    
    public long nextLong() throws Exception {
        return Long.parseLong(next());
    }
    
    public double nextDouble() throws Exception {
        return Double.parseDouble(next());
    }
    
    public int[] nextIntArray() throws Exception {
        return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
    }
    
    public String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
    
}
0