結果
| 問題 |
No.189 SUPER HAPPY DAY
|
| コンテスト | |
| ユーザー |
tenten
|
| 提出日時 | 2021-11-10 16:57:30 |
| 言語 | Java (openjdk 23) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,414 bytes |
| コンパイル時間 | 3,758 ms |
| コンパイル使用メモリ | 79,288 KB |
| 実行使用メモリ | 55,792 KB |
| 最終ジャッジ日時 | 2024-11-21 05:38:53 |
| 合計ジャッジ時間 | 9,792 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 12 WA * 11 |
ソースコード
import java.util.*;
import java.io.*;
public class Main {
static final int MOD = 1000000009;
public static void main(String[] args) throws Exception {
Scanner sc = new Scanner();
TreeMap<Integer, Long> month = getCount(sc.next().toCharArray());
TreeMap<Integer, Long> day = getCount(sc.next().toCharArray());
long ans = 0;
for (int x : month.keySet()) {
if (x == 0) {
continue;
}
ans += month.get(x) * day.getOrDefault(x, 0L) % MOD;
ans %= MOD;
}
System.out.println(ans);
}
static TreeMap<Integer, Long> getCount(char[] value) {
TreeMap<Integer, Long> counts = new TreeMap<>();
counts.put(0, 1L);
int total = 0;
boolean isFirst = true;
for (char c : value) {
int x = c - '0';
if (isFirst) {
isFirst = false;
for (int i = 1; i < x; i++) {
counts.put(i, 1L);
}
total += x;
continue;
}
Integer key = Integer.MAX_VALUE;
while ((key = counts.lowerKey(key)) != null) {
for (int i = 1; i <= 9; i++) {
counts.put(key + i, counts.getOrDefault(key + i, 0L) + counts.get(key));
}
}
for (int i = 0; i < x; i++) {
counts.put(total + i, counts.getOrDefault(total + i, 0L) + 1);
}
total += x;
}
counts.put(total, counts.getOrDefault(total, 0L) + 1);
return counts;
}
}
class Scanner {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer("");
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 String nextLine() throws Exception {
return br.readLine();
}
public String next() throws Exception {
if (!st.hasMoreTokens()) {
st = new StringTokenizer(br.readLine());
}
return st.nextToken();
}
}
tenten