結果
| 問題 |
No.1 道のショートカット
|
| コンテスト | |
| ユーザー |
spacia
|
| 提出日時 | 2016-01-02 07:18:10 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 539 ms / 5,000 ms |
| コード長 | 1,747 bytes |
| コンパイル時間 | 2,825 ms |
| コンパイル使用メモリ | 79,916 KB |
| 実行使用メモリ | 61,656 KB |
| 最終ジャッジ日時 | 2024-07-20 16:19:04 |
| 合計ジャッジ時間 | 8,461 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 40 |
ソースコード
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);
}
}
spacia