結果

問題 No.1 道のショートカット
ユーザー doyazaki012
提出日時 2015-05-31 07:15:05
言語 Java
(openjdk 23)
結果
AC  
実行時間 373 ms / 5,000 ms
コード長 1,498 bytes
コンパイル時間 2,468 ms
コンパイル使用メモリ 77,080 KB
実行使用メモリ 78,084 KB
最終ジャッジ日時 2024-07-20 16:15:16
合計ジャッジ時間 14,595 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 40
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

class Yuki1{
	public static final int MAX_TOWN = 50;
	public static final int MAX_MONNEY = 100000; 
	public static boolean[][] done = new boolean[MAX_TOWN+1][MAX_MONNEY];
	public static int[][] memo = new int[MAX_TOWN+1][MAX_MONNEY];
	public static int n ;
	public static int c ;
	public static int v ;
	public static int[] s = new int[1501];
	public static int[] t = new int[1501];
	public static int[] y =  new int[1501]; 
	public static int[] m = new int[1501];

	static int roadTime(int i,int j){
		if(done[i][j]==true) return memo[i][j];
		int res = 1111111;
		int moneyStock = 1000000000;
		if(i == 0){res = 0;}
		else{
			for(int k=0;k<v;k++){
				if(i == t[k] && c >= j+y[k]){
					if(res == roadTime(s[k],j+y[k])+m[k]){
						if(moneyStock > j+y[k]) res = roadTime(s[k],j+y[k])+m[k];
					}else if(res >roadTime(s[k],j+y[k])+m[k]){
						res = roadTime(s[k],j+y[k])+m[k];
						moneyStock = j+y[k];
					}
				}
			}
		}
		//System.out.println(i+" "+res);
		done[i][j] = true;
		memo[i][j] = res; 
		return res;
	}

	public static void main(String[] args){
		Scanner stdIn = new Scanner(System.in);
	
		n = stdIn.nextInt();
		c = stdIn.nextInt();
		v = stdIn.nextInt();

		for(int i=0;i<v;i++) s[i] = stdIn.nextInt()-1;
		for(int i=0;i<v;i++) t[i] = stdIn.nextInt()-1;
		for(int i=0;i<v;i++) y[i] = stdIn.nextInt();
		for(int i=0;i<v;i++) m[i] = stdIn.nextInt();


		int answer = roadTime(n-1,0);
		if(answer == 1111111) answer = -1;
		System.out.println(answer);
	}
}
0