結果
| 問題 |
No.2855 Move on Grid
|
| コンテスト | |
| ユーザー |
tenten
|
| 提出日時 | 2024-08-26 17:45:46 |
| 言語 | Java (openjdk 23) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 2,854 bytes |
| コンパイル時間 | 2,549 ms |
| コンパイル使用メモリ | 79,724 KB |
| 実行使用メモリ | 146,560 KB |
| 最終ジャッジ日時 | 2024-08-26 17:45:57 |
| 合計ジャッジ時間 | 11,835 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | TLE * 1 -- * 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) {
deq.add(new Path(p.r - 1, p.c, p.value));
}
if (p.r < h - 1) {
deq.add(new Path(p.r + 1, p.c, p.value));
}
if (p.c > 0) {
deq.add(new Path(p.r, p.c - 1, p.value));
}
if (p.c < w - 1) {
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();
}
}
}
tenten