結果
問題 | No.2855 Move on Grid |
ユーザー | tenten |
提出日時 | 2024-08-26 18:03:06 |
言語 | Java21 (openjdk 21) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,034 bytes |
コンパイル時間 | 2,506 ms |
コンパイル使用メモリ | 79,644 KB |
実行使用メモリ | 66,844 KB |
最終ジャッジ日時 | 2024-08-26 18:03:57 |
合計ジャッジ時間 | 46,435 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | WA | - |
testcase_01 | WA | - |
testcase_02 | AC | 888 ms
60,432 KB |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | AC | 200 ms
57,032 KB |
testcase_08 | WA | - |
testcase_09 | AC | 380 ms
57,228 KB |
testcase_10 | AC | 2,668 ms
66,588 KB |
testcase_11 | AC | 2,640 ms
66,600 KB |
testcase_12 | AC | 2,649 ms
66,492 KB |
testcase_13 | AC | 2,761 ms
66,844 KB |
testcase_14 | AC | 2,571 ms
66,388 KB |
testcase_15 | AC | 2,580 ms
66,728 KB |
testcase_16 | AC | 2,630 ms
66,312 KB |
testcase_17 | AC | 2,693 ms
66,800 KB |
testcase_18 | AC | 2,615 ms
66,584 KB |
testcase_19 | AC | 2,677 ms
66,764 KB |
testcase_20 | TLE | - |
testcase_21 | -- | - |
testcase_22 | -- | - |
testcase_23 | -- | - |
testcase_24 | -- | - |
testcase_25 | -- | - |
testcase_26 | -- | - |
testcase_27 | -- | - |
testcase_28 | -- | - |
testcase_29 | -- | - |
testcase_30 | -- | - |
testcase_31 | -- | - |
testcase_32 | -- | - |
testcase_33 | -- | - |
testcase_34 | -- | - |
testcase_35 | -- | - |
testcase_36 | -- | - |
testcase_37 | -- | - |
testcase_38 | -- | - |
testcase_39 | -- | - |
ソースコード
import java.io.*; import java.util.*; import java.util.function.*; 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[][] field = new int[h][w]; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { field[i][j] = sc.nextInt(); } } int left = 0; int right = 1000000001; Deque<Path> deq = new ArrayDeque<>(); while (right - left > 1) { int m = (left + right) / 2; deq.add(new Path(0, 0, 0)); int[][] counts = new int[h][w]; for (int[] arr : counts) { Arrays.fill(arr, Integer.MAX_VALUE); } while (deq.size() > 0) { Path p = deq.poll(); if (field[p.r][p.c] < m) { p.value++; } if (counts[p.r][p.c] <= p.value) { continue; } counts[p.r][p.c] = p.value; if (p.r > 0 && counts[p.r - 1][p.c] == Integer.MAX_VALUE) { deq.add(new Path(p.r - 1, p.c, p.value)); } if (p.r < h - 1 && counts[p.r + 1][p.c] == Integer.MAX_VALUE) { deq.add(new Path(p.r + 1, p.c, p.value)); } if (p.c > 0 && counts[p.r][p.c - 1] == Integer.MAX_VALUE) { deq.add(new Path(p.r, p.c - 1, p.value)); } if (p.c < w - 1 && counts[p.r][p.c + 1] == Integer.MAX_VALUE) { deq.add(new Path(p.r, p.c + 1, p.value)); } } if (counts[h - 1][w - 1] <= k) { left = m; } else { right = m; } } System.out.println(left); } static class Path { int r; int c; int value; public Path(int r, int c, int value) { this.r = r; this.c = c; this.value = value; } } } class Scanner { BufferedReader br; StringTokenizer st = new StringTokenizer(""); public Scanner() { try { br = new BufferedReader(new InputStreamReader(System.in)); } catch (Exception e) { } } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } public double nextDouble() { return Double.parseDouble(next()); } public String next() { try { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } } catch (Exception e) { e.printStackTrace(); } finally { return st.nextToken(); } } }