結果
問題 | No.1 道のショートカット |
ユーザー | zimpha |
提出日時 | 2017-03-20 19:09:53 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 115 ms / 5,000 ms |
コード長 | 3,279 bytes |
コンパイル時間 | 2,617 ms |
コンパイル使用メモリ | 80,048 KB |
実行使用メモリ | 40,392 KB |
最終ジャッジ日時 | 2024-07-20 16:29:27 |
合計ジャッジ時間 | 6,781 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 48 ms
36,992 KB |
testcase_01 | AC | 47 ms
37,328 KB |
testcase_02 | AC | 47 ms
37,184 KB |
testcase_03 | AC | 47 ms
37,288 KB |
testcase_04 | AC | 47 ms
36,848 KB |
testcase_05 | AC | 47 ms
36,812 KB |
testcase_06 | AC | 47 ms
37,244 KB |
testcase_07 | AC | 47 ms
37,272 KB |
testcase_08 | AC | 85 ms
38,992 KB |
testcase_09 | AC | 84 ms
38,700 KB |
testcase_10 | AC | 92 ms
38,656 KB |
testcase_11 | AC | 88 ms
39,124 KB |
testcase_12 | AC | 115 ms
40,392 KB |
testcase_13 | AC | 111 ms
40,064 KB |
testcase_14 | AC | 48 ms
37,336 KB |
testcase_15 | AC | 47 ms
37,224 KB |
testcase_16 | AC | 54 ms
36,980 KB |
testcase_17 | AC | 46 ms
37,376 KB |
testcase_18 | AC | 47 ms
37,520 KB |
testcase_19 | AC | 50 ms
37,444 KB |
testcase_20 | AC | 56 ms
37,480 KB |
testcase_21 | AC | 49 ms
37,432 KB |
testcase_22 | AC | 47 ms
36,860 KB |
testcase_23 | AC | 115 ms
39,540 KB |
testcase_24 | AC | 110 ms
39,856 KB |
testcase_25 | AC | 63 ms
38,348 KB |
testcase_26 | AC | 53 ms
37,376 KB |
testcase_27 | AC | 111 ms
40,072 KB |
testcase_28 | AC | 48 ms
37,376 KB |
testcase_29 | AC | 81 ms
38,952 KB |
testcase_30 | AC | 53 ms
37,372 KB |
testcase_31 | AC | 73 ms
38,128 KB |
testcase_32 | AC | 76 ms
38,612 KB |
testcase_33 | AC | 78 ms
38,140 KB |
testcase_34 | AC | 109 ms
39,644 KB |
testcase_35 | AC | 80 ms
38,612 KB |
testcase_36 | AC | 84 ms
38,488 KB |
testcase_37 | AC | 78 ms
38,300 KB |
testcase_38 | AC | 49 ms
37,464 KB |
testcase_39 | AC | 51 ms
37,496 KB |
testcase_40 | AC | 54 ms
37,724 KB |
testcase_41 | AC | 51 ms
37,308 KB |
testcase_42 | AC | 49 ms
37,228 KB |
testcase_43 | AC | 50 ms
37,228 KB |
ソースコード
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Arrays; import java.util.StringTokenizer; import java.io.IOException; import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.ArrayList; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * * @author Chiaki.Hoshinomori */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); Task001 solver = new Task001(); solver.solve(1, in, out); out.close(); } static class Task001 { public void solve(int testNumber, InputReader in, PrintWriter out) { int N = in.nextInt(); int C = in.nextInt(); int[][] dist = new int[N][]; ArrayList<Integer>[] graph = new ArrayList[N]; for (int i = 0; i < N; i++) { graph[i] = new ArrayList<>(); dist[i] = new int[C + 1]; Arrays.fill(dist[i], 1000000); } int V = in.nextInt(); int[] S = in.nextIntArray(V); int[] T = in.nextIntArray(V); int[] Y = in.nextIntArray(V); int[] M = in.nextIntArray(V); for (int i = 0; i < V; i++) { graph[S[i] - 1].add(i); } dist[0][0] = 0; for (int i = 0; i < N - 1; i++) { for (int j = 0; j < C; j++) { if (dist[i][j] == 1000000) continue; ; for (int k : graph[i]) { if (j + Y[k] <= C) { dist[T[k] - 1][j + Y[k]] = Math.min(dist[T[k] - 1][j + Y[k]], dist[i][j] + M[k]); } } } } int ret = -1; for (int i = 0; i <= C; i++) { if (ret == -1 || dist[N - 1][i] < ret) { ret = dist[N - 1][i]; } } if (ret == 1000000) ret = -1; out.println(ret); } } static class InputReader { public BufferedReader reader; public StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream), 32768); tokenizer = null; } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } public int[] nextIntArray(int n) { int[] r = new int[n]; for (int i = 0; i < n; i++) { r[i] = nextInt(); } return r; } } }