結果

問題 No.372 It's automatic
ユーザー tomerun
提出日時 2016-07-17 21:07:23
言語 Java
(openjdk 23)
結果
AC  
実行時間 4,100 ms / 6,000 ms
コード長 748 bytes
コンパイル時間 2,468 ms
コンパイル使用メモリ 76,740 KB
実行使用メモリ 42,500 KB
最終ジャッジ日時 2024-10-15 15:27:34
合計ジャッジ時間 49,814 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

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