結果

問題 No.1 道のショートカット
ユーザー spacia
提出日時 2016-01-01 22:26:08
言語 Java
(openjdk 23)
結果
WA  
実行時間 -
コード長 1,370 bytes
コンパイル時間 2,379 ms
コンパイル使用メモリ 77,680 KB
実行使用メモリ 53,824 KB
最終ジャッジ日時 2024-07-08 04:19:25
合計ジャッジ時間 6,890 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3 WA * 1
other AC * 16 WA * 24
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;

class Main1 {
	
	static int n , c;
	static int ans = -1;
	static int[][][] memo;
	
	public static void out (Object o) {
		System.out.println(o);
	}
	
	public static void solve (int nowPoint , int cost , int time) {
		for (int i = nowPoint + 1; i <= n; i++) {
			if (memo[nowPoint][i][0] == 0) continue;
			if (cost + memo[nowPoint][i][0] > c) continue;
			if (i != n) {
				solve(i , cost + memo[nowPoint][i][0] , time + memo[nowPoint][i][1]);
			} else {
				ans = ans == -1 ? time + memo[nowPoint][i][1] : Math.min(ans , time + memo[nowPoint][i][1]);
			}
		}
	}
	
	public static void main (String[] args) throws IOException {
		BufferedReader br = 
			new BufferedReader(new InputStreamReader(System.in));
		
		n = Integer.parseInt(br.readLine());
		c = Integer.parseInt(br.readLine());
		int v = Integer.parseInt(br.readLine());
		String[] line1 = br.readLine().split(" ");
		String[] line2 = br.readLine().split(" ");
		String[] line3 = br.readLine().split(" ");
		String[] line4 = br.readLine().split(" ");
		
		memo = new int[n + 1][n + 1][2];
		
		for (int i = 0; i < v; i++) {
			int s = Integer.parseInt(line1[i]);
			int t = Integer.parseInt(line2[i]);
			int y = Integer.parseInt(line3[i]);
			int m = Integer.parseInt(line4[i]);
			memo[s][t][0] = y;
			memo[s][t][1] = m;
		}
		
		solve(1,0,0);
		
		out(ans);
		
	}
}
0