結果

問題 No.189 SUPER HAPPY DAY
ユーザー tentententen
提出日時 2021-11-10 16:57:30
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 2,414 bytes
コンパイル時間 3,400 ms
コンパイル使用メモリ 75,664 KB
実行使用メモリ 60,048 KB
最終ジャッジ日時 2023-08-13 11:15:07
合計ジャッジ時間 10,697 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
49,500 KB
testcase_01 AC 56 ms
51,352 KB
testcase_02 AC 45 ms
49,428 KB
testcase_03 AC 55 ms
50,156 KB
testcase_04 AC 52 ms
50,244 KB
testcase_05 AC 54 ms
50,608 KB
testcase_06 AC 51 ms
50,056 KB
testcase_07 AC 58 ms
51,564 KB
testcase_08 AC 52 ms
50,152 KB
testcase_09 AC 54 ms
50,324 KB
testcase_10 AC 54 ms
50,188 KB
testcase_11 AC 55 ms
50,164 KB
testcase_12 AC 57 ms
50,200 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 427 ms
57,128 KB
testcase_24 AC 420 ms
57,384 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