結果
| 問題 |
No.1037 exhausted
|
| コンテスト | |
| ユーザー |
htensai
|
| 提出日時 | 2020-04-30 08:46:47 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 1,998 ms / 2,000 ms |
| コード長 | 2,209 bytes |
| コンパイル時間 | 2,515 ms |
| コンパイル使用メモリ | 79,580 KB |
| 実行使用メモリ | 292,592 KB |
| 最終ジャッジ日時 | 2024-12-14 12:30:09 |
| 合計ジャッジ時間 | 20,985 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 23 |
ソースコード
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int v = sc.nextInt();
int l = sc.nextInt();
GS[] stations = new GS[n + 2];
for (int i = 1; i <= n; i++) {
stations[i] = new GS(sc.nextInt(), sc.nextInt(), sc.nextInt());
}
stations[0] = new GS(0, 0, 0);
stations[n + 1] = new GS(l, 0, 0);
ArrayList<HashMap<Integer, Long>> dp = new ArrayList<>();
for (int i = 0; i <= n + 1; i++) {
dp.add(new HashMap<>());
}
dp.get(0).put(v, 0L);
for (int i = 1; i <= n + 1; i++) {
int length = stations[i].point - stations[i - 1].point;
HashMap<Integer, Long> map = dp.get(i);
for (Map.Entry<Integer, Long> entry : dp.get(i - 1).entrySet()) {
int gas = entry.getKey() - length;
if (gas < 0) {
continue;
}
if (map.containsKey(gas)) {
if (map.get(gas) > entry.getValue()) {
map.put(gas, entry.getValue());
}
} else {
map.put(gas, entry.getValue());
}
long cost = entry.getValue() + stations[i].cost;
gas = Math.min(v, gas + stations[i].gas);
if (map.containsKey(gas)) {
if (map.get(gas) > cost) {
map.put(gas, cost);
}
} else {
map.put(gas, cost);
}
}
}
if (dp.get(n + 1).size() == 0) {
System.out.println(-1);
return;
}
long min = Long.MAX_VALUE;
for (long x : dp.get(n + 1).values()) {
min = Math.min(x, min);
}
System.out.println(min);
}
static class GS {
int point;
int gas;
int cost;
public GS(int point, int gas, int cost) {
this.point = point;
this.gas = gas;
this.cost = cost;
}
}
}
htensai