結果
問題 |
No.372 It's automatic
|
ユーザー |
![]() |
提出日時 | 2019-11-21 10:44:07 |
言語 | Java (openjdk 23) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,327 bytes |
コンパイル時間 | 2,198 ms |
コンパイル使用メモリ | 79,216 KB |
実行使用メモリ | 41,452 KB |
最終ジャッジ日時 | 2024-10-09 13:15:10 |
合計ジャッジ時間 | 10,472 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | WA * 1 TLE * 1 -- * 21 |
ソースコード
import java.util.*; public class Main { static final int MOD = 1000000007; public static void main (String[] args) { Scanner sc = new Scanner(System.in); char[] arr = sc.next().toCharArray(); int m = sc.nextInt(); TreeMap<Integer, Integer> map = new TreeMap<>(); TreeMap<Integer, Integer> next = new TreeMap(); map.put(0, 1); boolean hasZero = false; for (int i = 0; i < arr.length; i++) { int x = arr[i] - '0'; if (x == 0) { hasZero = true; } while (map.size() > 0) { Map.Entry<Integer, Integer> entry = map.pollFirstEntry(); int y = entry.getKey(); if (next.containsKey(y)) { next.put(y, (entry.getValue() + next.get(y)) % MOD); } else { next.put(y, entry.getValue()); } int z; if (x == 0 && y == 0) { z = entry.getValue() - 1; } else { z = entry.getValue(); } y = (x + y) % m; if (next.containsKey(y)) { next.put(y, (z + next.get(y)) % MOD); } else { next.put(y, z); } } TreeMap<Integer, Integer> tmp = next; next = map; map = tmp; } int ans = map.get(0); if (!hasZero) { ans--; } System.out.println(ans); } }