結果
問題 | No.2366 登校 |
ユーザー | tenten |
提出日時 | 2023-07-04 15:50:35 |
言語 | Java21 (openjdk 21) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,604 bytes |
コンパイル時間 | 2,764 ms |
コンパイル使用メモリ | 84,824 KB |
実行使用メモリ | 736,244 KB |
最終ジャッジ日時 | 2024-07-18 11:18:43 |
合計ジャッジ時間 | 28,639 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | WA | - |
testcase_01 | WA | - |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | MLE | - |
testcase_24 | MLE | - |
testcase_25 | MLE | - |
testcase_26 | MLE | - |
ソースコード
import java.io.*; import java.util.*; import java.util.stream.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int h = sc.nextInt(); int w = sc.nextInt(); int k = sc.nextInt(); int t = Math.min(sc.nextInt(), h * w - 1); int[][] times = new int[h][w]; int[][] values = new int[h][w]; for (int i = 0; i < k; i++) { int r = sc.nextInt() - 1; int c = sc.nextInt() - 1; int a = sc.nextInt(); int b = sc.nextInt(); times[r][c] = a - 1; values[r][c] = b; } long[][][] costs = new long[h][w][h * w * 2]; for (long[][] arr1 : costs) { for (long[] arr2 : arr1) { Arrays.fill(arr2, Long.MAX_VALUE); } } PriorityQueue<Path> queue = new PriorityQueue<>(); queue.add(new Path(0, 0, h * w, 0)); while (queue.size() > 0) { Path p = queue.poll(); if (costs[p.r][p.c][p.time] <= p.value) { continue; } costs[p.r][p.c][p.time] = p.value; if (p.r < h - 1) { queue.add(new Path(p.r + 1, p.c, p.time + 1, p.value)); } if (p.c < w - 1) { queue.add(new Path(p.r, p.c + 1, p.time + 1, p.value)); } queue.add(new Path(p.r, p.c, Math.max(0, p.time - times[p.r][p.c]), p.value + values[p.r][p.c])); } long ans = Long.MAX_VALUE; for (int i = h * w + t; i >= 0; i--) { ans = Math.min(ans, costs[h - 1][w - 1][i]); } System.out.println(Arrays.toString(costs[h - 1][w - 1])); System.out.println(ans); } static class Path implements Comparable<Path> { int r; int c; int time; long value; public Path(int r, int c, int time, long value) { this.r = r; this.c = c; this.time = time; this.value = value; } public int compareTo(Path another) { if (value == another.value) { return 0; } else if (value < another.value) { return - 1; } else { return 1; } } } } class Utilities { static String arrayToLineString(Object[] arr) { return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n")); } static String arrayToLineString(int[] arr) { return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new)); } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); StringBuilder sb = new StringBuilder(); public Scanner() throws Exception { } public int nextInt() throws Exception { return Integer.parseInt(next()); } public long nextLong() throws Exception { return Long.parseLong(next()); } public double nextDouble() throws Exception { return Double.parseDouble(next()); } public int[] nextIntArray() throws Exception { return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray(); } public String next() throws Exception { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }