結果

問題 No.1949 足し算するだけのパズルゲーム(2)
ユーザー ygd.ygd.
提出日時 2022-05-23 23:58:34
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,865 bytes
コンパイル時間 165 ms
コンパイル使用メモリ 81,720 KB
実行使用メモリ 82,456 KB
最終ジャッジ日時 2023-10-20 17:49:14
合計ジャッジ時間 5,113 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 36 ms
53,456 KB
testcase_02 AC 39 ms
53,456 KB
testcase_03 AC 38 ms
53,456 KB
testcase_04 WA -
testcase_05 AC 39 ms
53,456 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 238 ms
80,352 KB
testcase_10 WA -
testcase_11 AC 269 ms
80,848 KB
testcase_12 AC 272 ms
81,108 KB
testcase_13 AC 70 ms
77,508 KB
testcase_14 AC 283 ms
82,456 KB
testcase_15 AC 292 ms
82,456 KB
testcase_16 AC 60 ms
76,912 KB
testcase_17 WA -
testcase_18 AC 63 ms
76,912 KB
testcase_19 AC 38 ms
53,456 KB
testcase_20 WA -
testcase_21 AC 37 ms
53,456 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 195 ms
80,548 KB
testcase_25 AC 244 ms
80,724 KB
権限があれば一括ダウンロードができます

ソースコード

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,Y*base+X)
    ok = [[0]*W for _ in range(H)]
    power = A[Y][X]
    while PQ:
        idx = heappop(PQ)
        y = idx//base
        x = idx%base
        #print(x,y,A[y][x])
        if ok[y][x] == 1: continue
        if power < A[y][x]: continue
        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, nny*base + nnx)
            else:
                heappush(PQ, 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