結果

問題 No.1949 足し算するだけのパズルゲーム(2)
ユーザー ygd.ygd.
提出日時 2022-05-24 00:02:01
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,938 bytes
コンパイル時間 162 ms
コンパイル使用メモリ 81,832 KB
実行使用メモリ 77,308 KB
最終ジャッジ日時 2023-10-20 17:49:31
合計ジャッジ時間 2,738 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 39 ms
53,540 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 38 ms
53,540 KB
testcase_05 WA -
testcase_06 AC 39 ms
53,540 KB
testcase_07 WA -
testcase_08 AC 72 ms
76,592 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 63 ms
76,944 KB
testcase_14 AC 68 ms
76,732 KB
testcase_15 AC 68 ms
76,732 KB
testcase_16 AC 65 ms
76,920 KB
testcase_17 WA -
testcase_18 AC 65 ms
76,896 KB
testcase_19 AC 38 ms
53,540 KB
testcase_20 WA -
testcase_21 AC 39 ms
53,540 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 62 ms
76,944 KB
testcase_25 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
#input = sys.stdin.readline
input = sys.stdin.buffer.readline #文字列はダメ
#sys.setrecursionlimit(1000000)
#import bisect
#import itertools
#import random
from heapq import heapify, heappop, heappush
#from collections import defaultdict 
#from collections import deque
#import copy
#import math
#from functools import lru_cache
#@lru_cache(maxsize=None)
#MOD = pow(10,9) + 7
#MOD = 998244353
dx = [1,0,-1,0]
dy = [0,1,0,-1]
#dx8 = [1,1,0,-1,-1,-1,0,1]
#dy8 = [0,1,1,1,0,-1,-1,-1]

base = 505

def main():
    H,W,Y,X = map(int,input().split()); INF = pow(10,18)
    X -= 1; Y -= 1
    A = [list(map(int,input().split())) for _ in range(H)]

    PQ = []
    heappush(PQ,(0,Y*base+X))
    ok = [[0]*W for _ in range(H)]
    power = A[Y][X]
    while PQ:
        dummy,idx = heappop(PQ)
        y = idx//base
        x = idx%base
        #print(x,y,A[y][x],"P",power)
        if ok[y][x] == 1: continue
        if power <= A[y][x]: continue
        power += A[y][x]
        ok[y][x] = 1
        for d in range(4):
            ny = y + dy[d]
            nx = x + dx[d]
            if ny < 0 or ny >= H or nx < 0 or nx >= W: continue
            if ok[ny][nx] == 1: continue #既に倒している。
            if A[ny][nx] < power:
                power += A[ny][nx]
                ok[ny][nx] = 1
                for dd in range(4):
                    nny = ny + dy[dd]
                    nnx = nx + dx[dd]
                    if nny < 0 or nny >= H or nnx < 0 or nnx >= W: continue
                    if ok[nny][nnx] == 1: continue #既に倒している。
                    heappush(PQ, (A[nny][nnx],nny*base + nnx))
            else:
                heappush(PQ, (A[ny][nx], ny*base + nx))
    #print(power)
    #print(ok)
    for i in range(H):
        for j in range(W):
            if ok[i][j] == 0:
                print('No')
                exit()
    print('Yes')



if __name__ == '__main__':
    main()
0