結果
問題 | No.1 道のショートカット |
ユーザー | Amanita2016 |
提出日時 | 2017-09-16 16:37:40 |
言語 | Java21 (openjdk 21) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,877 bytes |
コンパイル時間 | 3,042 ms |
コンパイル使用メモリ | 77,444 KB |
実行使用メモリ | 55,356 KB |
最終ジャッジ日時 | 2024-07-08 04:57:29 |
合計ジャッジ時間 | 7,908 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 50 ms
50,128 KB |
testcase_01 | AC | 47 ms
49,960 KB |
testcase_02 | AC | 48 ms
50,400 KB |
testcase_03 | AC | 48 ms
50,484 KB |
testcase_04 | AC | 48 ms
50,220 KB |
testcase_05 | AC | 49 ms
50,284 KB |
testcase_06 | AC | 48 ms
50,228 KB |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | RE | - |
testcase_16 | WA | - |
testcase_17 | RE | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | RE | - |
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 | RE | - |
testcase_43 | RE | - |
ソースコード
package yukicoder; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Shortcut { private static BufferedReader br; public static void main(String[] args) throws IOException{ br = new BufferedReader(new InputStreamReader(System.in)); int town = Integer.parseInt(br.readLine()); int money = Integer.parseInt(br.readLine()); int road = Integer.parseInt(br.readLine()); road++; int[] s = new int[road]; int[] t = new int[road]; int[] y = new int[road]; int[] m = new int[road]; arrayInit(s); arrayInit(t); arrayInit(y); arrayInit(m); //Library.disp(Library.cast(m)); int dp[][] = new int[3][road]; // cost time while(true){ for(int i = 1 ; i < road; i++){ dp[0][i] = 0; dp[1][i] = 0; dp[2][i] = -1; } for(int i = 1 ; i < road ; i++){ int from = s[i]; if(from == -1){ continue; } int to = t[i]; int fCost = dp[0][from]; int fTime = dp[1][from]; int tTime = dp[1][to]; int totalCost = y[i] + fCost; int totalTime = m[i] + fTime; if((tTime == 0 || totalTime < tTime) && totalCost <= money ){ dp[0][to] = totalCost; dp[1][to] = totalTime; dp[2][to] = i; } } int time = dp[1][road-1]; if(time == 0){ int max = -1; for(int i = 1 ; i < road ; i++){ int from = dp[2][i]; if(max < from){ max = from; } } if(max == -1){ break; } s[max] = -1; continue; } break; } int time = dp[1][road-1]; int disp = time == 0 ? -1 : time; System.out.println(disp); } private static void arrayInit(int[] array) throws IOException{ String[] spl = br.readLine().split(" "); for(int i = 1 ; i < array.length ; i++){ array[i] = Integer.parseInt(spl[i-1]); } } }