結果
問題 | No.1 道のショートカット |
ユーザー |
![]() |
提出日時 | 2015-04-23 13:27:31 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 243 ms / 5,000 ms |
コード長 | 1,841 bytes |
コンパイル時間 | 2,052 ms |
コンパイル使用メモリ | 77,324 KB |
実行使用メモリ | 46,340 KB |
最終ジャッジ日時 | 2024-07-20 16:12:43 |
合計ジャッジ時間 | 11,277 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 40 |
ソースコード
import java.util.*; public class Main { public static void main(String[] args) throws Exception { Scanner koko = new Scanner(System.in); int n = koko.nextInt(); int c = koko.nextInt(); int v = koko.nextInt(); int[] s = new int[v]; int[] t = new int[v]; int[] y = new int[v]; int[] m = new int[v]; for(int i=0; i<v; i++){ s[i]=koko.nextInt(); } for(int i=0; i<v; i++){ t[i]=koko.nextInt(); } for(int i=0; i<v; i++){ y[i]=koko.nextInt(); } for(int i=0; i<v; i++){ m[i]=koko.nextInt(); } boolean[][] stop = new boolean[n+1][c+1]; int[][] stoptime = new int[n+1][c+1]; stop[1][0]=true; stoptime[1][0]=0; for(int i=2; i<n+1; i++){ for(int j=0; j<v; j++){ if(i==t[j]){ for(int cost=0; cost<c+1-y[j]; cost++){ if(stop[s[j]][cost]){ if(stop[i][cost+y[j]]){ stoptime[i][cost+y[j]]=Math.min(stoptime[i][cost+y[j]], stoptime[s[j]][cost]+m[j]); }else{ stop[i][cost+y[j]]=true; stoptime[i][cost+y[j]]=stoptime[s[j]][cost]+m[j]; } } } } } } boolean flag = false; int min = n*1000; for(int cost=0; cost<c+1; cost++){ if(stop[n][cost]){ flag = true; min=Math.min(min, stoptime[n][cost]); } } if(flag){ System.out.println(min); }else{ System.out.println(-1); } } }