結果
問題 | No.1949 足し算するだけのパズルゲーム(2) |
ユーザー |
![]() |
提出日時 | 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 |
ソースコード
import heapqdef main():import sysinput = sys.stdin.readdata = input().split()idx = 0H = int(data[idx])W = int(data[idx+1])Y = int(data[idx+2]) - 1 # converting to 0-based indexX = int(data[idx+3]) - 1idx +=4A = []for i in range(H):row = list(map(int, data[idx:idx+W]))A.append(row)idx += Wcurrent_power = A[Y][X]visited = [[False for _ in range(W)] for _ in range(H)]visited[Y][X] = Trueremaining = H * W - 1 # exclude starting positionheap = []# Check initial position's neighborsdirections = [(-1, 0), (1, 0), (0, -1), (0, 1)]for dy, dx in directions:ny = Y + dynx = X + dxif 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")returnattack, y, x = heapq.heappop(heap)if visited[y][x]:continueif attack > current_power:print("No")returncurrent_power += attackvisited[y][x] = Trueremaining -= 1# Check neighbors of the current cellfor dy, dx in directions:ny = y + dynx = x + dxif 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()