結果

問題 No.1 道のショートカット
ユーザー spaciaspacia
提出日時 2016-01-02 01:24:05
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 1,696 bytes
コンパイル時間 2,076 ms
コンパイル使用メモリ 75,428 KB
実行使用メモリ 63,316 KB
最終ジャッジ日時 2023-09-22 12:36:40
合計ジャッジ時間 9,977 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
49,332 KB
testcase_01 AC 42 ms
49,712 KB
testcase_02 AC 41 ms
47,300 KB
testcase_03 AC 42 ms
49,284 KB
testcase_04 AC 88 ms
52,108 KB
testcase_05 AC 41 ms
49,456 KB
testcase_06 AC 42 ms
49,336 KB
testcase_07 AC 42 ms
47,224 KB
testcase_08 AC 100 ms
55,752 KB
testcase_09 AC 142 ms
55,012 KB
testcase_10 AC 306 ms
59,980 KB
testcase_11 TLE -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
権限があれば一括ダウンロードができます

ソースコード

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) continue;
				if (n != i) {
					solve(i , c0 + cost , t0 + time);
				} else {
					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