結果

問題 No.612 Move on grid
ユーザー htensaihtensai
提出日時 2020-02-12 09:40:35
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 1,633 bytes
コンパイル時間 2,224 ms
コンパイル使用メモリ 79,588 KB
実行使用メモリ 79,708 KB
最終ジャッジ日時 2024-04-14 05:58:57
合計ジャッジ時間 9,197 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 118 ms
53,120 KB
testcase_01 AC 133 ms
54,196 KB
testcase_02 AC 136 ms
54,656 KB
testcase_03 AC 493 ms
75,388 KB
testcase_04 AC 511 ms
79,708 KB
testcase_05 TLE -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
権限があれば一括ダウンロードができます

ソースコード

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[6];
        int count = 0;
        int max = 0;
        for (int i = 0; i < 3; i++) {
            arr[i] = sc.nextInt();
            arr[i + 3] = -arr[i];
            max = Math.max(max, Math.abs(arr[i]));
        }
        int d = sc.nextInt();
        int e = sc.nextInt();
        HashMap<Integer, Integer>[] maps = new HashMap[t + 1];
        maps[0] = new HashMap<>();
        maps[0].put(0, 1);
        for (int i = 1; i <= t; i++) {
            maps[i] = new HashMap<>();
            for (Map.Entry<Integer, Integer> entry : maps[i - 1].entrySet()) {
                int x = entry.getKey();
                int y = entry.getValue();
                for (int z : arr) {
                    if (x + z + max * (t - i) < d) {
                        continue;
                    }
                    if (x + z - max * (t - i) > e) {
                        continue;
                    }
                    if (maps[i].containsKey(x + z)) {
                        maps[i].put(x + z, (maps[i].get(x + z) + y) % MOD);
                    } else {
                        maps[i].put(x + z, y);
                    }
                }
            }
        }
        int total = 0;
        for (int i = d; i <= e; i++) {
            if (maps[t].containsKey(i)) {
                total += maps[t].get(i);
                total %= MOD;
            }
        }
        System.out.println(total);
    }
}
0