結果

問題 No.1948 足し算するだけのパズルゲーム(1)
ユーザー tassei903tassei903
提出日時 2022-05-21 09:40:22
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 202 ms / 2,000 ms
コード長 1,276 bytes
コンパイル時間 1,552 ms
コンパイル使用メモリ 81,412 KB
実行使用メモリ 94,348 KB
最終ジャッジ日時 2023-10-20 15:46:26
合計ジャッジ時間 5,311 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
53,256 KB
testcase_01 AC 35 ms
53,256 KB
testcase_02 AC 35 ms
53,256 KB
testcase_03 AC 36 ms
53,256 KB
testcase_04 AC 34 ms
53,256 KB
testcase_05 AC 35 ms
53,256 KB
testcase_06 AC 34 ms
53,256 KB
testcase_07 AC 141 ms
83,004 KB
testcase_08 AC 122 ms
81,884 KB
testcase_09 AC 139 ms
82,296 KB
testcase_10 AC 154 ms
94,348 KB
testcase_11 AC 180 ms
86,216 KB
testcase_12 AC 177 ms
86,900 KB
testcase_13 AC 202 ms
86,840 KB
testcase_14 AC 184 ms
86,052 KB
testcase_15 AC 167 ms
83,292 KB
testcase_16 AC 38 ms
55,308 KB
testcase_17 AC 43 ms
57,356 KB
testcase_18 AC 36 ms
53,260 KB
testcase_19 AC 37 ms
53,260 KB
testcase_20 AC 166 ms
83,420 KB
testcase_21 AC 174 ms
83,232 KB
testcase_22 AC 129 ms
84,588 KB
testcase_23 AC 113 ms
80,420 KB
testcase_24 AC 137 ms
84,616 KB
testcase_25 AC 173 ms
90,900 KB
testcase_26 AC 176 ms
89,468 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = lambda :sys.stdin.readline()[:-1]
ni = lambda :int(input())
na = lambda :list(map(int,input().split()))
yes = lambda :print("yes");Yes = lambda :print("Yes");YES = lambda : print("YES")
no = lambda :print("no");No = lambda :print("No");NO = lambda : print("NO")
#######################################################################

h,w = na()
a = [na() for i in range(h)]
dp = [[-float("inf") for j in range(w)]for i in range(h)]
ndp = [[-float("inf") for j in range(w)]for i in range(h)]
dp[0][0] = a[0][0]
for i in range(h):
    for j in range(w):
        if i < h-1 and dp[i][j] > a[i+1][j]:
            dp[i+1][j] = max(dp[i+1][j], dp[i][j] + a[i+1][j])
        if i < h-1 and ndp[i][j] > a[i+1][j]:
            ndp[i+1][j] = max(ndp[i+1][j], ndp[i][j] + a[i+1][j])
        if i < h-1 and ((i+1,j)!=(h-1,w-1)):
            ndp[i+1][j] = max(ndp[i+1][j], dp[i][j])
        if j < w-1 and dp[i][j] > a[i][j+1]:
            dp[i][j+1] = max(dp[i][j+1], dp[i][j] + a[i][j+1])
        if j < w-1 and ndp[i][j] > a[i][j+1]:
            ndp[i][j+1] = max(ndp[i][j+1], ndp[i][j] + a[i][j+1])
        if j < w-1 and ((i,j+1)!=(h-1,w-1)):
            ndp[i][j+1] = max(ndp[i][j+1], dp[i][j])
    
if dp[-1][-1] > 0 or ndp[-1][-1] > 0:
    Yes()
else:
    No()
0