結果

問題 No.372 It's automatic
ユーザー htensaihtensai
提出日時 2020-05-11 20:04:20
言語 Java19
(openjdk 21)
結果
AC  
実行時間 2,048 ms / 6,000 ms
コード長 846 bytes
コンパイル時間 2,077 ms
コンパイル使用メモリ 74,604 KB
実行使用メモリ 56,596 KB
最終ジャッジ日時 2023-09-26 08:48:08
合計ジャッジ時間 30,815 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 124 ms
56,232 KB
testcase_01 AC 120 ms
55,680 KB
testcase_02 AC 122 ms
55,792 KB
testcase_03 AC 119 ms
56,252 KB
testcase_04 AC 2,025 ms
56,316 KB
testcase_05 AC 2,048 ms
56,336 KB
testcase_06 AC 2,039 ms
56,052 KB
testcase_07 AC 1,955 ms
56,052 KB
testcase_08 AC 1,955 ms
56,504 KB
testcase_09 AC 1,951 ms
56,152 KB
testcase_10 AC 2,043 ms
56,272 KB
testcase_11 AC 2,043 ms
56,104 KB
testcase_12 AC 1,962 ms
56,024 KB
testcase_13 AC 1,937 ms
56,596 KB
testcase_14 AC 2,047 ms
55,836 KB
testcase_15 AC 2,046 ms
56,140 KB
testcase_16 AC 125 ms
55,648 KB
testcase_17 AC 124 ms
55,684 KB
testcase_18 AC 125 ms
55,840 KB
testcase_19 AC 123 ms
55,708 KB
testcase_20 AC 124 ms
56,012 KB
testcase_21 AC 269 ms
56,212 KB
testcase_22 AC 271 ms
56,012 KB
testcase_23 AC 265 ms
56,096 KB
testcase_24 AC 264 ms
55,852 KB
testcase_25 AC 269 ms
56,128 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();
		int[] prev = new int[m];
		int[] next = new int[m];
		long ans = 0;
		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]++;
		        next[x % m] %= MOD;
		    }
		    int[] tmp = next;
		    next = prev;
		    prev = tmp;
		    Arrays.fill(next, 0);
		}
		ans += prev[0];
		ans %= MOD;
		System.out.println(ans);
	}
}
0