結果
問題 | No.372 It's automatic |
ユーザー | tenten |
提出日時 | 2023-06-13 16:59:24 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 2,141 ms / 6,000 ms |
コード長 | 2,277 bytes |
コンパイル時間 | 3,594 ms |
コンパイル使用メモリ | 91,704 KB |
実行使用メモリ | 53,596 KB |
最終ジャッジ日時 | 2024-06-22 02:24:13 |
合計ジャッジ時間 | 31,039 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 23 |
ソースコード
import java.io.*; import java.util.*; import java.util.stream.*; public class Main { static final int MOD = 1000000007; public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); char[] inputs = sc.next().toCharArray(); int m = sc.nextInt(); int[] current = new int[m]; int[] next = new int[m]; int ans = 0; for (char c : inputs) { int x = c - '0'; for (int i = 0; i < m; i++) { next[(i * 10 + x) % m] += current[i]; next[(i * 10 + x) % m] %= MOD; } if (x > 0) { next[x % m]++; next[x % m] %= MOD; } else { ans++; ans %= MOD; } ans += next[0]; ans %= MOD; for (int i = 0; i < m; i++) { current[i] += next[i]; current[i] %= MOD; } Arrays.fill(next, 0); } System.out.println(ans); } } class Utilities { static String arrayToLineString(Object[] arr) { return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n")); } static String arrayToLineString(int[] arr) { return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new)); } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); StringBuilder sb = new StringBuilder(); public Scanner() throws Exception { } public int nextInt() throws Exception { return Integer.parseInt(next()); } public long nextLong() throws Exception { return Long.parseLong(next()); } public double nextDouble() throws Exception { return Double.parseDouble(next()); } public int[] nextIntArray() throws Exception { return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray(); } public String next() throws Exception { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }