結果

問題 No.1 道のショートカット
ユーザー spaciaspacia
提出日時 2016-01-02 07:18:10
言語 Java21
(openjdk 21)
結果
AC  
実行時間 373 ms / 5,000 ms
コード長 1,747 bytes
コンパイル時間 2,332 ms
コンパイル使用メモリ 75,496 KB
実行使用メモリ 58,824 KB
最終ジャッジ日時 2023-09-27 21:50:40
合計ジャッジ時間 9,010 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
49,360 KB
testcase_01 AC 42 ms
49,288 KB
testcase_02 AC 40 ms
49,244 KB
testcase_03 AC 42 ms
49,356 KB
testcase_04 AC 74 ms
53,528 KB
testcase_05 AC 41 ms
49,436 KB
testcase_06 AC 41 ms
49,188 KB
testcase_07 AC 43 ms
49,232 KB
testcase_08 AC 88 ms
53,372 KB
testcase_09 AC 109 ms
54,016 KB
testcase_10 AC 157 ms
56,776 KB
testcase_11 AC 153 ms
57,380 KB
testcase_12 AC 127 ms
52,044 KB
testcase_13 AC 151 ms
57,108 KB
testcase_14 AC 82 ms
53,532 KB
testcase_15 AC 44 ms
49,296 KB
testcase_16 AC 87 ms
53,640 KB
testcase_17 AC 40 ms
49,800 KB
testcase_18 AC 75 ms
50,996 KB
testcase_19 AC 84 ms
52,628 KB
testcase_20 AC 98 ms
53,728 KB
testcase_21 AC 87 ms
52,272 KB
testcase_22 AC 84 ms
50,916 KB
testcase_23 AC 373 ms
58,824 KB
testcase_24 AC 199 ms
58,512 KB
testcase_25 AC 100 ms
54,020 KB
testcase_26 AC 99 ms
54,260 KB
testcase_27 AC 158 ms
57,908 KB
testcase_28 AC 42 ms
49,480 KB
testcase_29 AC 154 ms
56,428 KB
testcase_30 AC 99 ms
53,348 KB
testcase_31 AC 164 ms
58,240 KB
testcase_32 AC 126 ms
54,516 KB
testcase_33 AC 104 ms
54,488 KB
testcase_34 AC 147 ms
56,796 KB
testcase_35 AC 117 ms
56,764 KB
testcase_36 AC 127 ms
52,212 KB
testcase_37 AC 115 ms
53,696 KB
testcase_38 AC 77 ms
52,572 KB
testcase_39 AC 86 ms
51,284 KB
testcase_40 AC 84 ms
53,616 KB
testcase_41 AC 87 ms
53,768 KB
testcase_42 AC 42 ms
49,168 KB
testcase_43 AC 43 ms
49,300 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

class Main1 {
	
	static int n , c;
	static int ans = -1;
	static String[][][] 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] == null) continue;
			String[] costs = memo[nowPoint][i][0].split(",");
			String[] times = memo[nowPoint][i][1].split(",");
			for (int j = 0; j < costs.length; j++) {
				int c0 = Integer.parseInt(costs[j]);
				int t0 = Integer.parseInt(times[j]);
				if (c0 + cost > c || (ans != -1 && ans < t0 + time)) continue;
				if (n != i) {
					solve(i , c0 + cost , t0 + time);
				} else {
					//out(ans);
					ans = ans == -1 ? t0 + time : Math.min(ans , t0 + time);
				}
			}
		}
	}
	
	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 String[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] = memo[s][t][0] == null ? String.valueOf(y) : memo[s][t][0] + "," + String.valueOf(y);
			memo[s][t][1] = memo[s][t][1] == null ? String.valueOf(m) : memo[s][t][1] + "," + String.valueOf(m);
		}
		
		solve(1,0,0);
		
		out(ans);
		
	}
}
0