結果

問題 No.1949 足し算するだけのパズルゲーム(2)
ユーザー lam6er
提出日時 2025-03-26 15:47:33
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,554 bytes
コンパイル時間 297 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 137,756 KB
最終ジャッジ日時 2025-03-26 15:48:54
合計ジャッジ時間 18,221 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 22 WA * 4
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

import heapq
def main():
import sys
input = sys.stdin.read
data = input().split()
idx = 0
H = int(data[idx])
W = int(data[idx+1])
Y = int(data[idx+2]) - 1 # converting to 0-based index
X = int(data[idx+3]) - 1
idx +=4
A = []
for i in range(H):
row = list(map(int, data[idx:idx+W]))
A.append(row)
idx += W
current_power = A[Y][X]
visited = [[False for _ in range(W)] for _ in range(H)]
visited[Y][X] = True
remaining = H * W - 1 # exclude starting position
heap = []
# Check initial position's neighbors
directions = [(-1, 0), (1, 0), (0, -1), (0, 1)]
for dy, dx in directions:
ny = Y + dy
nx = X + dx
if 0 <= ny < H and 0 <= nx < W and not visited[ny][nx]:
heapq.heappush(heap, (A[ny][nx], ny, nx))
while remaining > 0:
if not heap:
print("No")
return
attack, y, x = heapq.heappop(heap)
if visited[y][x]:
continue
if attack > current_power:
print("No")
return
current_power += attack
visited[y][x] = True
remaining -= 1
# Check neighbors of the current cell
for dy, dx in directions:
ny = y + dy
nx = x + dx
if 0 <= ny < H and 0 <= nx < W and not visited[ny][nx]:
heapq.heappush(heap, (A[ny][nx], ny, nx))
print("Yes")
if __name__ == "__main__":
main()
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0