結果

問題 No.1 道のショートカット
ユーザー kou6839
提出日時 2014-11-08 01:00:03
言語 Java
(openjdk 23)
結果
WA  
実行時間 -
コード長 1,585 bytes
コンパイル時間 1,937 ms
コンパイル使用メモリ 78,936 KB
実行使用メモリ 57,636 KB
最終ジャッジ日時 2024-07-08 03:35:02
合計ジャッジ時間 10,514 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 24 WA * 11 RE * 5
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
 
class miti{
	int now;
	int to;
	int cost;
	int time;
	miti(int now,int to,int cost,int time){
		this.now = now;
		this.to = to;
		this.cost=cost;
		this.time = time;
	}
}
class mitiComparator implements Comparator<miti>{

	@Override
	public int compare(miti o1, miti o2) {
		if(o1.now>o2.now){
			return 1;
		}else if(o1.now==o2.now){
			return 0;
		}else{
			return -1;
		}
	}
	
}
public 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();
		}
		miti[] miti1=new miti[V];
		for(int i=0;i<V;i++){
			miti1[i]=new miti(S[i],T[i],Y[i],M[i]);
		}
		Arrays.sort(miti1,new mitiComparator());

		int[] sumc =new int[V+1];
		int[] sumt = new int[V+1];
		for(int i=2;i<=V;i++){
			sumc[i]=Integer.MAX_VALUE;
			sumt[i]=Integer.MAX_VALUE;
		}
		for(miti a:miti1){
			if(sumc[a.now]==Integer.MAX_VALUE) continue;
			if(sumc[a.now]+a.cost<=C){
			sumc[a.to]=Math.min(sumc[a.to], sumc[a.now]+a.cost);
			}else{
				continue;
			}
			sumt[a.to]=Math.min(sumt[a.to], sumt[a.now]+a.time);
		}
		if(sumc[N]<Integer.MAX_VALUE){
			System.out.println(sumt[N]);
		}else{
			System.out.println(-1);
		}
	}
}
0