結果

問題 No.1948 足し算するだけのパズルゲーム(1)
ユーザー H20
提出日時 2022-04-10 19:30:54
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 218 ms / 2,000 ms
コード長 1,062 bytes
コンパイル時間 160 ms
コンパイル使用メモリ 82,484 KB
実行使用メモリ 102,012 KB
最終ジャッジ日時 2024-06-26 20:41:22
合計ジャッジ時間 4,837 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #

H,W = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(H)]
if not(1<=H<=500 and 1<=W<=500 and len(A)==H):
    exit()
for a in A:
    if not (len(a)==W and 1<=min(a) and max(a)<=10**9):
        exit()

DP = [[[0]*2 for _ in range(W)]for _ in range(H)]
DP[0][0][0]=A[0][0]
for h in range(H):
    for w in range(W):
        if h+1<H and DP[h][w][0]>A[h+1][w]:
            DP[h+1][w][0]=max(DP[h+1][w][0],DP[h][w][0]+A[h+1][w])
        if w+1<W and DP[h][w][0]>A[h][w+1]:
            DP[h][w+1][0]=max(DP[h][w+1][0],DP[h][w][0]+A[h][w+1])
        if h+1<H and DP[h][w][1]>A[h+1][w]:
            DP[h+1][w][1]=max(DP[h+1][w][1],DP[h][w][1]+A[h+1][w])
        if w+1<W and DP[h][w][1]>A[h][w+1]:
            DP[h][w+1][1]=max(DP[h][w+1][1],DP[h][w][1]+A[h][w+1])
        if h+1<H and DP[h][w][0]<=A[h+1][w]:
            DP[h+1][w][1]=max(DP[h+1][w][1],DP[h][w][0])
        if w+1<W and DP[h][w][0]<=A[h][w+1]:
            DP[h][w+1][1]=max(DP[h][w+1][1],DP[h][w][0])
if max(DP[H-1][W-1])>A[H-1][W-1]:
    print('Yes')
else:
    print('No')
0