結果

問題 No.1 道のショートカット
ユーザー yuki2006yuki2006
提出日時 2014-10-01 18:28:10
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 3,484 bytes
コンパイル時間 4,596 ms
コンパイル使用メモリ 82,204 KB
実行使用メモリ 61,424 KB
最終ジャッジ日時 2023-09-22 11:42:01
合計ジャッジ時間 14,198 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 123 ms
56,324 KB
testcase_03 AC 131 ms
55,892 KB
testcase_04 WA -
testcase_05 AC 123 ms
55,492 KB
testcase_06 AC 131 ms
55,768 KB
testcase_07 AC 139 ms
56,172 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 122 ms
56,084 KB
testcase_16 WA -
testcase_17 AC 125 ms
56,360 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 185 ms
56,508 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 AC 128 ms
55,468 KB
testcase_43 AC 126 ms
55,900 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Random;
import java.util.Scanner;

public class Yuki001 {
    private static boolean isDebug = false;

    public static void main(String[] args) {


        ArrayList<Integer> si = new ArrayList<Integer>();
        ArrayList<Integer> ti = new ArrayList<Integer>();
        ArrayList<Integer> ci = new ArrayList<Integer>();
        ArrayList<Integer> tis = new ArrayList<Integer>();

        Scanner scanner = new Scanner(System.in);

        int N = 10;
        int C = 20;

        if (isDebug) {
        } else {
            N = scanner.nextInt();
            C = scanner.nextInt();
        }

        int[][] cost = new int[N + 1][N + 1];
        int[][] time = new int[N + 1][N + 1];


        if (isDebug) {

            Random random = new Random();
            random.setSeed(1);

            for (int i = 2; i < N + 1; i++) {
                for (int j = 1; j < i; j++) {
                    int k = random.nextInt(C);
                    if (k > 5) {
                        cost[i][j] = k;
                        time[i][j] = random.nextInt(10) + 1;
                        ti.add(i);
                        si.add(j);
                        ci.add(k);
                        tis.add(time[i][j]);
                    }
                }
            }
        } else {
            int V = scanner.nextInt();

            for (int i = 0; i < V; i++) {
                si.add(scanner.nextInt());
            }
            for (int i = 0; i < V; i++) {
                ti.add(scanner.nextInt());
            }
            for (int i = 0; i < V; i++) {
                ci.add(scanner.nextInt());
                cost[ti.get(i)][si.get(i)] = ci.get(i);
            }
            for (int i = 0; i < V; i++) {
                tis.add(scanner.nextInt());
                time[ti.get(i)][si.get(i)] = tis.get(i);
            }
        }

        int MAX = Integer.MAX_VALUE / 2;

        int[][] dp = new int[N + 1][C + 1];

        for (int i = 0; i < dp.length; i++) {
            Arrays.fill(dp[i], MAX);
        }
        dp[1][C] = 0;
        for (int i = 2; i < N + 1; i++) {
            for (int k = 1; k < i; k++) {
                if (cost[i][k] == 0) {
                    break;
                }
                for (int t = 0; t <= C; t++) {
                    if (dp[k][t] >= MAX) {
                        continue;
                    }
                    int c = t - cost[i][k];
                    if (c < 0) {
                        continue;
                    }
                    dp[i][c] = Math.min(dp[i][c], dp[k][t] + time[i][k]);
                }
            }
        }

        boolean isCheck = false;
        for (int i = C; i >= 0; i--) {
            if (dp[N][i] != MAX) {
                System.out.println(dp[N][i]);
                isCheck = true;
                break;
            }
        }
        if (!isCheck) {
            System.out.println(-1);
        }

        System.out.flush();
        if (isDebug) {
            System.err.println(N);
            System.err.println(C);

            System.err.println(si.size());
            System.err.println(wrap(si));
            System.err.println(wrap(ti));
            System.err.println(wrap(ci));
            System.err.println(wrap(tis));
        }
    }

    static String wrap(ArrayList<? extends Object> list) {
        return list.toString().replace("[", "").replace("]", "").replace(",", "");
    }
}
0