結果

問題 No.189 SUPER HAPPY DAY
ユーザー tentententen
提出日時 2021-11-10 16:57:30
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 2,414 bytes
コンパイル時間 2,069 ms
コンパイル使用メモリ 79,168 KB
実行使用メモリ 60,376 KB
最終ジャッジ日時 2024-05-01 04:33:17
合計ジャッジ時間 9,583 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 52 ms
50,484 KB
testcase_01 AC 57 ms
50,444 KB
testcase_02 AC 52 ms
49,984 KB
testcase_03 AC 58 ms
50,472 KB
testcase_04 AC 55 ms
50,340 KB
testcase_05 AC 58 ms
50,304 KB
testcase_06 AC 57 ms
50,480 KB
testcase_07 AC 61 ms
50,504 KB
testcase_08 AC 58 ms
50,260 KB
testcase_09 AC 60 ms
50,440 KB
testcase_10 AC 59 ms
50,476 KB
testcase_11 AC 59 ms
50,052 KB
testcase_12 AC 58 ms
50,380 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 403 ms
57,100 KB
testcase_24 AC 417 ms
57,236 KB
testcase_25 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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