結果

問題 No.1949 足し算するだけのパズルゲーム(2)
ユーザー siganai
提出日時 2022-05-20 23:06:09
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,065 ms / 3,000 ms
コード長 809 bytes
コンパイル時間 515 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 99,512 KB
最終ジャッジ日時 2024-09-20 09:29:56
合計ジャッジ時間 9,712 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env PyPy3

from collections import Counter, defaultdict, deque
import itertools
import re
import math
from functools import reduce
import operator
import bisect
from heapq import *
import functools
mod=998244353

import sys
input=sys.stdin.readline
h,w,y,x=map(int,input().split())
a=[list(map(int,input().split())) for _ in range(h)]
now = a[y-1][x-1]
heap = []
dx = [1,-1,0,0]
dy = [0,0,1,-1]
a[y-1][x-1] = -1
py,px=y-1,x-1
cnt = 1
while cnt < h * w:
    for i in range(4):
        ny,nx=dy[i]+py,dx[i]+px
        if 0 <= ny < h and 0 <= nx < w:
            if a[ny][nx] != -1:
                heappush(heap,[a[ny][nx],ny,nx])
                a[ny][nx] = -1
    mi,py,px = heappop(heap)
    if now > mi:
        now += mi
        cnt += 1
    else:
        print('No')
        exit()
print('Yes')
0