結果
問題 | No.1949 足し算するだけのパズルゲーム(2) |
ユーザー | tenten |
提出日時 | 2022-09-27 10:47:13 |
言語 | Java21 (openjdk 21) |
結果 |
RE
|
実行時間 | - |
コード長 | 3,297 bytes |
コンパイル時間 | 2,315 ms |
コンパイル使用メモリ | 75,240 KB |
実行使用メモリ | 65,860 KB |
最終ジャッジ日時 | 2023-08-24 03:43:03 |
合計ジャッジ時間 | 11,380 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 46 ms
49,420 KB |
testcase_01 | AC | 45 ms
49,468 KB |
testcase_02 | AC | 46 ms
49,408 KB |
testcase_03 | AC | 47 ms
49,480 KB |
testcase_04 | RE | - |
testcase_05 | AC | 45 ms
49,468 KB |
testcase_06 | AC | 45 ms
49,676 KB |
testcase_07 | AC | 484 ms
65,860 KB |
testcase_08 | AC | 312 ms
57,828 KB |
testcase_09 | AC | 392 ms
61,536 KB |
testcase_10 | WA | - |
testcase_11 | AC | 411 ms
61,856 KB |
testcase_12 | AC | 377 ms
61,836 KB |
testcase_13 | RE | - |
testcase_14 | AC | 381 ms
61,684 KB |
testcase_15 | AC | 386 ms
61,660 KB |
testcase_16 | AC | 206 ms
56,348 KB |
testcase_17 | AC | 447 ms
65,376 KB |
testcase_18 | AC | 207 ms
57,052 KB |
testcase_19 | AC | 48 ms
49,504 KB |
testcase_20 | AC | 48 ms
49,516 KB |
testcase_21 | AC | 48 ms
49,468 KB |
testcase_22 | AC | 361 ms
61,368 KB |
testcase_23 | AC | 48 ms
49,828 KB |
testcase_24 | AC | 258 ms
57,836 KB |
testcase_25 | AC | 420 ms
58,952 KB |
ソースコード
import java.io.*; import java.util.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int h = sc.nextInt(); int w = sc.nextInt(); int x = sc.nextInt() - 1; int y = sc.nextInt() - 1; 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(); } } boolean[][] visited = new boolean[h][w]; visited[x][y] = true; long current = field[x][y]; PriorityQueue<Path> queue = new PriorityQueue<>(); if (x > 0) { queue.add(new Path(x - 1, y, field[x - 1][y])); visited[x - 1][y] = true; } if (x < h - 1) { queue.add(new Path(x + 1, y, field[x + 1][y])); visited[x + 1][y] = true; } if (y > 0) { queue.add(new Path(x, y - 1, field[x][y - 1])); visited[x][y - 1] = true; } if (x < h - 1) { queue.add(new Path(x, y + 1, field[x][y + 1])); visited[x][y + 1] = true; } while (queue.size() > 0) { Path p = queue.poll(); if (current <= p.value) { System.out.println("No"); return; } current += p.value; if (p.r > 0 && !visited[p.r - 1][p.c]) { queue.add(new Path(p.r - 1, p.c, field[p.r - 1][p.c])); visited[p.r - 1][p.c] = true; } if (p.r < h - 1 && !visited[p.r + 1][p.c]) { queue.add(new Path(p.r + 1, p.c, field[p.r + 1][p.c])); visited[p.r + 1][p.c] = true; } if (p.c > 0 && !visited[p.r][p.c - 1]) { queue.add(new Path(p.r, p.c - 1, field[p.r][p.c - 1])); visited[p.r][p.c - 1] = true; } if (p.c < w - 1 && !visited[p.r][p.c + 1]) { queue.add(new Path(p.r, p.c + 1, field[p.r][p.c + 1])); visited[p.r][p.c + 1] = true; } } System.out.println("Yes"); } static class Path implements Comparable<Path> { int r; int c; int value; public Path(int r, int c, int value) { this.r = r; this.c = c; this.value = value; } public int compareTo(Path another) { return value - another.value; } } } 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 String next() throws Exception { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }