結果

問題 No.372 It's automatic
ユーザー tomeruntomerun
提出日時 2016-07-17 21:07:23
言語 Java21
(openjdk 21)
結果
AC  
実行時間 3,824 ms / 6,000 ms
コード長 748 bytes
コンパイル時間 3,796 ms
コンパイル使用メモリ 73,588 KB
実行使用メモリ 58,864 KB
最終ジャッジ日時 2023-08-05 18:20:35
合計ジャッジ時間 51,599 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 117 ms
56,152 KB
testcase_01 AC 118 ms
56,300 KB
testcase_02 AC 120 ms
56,048 KB
testcase_03 AC 119 ms
55,724 KB
testcase_04 AC 3,598 ms
56,412 KB
testcase_05 AC 3,574 ms
58,864 KB
testcase_06 AC 3,597 ms
56,136 KB
testcase_07 AC 3,791 ms
56,712 KB
testcase_08 AC 3,806 ms
56,564 KB
testcase_09 AC 3,599 ms
56,704 KB
testcase_10 AC 3,619 ms
56,608 KB
testcase_11 AC 3,532 ms
56,552 KB
testcase_12 AC 3,672 ms
56,056 KB
testcase_13 AC 3,617 ms
56,956 KB
testcase_14 AC 3,824 ms
56,760 KB
testcase_15 AC 3,084 ms
56,708 KB
testcase_16 AC 127 ms
53,956 KB
testcase_17 AC 125 ms
55,472 KB
testcase_18 AC 122 ms
56,212 KB
testcase_19 AC 123 ms
55,788 KB
testcase_20 AC 130 ms
55,756 KB
testcase_21 AC 362 ms
56,616 KB
testcase_22 AC 367 ms
56,404 KB
testcase_23 AC 362 ms
56,148 KB
testcase_24 AC 319 ms
55,848 KB
testcase_25 AC 350 ms
56,448 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