結果

問題 No.372 It's automatic
ユーザー tomeruntomerun
提出日時 2016-07-17 21:07:23
言語 Java21
(openjdk 21)
結果
AC  
実行時間 3,660 ms / 6,000 ms
コード長 748 bytes
コンパイル時間 2,513 ms
コンパイル使用メモリ 77,560 KB
実行使用メモリ 54,816 KB
最終ジャッジ日時 2024-04-23 15:07:51
合計ジャッジ時間 43,759 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 114 ms
53,884 KB
testcase_01 AC 102 ms
53,024 KB
testcase_02 AC 112 ms
53,724 KB
testcase_03 AC 104 ms
53,020 KB
testcase_04 AC 2,705 ms
54,760 KB
testcase_05 AC 2,804 ms
54,516 KB
testcase_06 AC 3,660 ms
54,544 KB
testcase_07 AC 2,807 ms
54,432 KB
testcase_08 AC 3,244 ms
54,784 KB
testcase_09 AC 2,761 ms
54,628 KB
testcase_10 AC 3,080 ms
54,252 KB
testcase_11 AC 2,715 ms
54,772 KB
testcase_12 AC 3,107 ms
54,568 KB
testcase_13 AC 2,775 ms
54,816 KB
testcase_14 AC 3,100 ms
54,700 KB
testcase_15 AC 3,092 ms
54,740 KB
testcase_16 AC 104 ms
52,856 KB
testcase_17 AC 107 ms
53,436 KB
testcase_18 AC 100 ms
53,120 KB
testcase_19 AC 100 ms
53,124 KB
testcase_20 AC 118 ms
54,188 KB
testcase_21 AC 294 ms
54,192 KB
testcase_22 AC 296 ms
54,428 KB
testcase_23 AC 302 ms
54,292 KB
testcase_24 AC 281 ms
54,364 KB
testcase_25 AC 309 ms
54,196 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {
	static Scanner sc = new Scanner(System.in);
	static final int MOD = 1_000_000_007;

	public static void main(String[] args) {
		char[] S = sc.next().toCharArray();
		int M = sc.nextInt();
		long[][] count = new long[2][M];
		long ans = 0;
		int t = 0;
		for (int i = 0; i < S.length; ++i) {
			for (int j = 0; j < M; ++j) {
				count[t][j] = count[1-t][j];
			}
			for (int j = 0; j < M; ++j) {
				int next = (j * 10 + S[i] - '0') % M;
				count[t][next] += count[1 - t][j];
				if (count[t][next] >= MOD) count[t][next] -= MOD;
			}
			if (S[i] == '0') {
				++ans;
			} else {
				count[t][(S[i] - '0') % M]++;
			}
			t = 1 - t;
		}
		ans += count[1-t][0];
		System.out.println(ans % MOD);
	}

}
0