結果

問題 No.1948 足し算するだけのパズルゲーム(1)
ユーザー titiatitia
提出日時 2022-05-20 21:42:05
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 130 ms / 2,000 ms
コード長 1,152 bytes
コンパイル時間 173 ms
コンパイル使用メモリ 81,588 KB
実行使用メモリ 82,432 KB
最終ジャッジ日時 2023-10-20 12:08:38
合計ジャッジ時間 3,768 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
53,400 KB
testcase_01 AC 37 ms
53,400 KB
testcase_02 AC 37 ms
53,400 KB
testcase_03 AC 37 ms
53,400 KB
testcase_04 AC 37 ms
53,400 KB
testcase_05 AC 37 ms
53,400 KB
testcase_06 AC 36 ms
53,400 KB
testcase_07 AC 91 ms
77,460 KB
testcase_08 AC 79 ms
76,772 KB
testcase_09 AC 104 ms
81,776 KB
testcase_10 AC 98 ms
81,616 KB
testcase_11 AC 112 ms
82,432 KB
testcase_12 AC 116 ms
81,972 KB
testcase_13 AC 120 ms
82,136 KB
testcase_14 AC 115 ms
82,008 KB
testcase_15 AC 92 ms
77,320 KB
testcase_16 AC 39 ms
53,404 KB
testcase_17 AC 40 ms
55,452 KB
testcase_18 AC 37 ms
53,404 KB
testcase_19 AC 38 ms
53,404 KB
testcase_20 AC 130 ms
81,916 KB
testcase_21 AC 125 ms
81,916 KB
testcase_22 AC 79 ms
77,316 KB
testcase_23 AC 78 ms
77,312 KB
testcase_24 AC 103 ms
77,444 KB
testcase_25 AC 123 ms
81,660 KB
testcase_26 AC 128 ms
81,912 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

H,W=map(int,input().split())
A=[list(map(int,input().split())) for i in range(H)]

DP=[[-1]*W for i in range(H)]
DP2=[[-1]*W for i in range(H)]


DP[0][0]=A[0][0]

for i in range(H):
    for j in range(W):
        if DP[i][j]==-1:
            continue
        if i+1<H:
            if A[i+1][j]<DP[i][j]:
                DP[i+1][j]=max(DP[i+1][j],DP[i][j]+A[i+1][j])
            else:
                DP2[i+1][j]=max(DP2[i+1][j],DP[i][j])
        if j+1<W:
            if A[i][j+1]<DP[i][j]:
                DP[i][j+1]=max(DP[i][j+1],DP[i][j]+A[i][j+1])
            else:
                DP2[i][j+1]=max(DP2[i][j+1],DP[i][j])

for i in range(H):
    for j in range(W):
        if DP2[i][j]==-1:
            continue
        if i+1<H:
            if A[i+1][j]<DP2[i][j]:
                DP2[i+1][j]=max(DP2[i+1][j],DP2[i][j]+A[i+1][j])
        if j+1<W:
            if A[i][j+1]<DP2[i][j]:
                DP2[i][j+1]=max(DP2[i][j+1],DP2[i][j]+A[i][j+1])
            
if DP[H-2][W-1]>A[-1][-1] or DP2[H-2][W-1]>A[-1][-1] or DP[H-1][W-2]>A[-1][-1] or DP2[H-1][W-2]>A[-1][-1]:
    print("Yes")
else:
    print("No")
0