結果
問題 | No.1 道のショートカット |
ユーザー | uafr_cs |
提出日時 | 2015-04-29 23:12:47 |
言語 | Java21 (openjdk 21) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,378 bytes |
コンパイル時間 | 2,709 ms |
コンパイル使用メモリ | 76,100 KB |
実行使用メモリ | 61,732 KB |
最終ジャッジ日時 | 2023-09-22 12:08:23 |
合計ジャッジ時間 | 11,969 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 128 ms
55,828 KB |
testcase_01 | AC | 128 ms
55,972 KB |
testcase_02 | AC | 128 ms
55,832 KB |
testcase_03 | AC | 135 ms
55,896 KB |
testcase_04 | AC | 126 ms
55,648 KB |
testcase_05 | AC | 128 ms
55,904 KB |
testcase_06 | AC | 135 ms
55,968 KB |
testcase_07 | AC | 142 ms
55,752 KB |
testcase_08 | AC | 226 ms
59,416 KB |
testcase_09 | AC | 210 ms
58,540 KB |
testcase_10 | AC | 217 ms
59,392 KB |
testcase_11 | AC | 221 ms
58,976 KB |
testcase_12 | AC | 231 ms
59,908 KB |
testcase_13 | WA | - |
testcase_14 | AC | 180 ms
56,012 KB |
testcase_15 | AC | 126 ms
54,080 KB |
testcase_16 | AC | 195 ms
56,536 KB |
testcase_17 | AC | 129 ms
57,884 KB |
testcase_18 | AC | 181 ms
56,084 KB |
testcase_19 | AC | 166 ms
56,012 KB |
testcase_20 | AC | 189 ms
56,028 KB |
testcase_21 | AC | 184 ms
55,996 KB |
testcase_22 | AC | 153 ms
56,164 KB |
testcase_23 | WA | - |
testcase_24 | AC | 218 ms
58,840 KB |
testcase_25 | AC | 190 ms
56,188 KB |
testcase_26 | AC | 187 ms
56,212 KB |
testcase_27 | AC | 220 ms
59,760 KB |
testcase_28 | AC | 133 ms
55,840 KB |
testcase_29 | AC | 221 ms
59,244 KB |
testcase_30 | AC | 196 ms
58,596 KB |
testcase_31 | AC | 208 ms
58,572 KB |
testcase_32 | AC | 210 ms
58,540 KB |
testcase_33 | AC | 204 ms
58,796 KB |
testcase_34 | AC | 218 ms
58,848 KB |
testcase_35 | WA | - |
testcase_36 | AC | 217 ms
59,144 KB |
testcase_37 | AC | 212 ms
59,224 KB |
testcase_38 | AC | 154 ms
56,016 KB |
testcase_39 | AC | 187 ms
55,736 KB |
testcase_40 | AC | 196 ms
58,080 KB |
testcase_41 | AC | 182 ms
56,448 KB |
testcase_42 | AC | 125 ms
55,524 KB |
testcase_43 | AC | 124 ms
55,532 KB |
ソースコード
import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; import java.util.Map.Entry; 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<HashMap<Integer, HashMap<Integer, Integer>>> adj = new ArrayList<HashMap<Integer, HashMap<Integer, Integer>>>(); for(int i = 0; i < N; i++){ adj.add(new HashMap<Integer, HashMap<Integer, Integer>>()); } for(int i = 0; i < V; i++){ if(!adj.get(S[i]).containsKey(T[i])){ adj.get(S[i]).put(T[i], new HashMap<Integer, Integer>()); } adj.get(S[i]).get(T[i]).put(Y[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(Entry<Integer, HashMap<Integer, Integer>> entrys : adj.get(state.node).entrySet()){ final int next = entrys.getKey(); for(Entry<Integer, Integer> entry : entrys.getValue().entrySet()){ final int next_cost = state.cost + entry.getKey(); final int next_time = state.time + entry.getValue(); 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); } }