結果
問題 | No.1 道のショートカット |
ユーザー | uafr_cs |
提出日時 | 2015-04-29 22:48:58 |
言語 | Java21 (openjdk 21) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,362 bytes |
コンパイル時間 | 2,214 ms |
コンパイル使用メモリ | 81,676 KB |
実行使用メモリ | 60,772 KB |
最終ジャッジ日時 | 2023-09-22 12:08:40 |
合計ジャッジ時間 | 11,370 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 122 ms
55,820 KB |
testcase_01 | AC | 123 ms
56,116 KB |
testcase_02 | AC | 122 ms
55,916 KB |
testcase_03 | AC | 130 ms
55,508 KB |
testcase_04 | WA | - |
testcase_05 | AC | 122 ms
56,140 KB |
testcase_06 | AC | 134 ms
56,172 KB |
testcase_07 | AC | 138 ms
55,956 KB |
testcase_08 | AC | 201 ms
59,488 KB |
testcase_09 | AC | 206 ms
59,080 KB |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | AC | 122 ms
56,116 KB |
testcase_16 | WA | - |
testcase_17 | AC | 130 ms
55,468 KB |
testcase_18 | AC | 176 ms
56,132 KB |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | AC | 173 ms
56,328 KB |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | AC | 184 ms
56,480 KB |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | AC | 130 ms
55,504 KB |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | WA | - |
testcase_32 | WA | - |
testcase_33 | AC | 198 ms
58,436 KB |
testcase_34 | WA | - |
testcase_35 | WA | - |
testcase_36 | WA | - |
testcase_37 | WA | - |
testcase_38 | AC | 146 ms
55,724 KB |
testcase_39 | WA | - |
testcase_40 | WA | - |
testcase_41 | WA | - |
testcase_42 | AC | 125 ms
55,992 KB |
testcase_43 | AC | 125 ms
55,964 KB |
ソースコード
import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; import java.util.PriorityQueue; import java.util.Scanner; public class Main { public static class State implements Comparable<State> { int node, cost, time; public State(int node, int cost, int time) { super(); this.node = node; this.cost = cost; this.time = time; } public int compareTo(State o) { return Integer.compare(this.time, o.time); } } public static void main(String[] args){ Scanner sc = new Scanner(System.in); final int N = sc.nextInt(); final int C = sc.nextInt(); final int V = sc.nextInt(); int[] S = new int[V]; for(int i = 0; i < V; i++){ S[i] = sc.nextInt() - 1; } int[] T = new int[V]; for(int i = 0; i < V; i++){ T[i] = sc.nextInt() - 1; } int[] Y = new int[V]; for(int i = 0; i < V; i++){ Y[i] = sc.nextInt(); } int[] M = new int[V]; for(int i = 0; i < V; i++){ M[i] = sc.nextInt(); } ArrayList<HashSet<Integer>> nexts = new ArrayList<HashSet<Integer>>(); ArrayList<HashMap<Integer, Integer>> costs = new ArrayList<HashMap<Integer, Integer>>(); ArrayList<HashMap<Integer, Integer>> times = new ArrayList<HashMap<Integer, Integer>>(); for(int i = 0; i < N; i++){ nexts.add(new HashSet<Integer>()); costs.add(new HashMap<Integer, Integer>()); times.add(new HashMap<Integer, Integer>()); } for(int i = 0; i < V; i++){ nexts.get(S[i]).add(T[i]); costs.get(S[i]).put(T[i], Y[i]); times.get(S[i]).put(T[i], M[i]); } boolean[][] visited = new boolean[N][C + 1]; PriorityQueue<State> queue = new PriorityQueue<State>(); queue.add(new State(0, 0, 0)); while(!queue.isEmpty()){ final State state = queue.poll(); if(visited[state.node][state.cost]){ continue; }else{ visited[state.node][state.cost] = true; } if(state.node == N - 1){ System.out.println(state.time); return; } for(final int next : nexts.get(state.node)){ final int next_cost = state.cost + costs.get(state.node).get(next); final int next_time = state.time + times.get(state.node).get(next); if(next_cost > C){ continue; }else if(visited[next][next_cost]){ continue; } queue.add(new State(next, next_cost, next_time)); } } System.out.println(-1); } }