結果

問題 No.1948 足し算するだけのパズルゲーム(1)
ユーザー ikomaikoma
提出日時 2022-05-20 23:34:42
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 138 ms / 2,000 ms
コード長 1,152 bytes
コンパイル時間 729 ms
コンパイル使用メモリ 81,720 KB
実行使用メモリ 82,832 KB
最終ジャッジ日時 2023-10-20 14:30:44
合計ジャッジ時間 4,365 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
53,464 KB
testcase_01 AC 37 ms
53,464 KB
testcase_02 AC 36 ms
53,464 KB
testcase_03 AC 36 ms
53,464 KB
testcase_04 AC 37 ms
53,464 KB
testcase_05 AC 38 ms
53,464 KB
testcase_06 AC 37 ms
53,464 KB
testcase_07 AC 109 ms
78,200 KB
testcase_08 AC 113 ms
81,940 KB
testcase_09 AC 121 ms
82,020 KB
testcase_10 AC 100 ms
81,976 KB
testcase_11 AC 125 ms
82,604 KB
testcase_12 AC 123 ms
82,192 KB
testcase_13 AC 128 ms
82,180 KB
testcase_14 AC 138 ms
82,832 KB
testcase_15 AC 123 ms
82,228 KB
testcase_16 AC 42 ms
55,512 KB
testcase_17 AC 44 ms
55,512 KB
testcase_18 AC 38 ms
53,464 KB
testcase_19 AC 39 ms
53,464 KB
testcase_20 AC 123 ms
82,084 KB
testcase_21 AC 124 ms
82,060 KB
testcase_22 AC 96 ms
77,492 KB
testcase_23 AC 108 ms
78,100 KB
testcase_24 AC 92 ms
77,528 KB
testcase_25 AC 112 ms
81,972 KB
testcase_26 AC 123 ms
82,176 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline


H,W=map(int,input().split())
A=[list(map(int,input().split())) for _ in range(H)]
INF=float("inf")
dp = [[0]*W for _ in range(H)]
dp2 = [[0]*W for _ in range(H)]
dp[0][0]=A[0][0]
for h in range(H):
    for w in range(W):
        if h==0 and w==0: continue
        if h==0:
            dp[h][w]=dp[h][w-1]
        elif w==0:
            dp[h][w]=dp[h-1][w]
        else:
            dp[h][w]=max(dp[h-1][w],dp[h][w-1])
        if dp[h][w] > A[h][w]:
            dp[h][w]+=A[h][w]
        else:
            if h<H-1:
                dp2[h+1][w]=max(dp2[h+1][w], dp[h][w])
            if w<W-1:
                dp2[h][w+1]=max(dp2[h][w+1], dp[h][w])
            dp[h][w]=0
for h in range(H):
    for w in range(W):
        if h==0 and w==0: continue
        if h==0:
            dp2[h][w]=max(dp2[h][w],dp2[h][w-1])
        elif w==0:
            dp2[h][w]=max(dp2[h][w],dp2[h-1][w])
        else:
            dp2[h][w]=max(dp2[h][w],dp2[h-1][w],dp2[h][w-1])
        if dp2[h][w] > A[h][w]:
            dp2[h][w]+=A[h][w]
        else:
            dp2[h][w]=0
print("Yes" if dp[-1][-1]>0 or dp2[-1][-1]>0 else "No")
0