結果
問題 | No.372 It's automatic |
ユーザー | uafr_cs |
提出日時 | 2016-05-15 20:17:29 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 1,926 ms / 6,000 ms |
コード長 | 2,083 bytes |
コンパイル時間 | 2,273 ms |
コンパイル使用メモリ | 79,236 KB |
実行使用メモリ | 40,536 KB |
最終ジャッジ日時 | 2024-10-06 04:06:27 |
合計ジャッジ時間 | 25,147 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 51 ms
37,156 KB |
testcase_01 | AC | 52 ms
36,920 KB |
testcase_02 | AC | 51 ms
36,880 KB |
testcase_03 | AC | 54 ms
37,008 KB |
testcase_04 | AC | 1,546 ms
40,472 KB |
testcase_05 | AC | 1,898 ms
40,156 KB |
testcase_06 | AC | 1,544 ms
39,444 KB |
testcase_07 | AC | 1,552 ms
39,360 KB |
testcase_08 | AC | 1,563 ms
39,236 KB |
testcase_09 | AC | 1,910 ms
39,204 KB |
testcase_10 | AC | 1,548 ms
39,272 KB |
testcase_11 | AC | 1,926 ms
40,536 KB |
testcase_12 | AC | 1,556 ms
39,360 KB |
testcase_13 | AC | 1,517 ms
39,444 KB |
testcase_14 | AC | 1,911 ms
39,208 KB |
testcase_15 | AC | 1,519 ms
39,360 KB |
testcase_16 | AC | 53 ms
36,976 KB |
testcase_17 | AC | 53 ms
37,004 KB |
testcase_18 | AC | 53 ms
37,004 KB |
testcase_19 | AC | 53 ms
36,748 KB |
testcase_20 | AC | 52 ms
36,480 KB |
testcase_21 | AC | 174 ms
38,952 KB |
testcase_22 | AC | 169 ms
38,792 KB |
testcase_23 | AC | 164 ms
39,080 KB |
testcase_24 | AC | 155 ms
38,792 KB |
testcase_25 | AC | 157 ms
39,076 KB |
ソースコード
import java.io.BufferedReader; import java.io.Closeable; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.Arrays; import java.util.HashSet; import java.util.LinkedList; import java.util.Scanner; import java.util.Set; import java.util.StringTokenizer; public class Main { public static void main(String[] args) throws IOException { Scanner sc = new Scanner(System.in); final char[] S = sc.next().toCharArray(); final int M = sc.nextInt(); final long MOD = 1000000007; long[][] mods = new long[2][M + 1]; mods[0][0] = 1; int zero_count = 0; for(int cur = 0; cur < S.length; cur++){ final int turn = cur % 2; final int cur_num = Character.getNumericValue(S[cur]); if(cur_num == 0){ zero_count++; } for(int i = 0; i <= M; i++){ mods[1 - turn][i] = mods[turn][i]; } for(int mod = (cur_num != 0 ? 0 : 1); mod <= M; mod++){ if(mods[turn][mod] == 0){ continue; } final int next_mod = (mod * 10 + cur_num) % M; if(next_mod == 0){ mods[1 - turn][M] += mods[turn][mod]; mods[1 - turn][M] %= MOD; }else{ mods[1 - turn][next_mod] += mods[turn][mod]; mods[1 - turn][next_mod] %= MOD; } } } System.out.println((mods[S.length % 2][M] + zero_count) % MOD); } public static class Scanner implements Closeable { private BufferedReader br; private StringTokenizer tok; public Scanner(InputStream is) throws IOException { br = new BufferedReader(new InputStreamReader(is)); } private void getLine() throws IOException { while (!hasNext()) { tok = new StringTokenizer(br.readLine()); } } private boolean hasNext() { return tok != null && tok.hasMoreTokens(); } public String next() throws IOException { getLine(); return tok.nextToken(); } public int nextInt() throws IOException { return Integer.parseInt(next()); } public long nextLong() throws IOException { return Long.parseLong(next()); } public void close() throws IOException { br.close(); } } }