結果

問題 No.189 SUPER HAPPY DAY
ユーザー takeya_okinotakeya_okino
提出日時 2019-06-17 23:35:18
言語 Java21
(openjdk 21)
結果
AC  
実行時間 396 ms / 5,000 ms
コード長 1,590 bytes
コンパイル時間 2,294 ms
コンパイル使用メモリ 74,164 KB
実行使用メモリ 115,972 KB
最終ジャッジ日時 2023-08-19 17:38:00
合計ジャッジ時間 8,811 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 114 ms
55,736 KB
testcase_01 AC 116 ms
57,680 KB
testcase_02 AC 113 ms
55,468 KB
testcase_03 AC 116 ms
57,952 KB
testcase_04 AC 115 ms
57,764 KB
testcase_05 AC 115 ms
58,216 KB
testcase_06 AC 116 ms
57,360 KB
testcase_07 AC 116 ms
57,860 KB
testcase_08 AC 117 ms
57,668 KB
testcase_09 AC 117 ms
57,252 KB
testcase_10 AC 116 ms
57,988 KB
testcase_11 AC 116 ms
58,628 KB
testcase_12 AC 117 ms
57,536 KB
testcase_13 AC 261 ms
80,848 KB
testcase_14 AC 285 ms
80,920 KB
testcase_15 AC 319 ms
87,992 KB
testcase_16 AC 341 ms
86,564 KB
testcase_17 AC 295 ms
81,156 KB
testcase_18 AC 331 ms
88,604 KB
testcase_19 AC 347 ms
88,252 KB
testcase_20 AC 183 ms
65,344 KB
testcase_21 AC 231 ms
69,760 KB
testcase_22 AC 141 ms
60,372 KB
testcase_23 AC 299 ms
87,708 KB
testcase_24 AC 212 ms
68,348 KB
testcase_25 AC 396 ms
115,972 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
  public static long MOD = (long)Math.pow(10, 9) + 9;
  public static long[][][] dp;
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String M = sc.next();
    String D = sc.next();
    int lenM = M.length();
    int lenD = D.length();
    func(D);
    int len2 = D.length();
    long[][][] dp2 = new long[len2][2000][2];
    for(int i = 0; i < len2; i++) {
      for(int j = 0; j < 2000; j++) {
        for(int k = 0; k < 2; k++) {
          dp2[i][j][k] = dp[i][j][k];
        }
      }
    }
    func(M);
    long ans = 0;
    for(int i = 1; i < 2000; i++) {
      long t1 = (dp[lenM - 1][i][0] + dp[lenM - 1][i][1]) % MOD;
      long t2 = (dp2[lenD - 1][i][0] + dp2[lenD - 1][i][1]) % MOD;
      long t = (t1 * t2) % MOD;
      ans = (ans + t) % MOD;
    }
    System.out.println(ans);
  }

  public static void func(String s) {
    int len = s.length();
    dp = new long[len][2000][2];
    int first = Integer.parseInt(String.valueOf(s.charAt(0)));
    for(int i = 0; i < first; i++) {
      dp[0][i][1] = 1; 
    }
    dp[0][first][0] = 1;
    for(int i = 1; i < len; i++) {
      int d = Integer.parseInt(String.valueOf(s.charAt(i)));
      for(int j = 0; j <= (9 * i); j++) {
        dp[i][j + d][0] = (dp[i][j + d][0] + dp[i - 1][j][0]) % MOD;
        for(int k = 0; k < d; k++) {
          dp[i][j + k][1] = (dp[i][j + k][1] + dp[i - 1][j][0]) % MOD;
        }
        for(int k = 0; k < 10; k++) {
          dp[i][j + k][1] = (dp[i][j + k][1] + dp[i - 1][j][1]) % MOD;
        }
      }
    }
  }
}
0