結果
問題 | No.1 道のショートカット |
ユーザー | uafr_cs |
提出日時 | 2015-04-29 22:52:25 |
言語 | Java21 (openjdk 21) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,828 bytes |
コンパイル時間 | 2,107 ms |
コンパイル使用メモリ | 80,296 KB |
実行使用メモリ | 58,940 KB |
最終ジャッジ日時 | 2024-07-08 03:54:43 |
合計ジャッジ時間 | 10,231 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 109 ms
53,496 KB |
testcase_01 | AC | 116 ms
52,852 KB |
testcase_02 | AC | 111 ms
53,320 KB |
testcase_03 | AC | 122 ms
54,236 KB |
testcase_04 | WA | - |
testcase_05 | AC | 118 ms
53,960 KB |
testcase_06 | AC | 122 ms
54,316 KB |
testcase_07 | AC | 119 ms
53,948 KB |
testcase_08 | AC | 190 ms
57,900 KB |
testcase_09 | AC | 188 ms
56,772 KB |
testcase_10 | AC | 193 ms
57,436 KB |
testcase_11 | AC | 196 ms
57,644 KB |
testcase_12 | WA | - |
testcase_13 | AC | 206 ms
57,976 KB |
testcase_14 | AC | 141 ms
53,996 KB |
testcase_15 | AC | 115 ms
53,780 KB |
testcase_16 | WA | - |
testcase_17 | AC | 117 ms
54,192 KB |
testcase_18 | AC | 160 ms
54,308 KB |
testcase_19 | AC | 148 ms
54,320 KB |
testcase_20 | AC | 157 ms
54,436 KB |
testcase_21 | AC | 162 ms
54,104 KB |
testcase_22 | AC | 157 ms
54,084 KB |
testcase_23 | AC | 200 ms
57,744 KB |
testcase_24 | AC | 194 ms
57,436 KB |
testcase_25 | AC | 159 ms
54,572 KB |
testcase_26 | AC | 155 ms
54,200 KB |
testcase_27 | AC | 200 ms
57,568 KB |
testcase_28 | AC | 124 ms
54,260 KB |
testcase_29 | AC | 195 ms
57,508 KB |
testcase_30 | WA | - |
testcase_31 | AC | 180 ms
56,728 KB |
testcase_32 | WA | - |
testcase_33 | WA | - |
testcase_34 | WA | - |
testcase_35 | AC | 187 ms
57,320 KB |
testcase_36 | WA | - |
testcase_37 | WA | - |
testcase_38 | WA | - |
testcase_39 | AC | 153 ms
54,136 KB |
testcase_40 | WA | - |
testcase_41 | WA | - |
testcase_42 | AC | 116 ms
54,424 KB |
testcase_43 | AC | 110 ms
53,860 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) { if(Integer.compare(this.time, o.time) != 0){ return Integer.compare(this.time, o.time); }else if(Integer.compare(this.cost, o.cost) != 0){ return Integer.compare(this.cost, o.cost); }else if(Integer.compare(this.node, o.node) != 0){ return Integer.compare(this.node, o.node); }else{ return 0; } } } 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], Math.min(Y[i], costs.get(S[i]).containsKey(T[i]) ? costs.get(S[i]).get(T[i]) : Integer.MAX_VALUE)); times.get(S[i]).put(T[i], Math.min(M[i], times.get(S[i]).containsKey(T[i]) ? times.get(S[i]).get(T[i]) : Integer.MAX_VALUE)); } 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); } }