結果

問題 No.189 SUPER HAPPY DAY
ユーザー htensaihtensai
提出日時 2020-05-11 09:03:40
言語 Java21
(openjdk 21)
結果
AC  
実行時間 246 ms / 5,000 ms
コード長 1,380 bytes
コンパイル時間 2,398 ms
コンパイル使用メモリ 74,468 KB
実行使用メモリ 65,524 KB
最終ジャッジ日時 2023-09-25 03:35:55
合計ジャッジ時間 7,440 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 117 ms
55,712 KB
testcase_01 AC 119 ms
55,804 KB
testcase_02 AC 120 ms
55,640 KB
testcase_03 AC 120 ms
55,848 KB
testcase_04 AC 120 ms
55,608 KB
testcase_05 AC 119 ms
55,284 KB
testcase_06 AC 120 ms
55,804 KB
testcase_07 AC 120 ms
55,700 KB
testcase_08 AC 119 ms
56,136 KB
testcase_09 AC 120 ms
55,792 KB
testcase_10 AC 119 ms
55,640 KB
testcase_11 AC 121 ms
55,432 KB
testcase_12 AC 120 ms
55,772 KB
testcase_13 AC 168 ms
60,212 KB
testcase_14 AC 178 ms
62,840 KB
testcase_15 AC 171 ms
64,892 KB
testcase_16 AC 181 ms
65,200 KB
testcase_17 AC 188 ms
65,096 KB
testcase_18 AC 176 ms
64,992 KB
testcase_19 AC 196 ms
64,904 KB
testcase_20 AC 146 ms
58,248 KB
testcase_21 AC 161 ms
58,336 KB
testcase_22 AC 122 ms
55,840 KB
testcase_23 AC 178 ms
64,948 KB
testcase_24 AC 177 ms
64,928 KB
testcase_25 AC 246 ms
65,524 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    static final int MOD = 1000000009;
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int[] months = getCount(sc.next().toCharArray());
		int[] days = getCount(sc.next().toCharArray());
		long total = 0;
		for (int i = 1; i < months.length && i < days.length; i++) {
		    total += (long)months[i] * days[i] % MOD;
		    total %= MOD;
		}
	    System.out.println(total);
	}
	
	static int[] getCount(char[] arr) {
	    int length = arr.length;
	    int[][][] dp = new int[length + 1][length * 9 + 1][2];
	    dp[0][0][1] = 1;
	    for (int i = 1; i <= length; i++) {
	        for (int j = 0; j <= (i - 1) * 9; j++) {
	            for (int k = 0; k <= 9; k++) {
	                dp[i][j + k][0] += dp[i - 1][j][0];
	                dp[i][j + k][0] %= MOD;
	                if (k < arr[i - 1] - '0') {
	                    dp[i][j + k][0] += dp[i - 1][j][1];
	                    dp[i][j + k][0] %= MOD;
	                } else if (k == arr[i - 1] - '0') {
	                    dp[i][j + k][1] += dp[i - 1][j][1];
	                    dp[i][j + k][1] %= MOD;
	                }
	            }
	        }
	    }
	    int[] ans = new int[length * 9 + 1];
	    for (int i = 1; i < ans.length; i++) {
	        ans[i] = dp[length][i][0] + dp[length][i][1];
	        ans[i] %= MOD;
	    }
	    return ans;
	}
}
0