結果

問題 No.1949 足し算するだけのパズルゲーム(2)
コンテスト
ユーザー flippergo
提出日時 2026-03-31 13:27:15
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 644 ms / 3,000 ms
コード長 825 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 984 ms
コンパイル使用メモリ 85,376 KB
実行使用メモリ 104,424 KB
最終ジャッジ日時 2026-03-31 13:27:48
合計ジャッジ時間 4,813 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge2_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import heapq
H,W,y,x = map(int,input().split())
y -= 1
x -= 1
A = [list(map(int,input().split())) for _ in range(H)]
amax = 0
for i in range(H):
    amax = max(amax,max(A[i]))
tot = A[y][x]
B = [[0 for _ in range(W)] for _ in range(H)]
B[y][x] = 1
heap = []
for dy,dx in [[-1,0],[1,0],[0,-1],[0,1]]:
    ny = y + dy
    nx = x + dx
    if 0 <= ny < H and 0 <= nx < W and B[ny][nx] ==0:
        B[ny][nx] = 1
        heapq.heappush(heap,(A[ny][nx],ny,nx))
ans = "No"
while heap:
    a,i,j = heapq.heappop(heap)
    if tot<=a:break
    tot += a
    for di,dj in [[-1,0],[1,0],[0,-1],[0,1]]:
        ni = i + di
        nj = j + dj
        if 0 <= ni < H and 0 <= nj < W and B[ni][nj] ==0:
            B[ni][nj] = 1
            heapq.heappush(heap,(A[ni][nj],ni,nj))
    if tot>amax:
        ans = "Yes"
        break
print(ans)
0