結果

問題 No.1948 足し算するだけのパズルゲーム(1)
ユーザー 👑 H20H20
提出日時 2022-04-10 19:30:54
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 251 ms / 2,000 ms
コード長 1,062 bytes
コンパイル時間 281 ms
コンパイル使用メモリ 86,888 KB
実行使用メモリ 103,916 KB
最終ジャッジ日時 2023-09-09 03:32:00
合計ジャッジ時間 6,035 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
71,360 KB
testcase_01 AC 73 ms
71,144 KB
testcase_02 AC 71 ms
71,268 KB
testcase_03 AC 72 ms
71,292 KB
testcase_04 AC 72 ms
71,404 KB
testcase_05 AC 70 ms
71,444 KB
testcase_06 AC 74 ms
71,448 KB
testcase_07 AC 212 ms
101,656 KB
testcase_08 AC 186 ms
101,788 KB
testcase_09 AC 207 ms
101,760 KB
testcase_10 AC 187 ms
101,664 KB
testcase_11 AC 218 ms
102,456 KB
testcase_12 AC 218 ms
102,556 KB
testcase_13 AC 251 ms
103,916 KB
testcase_14 AC 238 ms
103,340 KB
testcase_15 AC 210 ms
102,540 KB
testcase_16 AC 77 ms
75,124 KB
testcase_17 AC 86 ms
75,012 KB
testcase_18 AC 73 ms
71,276 KB
testcase_19 AC 71 ms
71,412 KB
testcase_20 AC 234 ms
102,820 KB
testcase_21 AC 224 ms
102,932 KB
testcase_22 AC 161 ms
90,028 KB
testcase_23 AC 161 ms
90,660 KB
testcase_24 AC 190 ms
102,520 KB
testcase_25 AC 211 ms
101,988 KB
testcase_26 AC 233 ms
102,184 KB
権限があれば一括ダウンロードができます

ソースコード

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