結果
問題 | No.1948 足し算するだけのパズルゲーム(1) |
ユーザー | tenten |
提出日時 | 2022-07-27 23:26:40 |
言語 | Java21 (openjdk 21) |
結果 |
TLE
|
実行時間 | - |
コード長 | 3,867 bytes |
コンパイル時間 | 2,646 ms |
コンパイル使用メモリ | 79,208 KB |
実行使用メモリ | 63,672 KB |
最終ジャッジ日時 | 2024-07-17 12:57:50 |
合計ジャッジ時間 | 15,166 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 53 ms
37,224 KB |
testcase_01 | AC | 53 ms
37,300 KB |
testcase_02 | AC | 54 ms
37,284 KB |
testcase_03 | AC | 54 ms
37,344 KB |
testcase_04 | AC | 53 ms
37,428 KB |
testcase_05 | AC | 55 ms
37,236 KB |
testcase_06 | AC | 54 ms
37,164 KB |
testcase_07 | AC | 456 ms
52,164 KB |
testcase_08 | AC | 329 ms
48,484 KB |
testcase_09 | AC | 670 ms
58,584 KB |
testcase_10 | AC | 555 ms
58,428 KB |
testcase_11 | AC | 606 ms
58,504 KB |
testcase_12 | AC | 709 ms
53,480 KB |
testcase_13 | AC | 1,868 ms
63,672 KB |
testcase_14 | AC | 1,422 ms
58,836 KB |
testcase_15 | AC | 325 ms
48,988 KB |
testcase_16 | AC | 62 ms
37,052 KB |
testcase_17 | AC | 77 ms
37,820 KB |
testcase_18 | AC | 55 ms
37,108 KB |
testcase_19 | AC | 55 ms
37,416 KB |
testcase_20 | TLE | - |
testcase_21 | -- | - |
testcase_22 | -- | - |
testcase_23 | -- | - |
testcase_24 | -- | - |
testcase_25 | -- | - |
testcase_26 | -- | - |
ソースコード
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[][] field = new int[h][w]; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { field[i][j] = sc.nextInt(); } } PriorityQueue<Path> queue = new PriorityQueue<>(); queue.add(new Path(1, 0, 0, field[0][0])); queue.add(new Path(0, 1, 0, field[0][0])); long[][][] gains = new long[2][h][w]; while (queue.size() > 0) { Path p = queue.poll(); if (p.value <= field[p.r][p.c]) { if (p.count == 1) { continue; } if (p.r < h - 1) { queue.add(new Path(p.r + 1, p.c, 1, p.value)); } if (p.c < w - 1) { queue.add(new Path(p.r, p.c + 1, 1, p.value)); } } else { p.value += field[p.r][p.c]; if (gains[p.count][p.r][p.c] >= p.value) { continue; } gains[p.count][p.r][p.c] = p.value; if (p.r < h - 1) { queue.add(new Path(p.r + 1, p.c, p.count, p.value)); } if (p.c < w - 1) { queue.add(new Path(p.r, p.c + 1, p.count, p.value)); } } } if (gains[0][h - 1][w - 1] > 0 || gains[1][h - 1][w - 1] > 0) { System.out.println("Yes"); } else { System.out.println("No"); } } static class Path implements Comparable<Path> { int r; int c; int count; long value; public Path(int r, int c, int count, long value) { this.r = r; this.c = c; this.count = count; 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 BinaryIndexedTree { int size; int[] tree; public BinaryIndexedTree(int size) { this.size = size; tree = new int[size]; } public void clear() { Arrays.fill(tree, 0); } public void add(int idx, int value) { int mask = 1; while (idx < size) { if ((idx & mask) != 0) { tree[idx] += value; idx += mask; } mask <<= 1; } } public int getSum(int from, int to) { return getSum(to) - getSum(from - 1); } public int getSum(int x) { int mask = 1; int ans = 0; while (x > 0) { if ((x & mask) != 0) { ans += tree[x]; x -= mask; } mask <<= 1; } return ans; } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); 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 { if (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }