結果
問題 |
No.2855 Move on Grid
|
ユーザー |
![]() |
提出日時 | 2024-08-26 18:03:06 |
言語 | Java (openjdk 23) |
結果 |
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 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 13 WA * 7 TLE * 1 -- * 19 |
ソースコード
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(); } } }