結果

問題 No.372 It's automatic
ユーザー tentententen
提出日時 2023-12-14 08:25:32
言語 Java21
(openjdk 21)
結果
MLE  
実行時間 -
コード長 2,145 bytes
コンパイル時間 2,762 ms
コンパイル使用メモリ 94,184 KB
実行使用メモリ 745,372 KB
最終ジャッジ日時 2023-12-14 08:25:48
合計ジャッジ時間 15,961 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 55 ms
54,008 KB
testcase_01 AC 54 ms
52,040 KB
testcase_02 AC 53 ms
54,008 KB
testcase_03 AC 54 ms
54,020 KB
testcase_04 MLE -
testcase_05 MLE -
testcase_06 MLE -
testcase_07 MLE -
testcase_08 MLE -
testcase_09 MLE -
testcase_10 MLE -
testcase_11 MLE -
testcase_12 MLE -
testcase_13 MLE -
testcase_14 MLE -
testcase_15 MLE -
testcase_16 AC 56 ms
54,012 KB
testcase_17 AC 56 ms
54,016 KB
testcase_18 AC 55 ms
54,008 KB
testcase_19 AC 55 ms
54,012 KB
testcase_20 AC 56 ms
54,000 KB
testcase_21 AC 208 ms
90,852 KB
testcase_22 AC 211 ms
92,788 KB
testcase_23 AC 215 ms
92,808 KB
testcase_24 AC 210 ms
92,816 KB
testcase_25 AC 211 ms
92,800 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 length = inputs.length;
        int m = sc.nextInt();
        int[][] dp = new int[length + 1][m];
        int ans = 0;
        for (int i = 0; i < length; i++) {
            int x = inputs[i] - '0';
            for (int j = 0; j < m; j++) {
                dp[i + 1][j] += dp[i][j];
                dp[i + 1][j] %= MOD;
                dp[i + 1][(j * 10 + x) % m] += dp[i][j];
                dp[i + 1][(j * 10 + x) % m] %= MOD;
            }
            if (x == 0) {
                ans++;
            } else {
                dp[i + 1][x % m]++;
            }
        }
        System.out.println((dp[length][0] + ans) % MOD);
    }
}
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