結果

問題 No.372 It's automatic
ユーザー tentententen
提出日時 2020-09-30 09:00:20
言語 Java21
(openjdk 21)
結果
AC  
実行時間 2,032 ms / 6,000 ms
コード長 962 bytes
コンパイル時間 5,854 ms
コンパイル使用メモリ 73,392 KB
実行使用メモリ 56,464 KB
最終ジャッジ日時 2023-09-18 19:11:27
合計ジャッジ時間 33,762 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 132 ms
55,636 KB
testcase_01 AC 130 ms
55,448 KB
testcase_02 AC 133 ms
55,288 KB
testcase_03 AC 133 ms
55,760 KB
testcase_04 AC 2,016 ms
56,048 KB
testcase_05 AC 2,026 ms
55,740 KB
testcase_06 AC 2,014 ms
55,712 KB
testcase_07 AC 2,000 ms
56,360 KB
testcase_08 AC 2,013 ms
55,772 KB
testcase_09 AC 1,996 ms
56,048 KB
testcase_10 AC 2,017 ms
55,996 KB
testcase_11 AC 2,004 ms
55,904 KB
testcase_12 AC 2,012 ms
56,464 KB
testcase_13 AC 1,984 ms
56,088 KB
testcase_14 AC 2,021 ms
56,008 KB
testcase_15 AC 2,032 ms
55,860 KB
testcase_16 AC 132 ms
55,620 KB
testcase_17 AC 128 ms
55,380 KB
testcase_18 AC 131 ms
53,824 KB
testcase_19 AC 131 ms
55,660 KB
testcase_20 AC 129 ms
55,960 KB
testcase_21 AC 269 ms
56,240 KB
testcase_22 AC 276 ms
55,920 KB
testcase_23 AC 266 ms
56,192 KB
testcase_24 AC 275 ms
55,976 KB
testcase_25 AC 267 ms
54,160 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    static final int MOD = 1000000007;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        char[] arr = sc.next().toCharArray();
        int length = arr.length;
        int m = sc.nextInt();
        long ans = 0;
        int[] prev = new int[m];
        int[] next = new int[m];
        for (int i = 0; i < length; i++) {
            int x = arr[i] - '0';
            for (int j = 0; j < m; j++) {
                next[j] += prev[j];
                next[j] %= MOD;
                next[(j * 10 + x) % m] += prev[j];
                next[(j * 10 + x) % m] %= MOD;
            }
            if (x == 0) {
                ans++;
            } else {
                next[x % m]++;
            }
            int[] tmp = next;
            next = prev;
            prev = tmp;
            Arrays.fill(next, 0);
        }
        System.out.println((prev[0] + ans) % MOD);
    }
}
0