結果

問題 No.372 It's automatic
ユーザー htensaihtensai
提出日時 2019-11-21 10:44:07
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,327 bytes
コンパイル時間 2,510 ms
コンパイル使用メモリ 79,612 KB
実行使用メモリ 72,476 KB
最終ジャッジ日時 2024-04-17 19:08:27
合計ジャッジ時間 10,098 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 95 ms
39,836 KB
testcase_02 AC 98 ms
41,544 KB
testcase_03 AC 106 ms
41,524 KB
testcase_04 TLE -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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);
	}
}
0