結果
| 問題 | No.496 ワープクリスタル (給料日前編) |
| コンテスト | |
| ユーザー |
tenten
|
| 提出日時 | 2020-12-10 11:33:53 |
| 言語 | Java (openjdk 23) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,808 bytes |
| 記録 | |
| コンパイル時間 | 2,406 ms |
| コンパイル使用メモリ | 78,644 KB |
| 実行使用メモリ | 59,536 KB |
| 最終ジャッジ日時 | 2024-09-19 19:15:15 |
| 合計ジャッジ時間 | 7,560 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 17 WA * 6 |
ソースコード
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int gx = sc.nextInt();
int gy = sc.nextInt();
int n = sc.nextInt();
int f = sc.nextInt();
int[] xArr = new int[n];
int[] yArr = new int[n];
int[] cArr = new int[n];
for (int i = 0; i < n; i++) {
xArr[i] = sc.nextInt();
yArr[i] = sc.nextInt();
cArr[i] = sc.nextInt();
}
int[][] costs = new int[gx + 1][gy + 1];
for (int[] arr : costs) {
Arrays.fill(arr, Integer.MAX_VALUE);
}
PriorityQueue<Path> queue = new PriorityQueue<>();
queue.add(new Path(0, 0, 0));
while (queue.size() > 0) {
Path p = queue.poll();
if (costs[p.x][p.y] <= p.value) {
continue;
}
costs[p.x][p.y] = p.value;
if (p.x < gx) {
queue.add(new Path(p.x + 1, p.y, p.value + f));
}
if (p.y < gy) {
queue.add(new Path(p.x, p.y + 1, p.value + f));
}
for (int i = 0; i < n; i++) {
if (p.x + xArr[i] <= gx && p.y + yArr[i] <= gy) {
queue.add(new Path(p.x + xArr[i], p.y + yArr[i], p.value + cArr[i]));
}
}
}
System.out.println(costs[gx][gy]);
}
static class Path implements Comparable<Path> {
int x;
int y;
int value;
public Path(int x, int y, int value) {
this.x = x;
this.y = y;
this.value = value;
}
public int compareTo(Path another) {
return value - another.value;
}
}
}
tenten