結果
| 問題 |
No.1 道のショートカット
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2014-10-01 18:28:10 |
| 言語 | Java (openjdk 23) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 3,484 bytes |
| コンパイル時間 | 3,390 ms |
| コンパイル使用メモリ | 86,996 KB |
| 実行使用メモリ | 59,316 KB |
| 最終ジャッジ日時 | 2024-07-08 03:31:05 |
| 合計ジャッジ時間 | 11,988 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 WA * 2 |
| other | AC * 8 WA * 32 |
ソースコード
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Random;
import java.util.Scanner;
public class Yuki001 {
private static boolean isDebug = false;
public static void main(String[] args) {
ArrayList<Integer> si = new ArrayList<Integer>();
ArrayList<Integer> ti = new ArrayList<Integer>();
ArrayList<Integer> ci = new ArrayList<Integer>();
ArrayList<Integer> tis = new ArrayList<Integer>();
Scanner scanner = new Scanner(System.in);
int N = 10;
int C = 20;
if (isDebug) {
} else {
N = scanner.nextInt();
C = scanner.nextInt();
}
int[][] cost = new int[N + 1][N + 1];
int[][] time = new int[N + 1][N + 1];
if (isDebug) {
Random random = new Random();
random.setSeed(1);
for (int i = 2; i < N + 1; i++) {
for (int j = 1; j < i; j++) {
int k = random.nextInt(C);
if (k > 5) {
cost[i][j] = k;
time[i][j] = random.nextInt(10) + 1;
ti.add(i);
si.add(j);
ci.add(k);
tis.add(time[i][j]);
}
}
}
} else {
int V = scanner.nextInt();
for (int i = 0; i < V; i++) {
si.add(scanner.nextInt());
}
for (int i = 0; i < V; i++) {
ti.add(scanner.nextInt());
}
for (int i = 0; i < V; i++) {
ci.add(scanner.nextInt());
cost[ti.get(i)][si.get(i)] = ci.get(i);
}
for (int i = 0; i < V; i++) {
tis.add(scanner.nextInt());
time[ti.get(i)][si.get(i)] = tis.get(i);
}
}
int MAX = Integer.MAX_VALUE / 2;
int[][] dp = new int[N + 1][C + 1];
for (int i = 0; i < dp.length; i++) {
Arrays.fill(dp[i], MAX);
}
dp[1][C] = 0;
for (int i = 2; i < N + 1; i++) {
for (int k = 1; k < i; k++) {
if (cost[i][k] == 0) {
break;
}
for (int t = 0; t <= C; t++) {
if (dp[k][t] >= MAX) {
continue;
}
int c = t - cost[i][k];
if (c < 0) {
continue;
}
dp[i][c] = Math.min(dp[i][c], dp[k][t] + time[i][k]);
}
}
}
boolean isCheck = false;
for (int i = C; i >= 0; i--) {
if (dp[N][i] != MAX) {
System.out.println(dp[N][i]);
isCheck = true;
break;
}
}
if (!isCheck) {
System.out.println(-1);
}
System.out.flush();
if (isDebug) {
System.err.println(N);
System.err.println(C);
System.err.println(si.size());
System.err.println(wrap(si));
System.err.println(wrap(ti));
System.err.println(wrap(ci));
System.err.println(wrap(tis));
}
}
static String wrap(ArrayList<? extends Object> list) {
return list.toString().replace("[", "").replace("]", "").replace(",", "");
}
}