結果

問題 No.189 SUPER HAPPY DAY
ユーザー tentententen
提出日時 2022-08-19 18:03:49
言語 Java21
(openjdk 21)
結果
AC  
実行時間 147 ms / 5,000 ms
コード長 3,564 bytes
コンパイル時間 2,377 ms
コンパイル使用メモリ 79,000 KB
実行使用メモリ 43,876 KB
最終ジャッジ日時 2024-04-16 21:38:53
合計ジャッジ時間 5,378 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 52 ms
37,164 KB
testcase_01 AC 52 ms
36,696 KB
testcase_02 AC 52 ms
36,824 KB
testcase_03 AC 53 ms
36,972 KB
testcase_04 AC 53 ms
36,820 KB
testcase_05 AC 52 ms
36,788 KB
testcase_06 AC 54 ms
36,964 KB
testcase_07 AC 53 ms
36,776 KB
testcase_08 AC 54 ms
37,232 KB
testcase_09 AC 53 ms
37,188 KB
testcase_10 AC 53 ms
36,972 KB
testcase_11 AC 54 ms
37,020 KB
testcase_12 AC 53 ms
36,796 KB
testcase_13 AC 107 ms
40,208 KB
testcase_14 AC 106 ms
40,896 KB
testcase_15 AC 100 ms
41,136 KB
testcase_16 AC 98 ms
41,756 KB
testcase_17 AC 127 ms
42,016 KB
testcase_18 AC 99 ms
41,128 KB
testcase_19 AC 125 ms
42,380 KB
testcase_20 AC 91 ms
38,904 KB
testcase_21 AC 90 ms
38,600 KB
testcase_22 AC 56 ms
36,888 KB
testcase_23 AC 99 ms
41,976 KB
testcase_24 AC 109 ms
42,236 KB
testcase_25 AC 147 ms
43,876 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;

public class Main {
    static final int MOD = 1000000009;
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        long[] month = getDp(sc.next().toCharArray());
        long[] day = getDp(sc.next().toCharArray());
        long ans = 0;
        for (int i = 1; i < month.length && i < day.length; i++) {
            ans += (month[i] % MOD) * (day[i] % MOD) % MOD;
            ans %= MOD;
        }
        System.out.println(ans);
    }
    
    static long[] getDp(char[] inputA) {
        long[][] dp = new long[inputA.length][inputA.length * 9 + 1];
        for (int i = 1; i < inputA[0] - '0'; i++) {
            dp[0][i] = 1;
        }
        int current = inputA[0] - '0';
        for (int i = 1; i < inputA.length; i++) {
            int x = inputA[i] - '0';
            for (int j = 1; j < i * 9; j++) {
                if (dp[i - 1][j] == 0) {
                    continue;
                }
                for (int k = 0; k < 10; k++) {
                    dp[i][j + k] += dp[i - 1][j];
                    dp[i][j + k] %= MOD;
                }
            }
            for (int j = 1; j < 10; j++) {
                dp[i][j]++;
            }
            for (int j = 0; j < x; j++) {
                dp[i][current + j]++;
            }
            current += x;
        }
        dp[inputA.length - 1][current]++;
        return dp[inputA.length - 1];
    }
    
    static HashMap<Integer, Integer> getMap(int x) {
        HashMap<Integer, Integer> ans = new HashMap<>();
        for (int i = 2; i <= x; i++) {
            int y = i;
            for (int j = 2; j <= Math.sqrt(y); j++) {
                while (y % j == 0) {
                    ans.put(j, ans.getOrDefault(j, 0) + 1);
                    y /= j;
                }
            }
            if (y > 1) {
                ans.put(y, ans.getOrDefault(y, 0) + 1);
            }
        }
        return ans;
    }
    
    static int pow(int x, int p) {
        if (p == 0) {
            return 1;
        } else if (p % 2 == 0) {
            return pow(x * x % MOD, p / 2);
        } else {
            return pow(x, p - 1) * x % MOD;
        }
    }
    
    static int check(int idx, ArrayList<Integer> list) {
        if (idx < 0) {
            return 0;
        }
        ArrayList<Integer> odd  = new ArrayList<>();
        ArrayList<Integer> ev = new ArrayList<>();
        for (int x : list) {
            if ((x & (1 << idx)) == 0) {
                ev.add(x);
            } else {
                odd.add(x);
            }
        }
        if (ev.size() == 0) {
            return check(idx - 1, odd);
        } else if (odd.size() == 0) {
            return check(idx - 1, ev);
        } else {
            return Math.min(check(idx - 1, odd), check(idx - 1, ev)) + (1 << idx);
        }
    }
}

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 next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
}
0