結果

問題 No.189 SUPER HAPPY DAY
ユーザー ぴろずぴろず
提出日時 2015-05-29 12:32:51
言語 Java21
(openjdk 21)
結果
AC  
実行時間 258 ms / 5,000 ms
コード長 1,157 bytes
コンパイル時間 2,085 ms
コンパイル使用メモリ 74,600 KB
実行使用メモリ 65,448 KB
最終ジャッジ日時 2023-09-20 15:36:31
合計ジャッジ時間 8,362 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 128 ms
55,540 KB
testcase_01 AC 177 ms
57,048 KB
testcase_02 AC 127 ms
55,564 KB
testcase_03 AC 169 ms
56,496 KB
testcase_04 AC 171 ms
56,144 KB
testcase_05 AC 170 ms
56,100 KB
testcase_06 AC 169 ms
56,428 KB
testcase_07 AC 170 ms
56,352 KB
testcase_08 AC 171 ms
56,604 KB
testcase_09 AC 170 ms
56,480 KB
testcase_10 AC 170 ms
56,360 KB
testcase_11 AC 171 ms
56,448 KB
testcase_12 AC 171 ms
56,428 KB
testcase_13 AC 200 ms
59,300 KB
testcase_14 AC 220 ms
63,580 KB
testcase_15 AC 210 ms
61,096 KB
testcase_16 AC 214 ms
65,448 KB
testcase_17 AC 216 ms
61,148 KB
testcase_18 AC 208 ms
61,328 KB
testcase_19 AC 230 ms
63,612 KB
testcase_20 AC 197 ms
60,800 KB
testcase_21 AC 196 ms
59,276 KB
testcase_22 AC 178 ms
56,656 KB
testcase_23 AC 184 ms
60,116 KB
testcase_24 AC 209 ms
60,940 KB
testcase_25 AC 258 ms
65,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package no189;

import java.util.Scanner;

public class Main {
	public static final long MOD = 1000000009;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long[] m = count(sc.next());
		long[] d = count(sc.next());
		long ans = 0;
		for(int i=1;i<=2000;i++) {
			ans = (ans + m[i] * d[i]) % MOD;
		}
		System.out.println(ans);
	}

	public static long[] count(String s) {
		int n = s.length();
		int[] d = new int[n];
		for(int i=0;i<n;i++) {
			d[i] = s.charAt(i) - '0';
		}
		long[][][] dp = new long[n+1][2][2020];
		dp[0][0][0] = 1;
		for(int i=0;i<n;i++) {
			for(int j=0;j<=2000;j++) {
				for(int k=0;k<=9;k++) {
					dp[i+1][1][j+k] += dp[i][1][j];
					if (d[i] > k) {
						dp[i+1][1][j+k] += dp[i][0][j];
					}else if(d[i] == k) {
						dp[i+1][0][j+k] += dp[i][0][j];
					}
					dp[i+1][0][j+k] %= MOD;
					dp[i+1][1][j+k] %= MOD;
				}
			}
//			System.out.println(i);
//			System.out.println(Arrays.toString(dp[i][0]));
//			System.out.println(Arrays.toString(dp[i][1]));
		}
		long[] ret = new long[2020];
		for(int i=0;i<2020;i++) {
			ret[i] = (dp[n][0][i] + dp[n][1][i]) % MOD;
		}
		return ret;
	}

}
0