結果
問題 |
No.1 道のショートカット
|
ユーザー |
![]() |
提出日時 | 2015-02-26 22:52:47 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 241 ms / 5,000 ms |
コード長 | 1,074 bytes |
コンパイル時間 | 2,173 ms |
コンパイル使用メモリ | 77,732 KB |
実行使用メモリ | 46,296 KB |
最終ジャッジ日時 | 2024-07-20 16:11:16 |
合計ジャッジ時間 | 11,512 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 40 |
ソースコード
import java.math.*; import java.util.*; class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int c = sc.nextInt(); int v = sc.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]=sc.nextInt(); } for(int i=0;i<v;i++){ t[i]=sc.nextInt(); } for(int i=0;i<v;i++){ y[i]=sc.nextInt(); } for(int i=0;i<v;i++){ m[i]=sc.nextInt(); } int[][] dp=new int[n+1][c+1]; for(int i=1;i<=n;i++){ Arrays.fill(dp[i], Integer.MAX_VALUE-2000); } Arrays.fill(dp[1], 0); for(int i=1;i<n;i++){ for(int j=0;j<v;j++){ if(s[j]==i){ for(int k=0;k<=c;k++){ if(k!=Integer.MAX_VALUE-2000 && k+y[j]<=c){ dp[t[j]][k+y[j]]=Math.min(dp[t[j]][k+y[j]], dp[i][k]+m[j]); } } } } } int ans=Integer.MAX_VALUE-2000; for(int i=0;i<=c;i++){ ans=Math.min(ans, dp[n][i]); } if(ans==Integer.MAX_VALUE-2000){ System.out.println(-1); }else{ System.out.println(ans); } } }