結果
問題 | No.372 It's automatic |
ユーザー | uafr_cs |
提出日時 | 2016-05-13 23:31:01 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 2,038 ms / 6,000 ms |
コード長 | 2,069 bytes |
コンパイル時間 | 2,566 ms |
コンパイル使用メモリ | 78,804 KB |
実行使用メモリ | 53,740 KB |
最終ジャッジ日時 | 2024-10-05 18:07:24 |
合計ジャッジ時間 | 28,728 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 52 ms
50,236 KB |
testcase_01 | AC | 52 ms
50,040 KB |
testcase_02 | AC | 54 ms
50,040 KB |
testcase_03 | AC | 53 ms
50,308 KB |
testcase_04 | AC | 1,912 ms
52,656 KB |
testcase_05 | AC | 1,928 ms
52,484 KB |
testcase_06 | AC | 1,948 ms
53,720 KB |
testcase_07 | AC | 1,971 ms
52,604 KB |
testcase_08 | AC | 2,030 ms
53,448 KB |
testcase_09 | AC | 1,928 ms
53,740 KB |
testcase_10 | AC | 1,972 ms
52,376 KB |
testcase_11 | AC | 1,919 ms
53,668 KB |
testcase_12 | AC | 2,038 ms
52,604 KB |
testcase_13 | AC | 1,875 ms
52,676 KB |
testcase_14 | AC | 1,887 ms
52,468 KB |
testcase_15 | AC | 2,028 ms
52,956 KB |
testcase_16 | AC | 54 ms
50,208 KB |
testcase_17 | AC | 54 ms
50,036 KB |
testcase_18 | AC | 54 ms
50,528 KB |
testcase_19 | AC | 55 ms
50,328 KB |
testcase_20 | AC | 54 ms
50,012 KB |
testcase_21 | AC | 230 ms
53,600 KB |
testcase_22 | AC | 218 ms
52,764 KB |
testcase_23 | AC | 215 ms
52,488 KB |
testcase_24 | AC | 205 ms
52,600 KB |
testcase_25 | AC | 214 ms
52,224 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[M + 1]; mods[0] = 1; int zero_count = 0; long[] next_tmp = new long[M + 1]; for(int cur = 0; cur < S.length; cur++){ final int cur_num = Character.getNumericValue(S[cur]); Arrays.fill(next_tmp, 0); if(cur_num == 0){ zero_count++; } for(int mod = (cur_num != 0 ? 0 : 1); mod <= M; mod++){ if(mods[mod] == 0){ continue; } final int next_mod = (mod * 10 + cur_num) % M; if(next_mod == 0){ next_tmp[M] += mods[mod]; next_tmp[M] %= MOD; }else{ next_tmp[next_mod] += mods[mod]; next_tmp[next_mod] %= MOD; } } for(int i = 0; i <= M; i++){ mods[i] += next_tmp[i]; mods[i] %= MOD; } } System.out.println((mods[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(); } } }