結果

問題 No.1948 足し算するだけのパズルゲーム(1)
ユーザー chineristACchineristAC
提出日時 2022-05-20 21:48:29
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 150 ms / 2,000 ms
コード長 1,147 bytes
コンパイル時間 1,253 ms
コンパイル使用メモリ 81,592 KB
実行使用メモリ 84,316 KB
最終ジャッジ日時 2023-10-20 12:18:05
合計ジャッジ時間 4,332 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 46 ms
56,100 KB
testcase_01 AC 46 ms
56,100 KB
testcase_02 AC 45 ms
56,100 KB
testcase_03 AC 46 ms
56,100 KB
testcase_04 AC 46 ms
56,100 KB
testcase_05 AC 46 ms
56,100 KB
testcase_06 AC 45 ms
56,100 KB
testcase_07 AC 127 ms
83,172 KB
testcase_08 AC 109 ms
79,616 KB
testcase_09 AC 127 ms
80,216 KB
testcase_10 AC 108 ms
79,512 KB
testcase_11 AC 131 ms
80,644 KB
testcase_12 AC 132 ms
84,048 KB
testcase_13 AC 150 ms
84,316 KB
testcase_14 AC 146 ms
84,240 KB
testcase_15 AC 124 ms
83,464 KB
testcase_16 AC 49 ms
58,160 KB
testcase_17 AC 52 ms
60,208 KB
testcase_18 AC 47 ms
58,160 KB
testcase_19 AC 47 ms
58,160 KB
testcase_20 AC 141 ms
83,820 KB
testcase_21 AC 133 ms
83,368 KB
testcase_22 AC 104 ms
78,548 KB
testcase_23 AC 104 ms
78,536 KB
testcase_24 AC 107 ms
78,476 KB
testcase_25 AC 125 ms
83,340 KB
testcase_26 AC 134 ms
82,020 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys,random,bisect
from collections import deque,defaultdict
import heapq
from itertools import permutations
from math import gcd

input = lambda :sys.stdin.readline().rstrip()
mi = lambda :map(int,input().split())
li = lambda :list(mi())

INF = 10**17

H,W = mi()
A = [li() for i in range(H)]

dp0 = [[-INF]*W for i in range(H)]
dp1 = [[-INF]*W for i in range(H)]
dp1[0][0] = A[0][0]

for i in range(H):
    for j in range(W):
        if i!=H-1:
            if dp0[i][j] > A[i+1][j]:
                dp0[i+1][j] = max(dp0[i+1][j],dp0[i][j]+A[i+1][j])
            if dp1[i][j] > A[i+1][j]:
                dp1[i+1][j] = max(dp1[i+1][j],dp1[i][j]+A[i+1][j])
            elif (i+1,j)!=(H-1,W-1):
                dp0[i+1][j] = max(dp0[i+1][j],dp1[i][j])
        if j!=W-1:
            if dp0[i][j] > A[i][j+1]:
                dp0[i][j+1] = max(dp0[i][j+1],dp0[i][j]+A[i][j+1])
            if dp1[i][j] > A[i][j+1]:
                dp1[i][j+1] = max(dp1[i][j+1],dp1[i][j]+A[i][j+1])
            elif (i,j+1)!=(H-1,W-1):
                dp0[i][j+1] = max(dp0[i][j+1],dp1[i][j])


print("Yes" if dp1[-1][-1]!=-INF or dp0[-1][-1]!=-INF else "No")
0