結果

問題 No.612 Move on grid
ユーザー htensaihtensai
提出日時 2020-02-12 09:59:48
言語 Java21
(openjdk 21)
結果
AC  
実行時間 467 ms / 2,500 ms
コード長 1,191 bytes
コンパイル時間 2,190 ms
コンパイル使用メモリ 77,120 KB
実行使用メモリ 92,656 KB
最終ジャッジ日時 2024-04-14 06:27:26
合計ジャッジ時間 10,767 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 144 ms
54,016 KB
testcase_01 AC 174 ms
54,288 KB
testcase_02 AC 180 ms
54,344 KB
testcase_03 AC 240 ms
63,324 KB
testcase_04 AC 467 ms
92,068 KB
testcase_05 AC 443 ms
92,424 KB
testcase_06 AC 447 ms
92,656 KB
testcase_07 AC 451 ms
92,496 KB
testcase_08 AC 448 ms
92,212 KB
testcase_09 AC 447 ms
92,188 KB
testcase_10 AC 365 ms
78,412 KB
testcase_11 AC 276 ms
66,488 KB
testcase_12 AC 379 ms
85,292 KB
testcase_13 AC 283 ms
69,720 KB
testcase_14 AC 400 ms
85,384 KB
testcase_15 AC 259 ms
66,004 KB
testcase_16 AC 432 ms
89,924 KB
testcase_17 AC 289 ms
69,596 KB
testcase_18 AC 380 ms
86,136 KB
testcase_19 AC 344 ms
85,544 KB
testcase_20 AC 429 ms
90,016 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    static final int MOD = 1000000007;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        int[] arr = new int[3];
        int count = 0;
        int max = 0;
        for (int i = 0; i < 3; i++) {
            arr[i] = Math.abs(sc.nextInt());
        }
        int d = sc.nextInt();
        int e = sc.nextInt();
        int[][] dp = new int[t + 1][20002];
        dp[0][10001] = 1;
        for (int i = 0; i < t; i++) {
            for (int j = 0; j < dp[i].length; j++) {
                for (int x : arr) {
                    if (j - x >= 0) {
                        dp[i + 1][j - x] += dp[i][j];
                        dp[i + 1][j - x] %= MOD;
                    }
                    if (j + x < dp[i].length) {
                        dp[i + 1][j + x] += dp[i][j];
                        dp[i + 1][j + x] %= MOD;
                    }
                }
            }
        }
        int total = 0;
        for (int i = d + 10001; i <= e + 10001; i++) {
            total += dp[t][i];
            total %= MOD;
        }
        System.out.println(total);
    }
}
0