結果

問題 No.1948 足し算するだけのパズルゲーム(1)
ユーザー ygd.ygd.
提出日時 2022-05-23 23:34:58
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 530 ms / 2,000 ms
コード長 1,929 bytes
コンパイル時間 94 ms
コンパイル使用メモリ 12,076 KB
実行使用メモリ 47,312 KB
最終ジャッジ日時 2023-10-20 17:47:09
合計ジャッジ時間 8,130 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
10,272 KB
testcase_01 AC 30 ms
10,272 KB
testcase_02 AC 29 ms
10,272 KB
testcase_03 AC 30 ms
10,272 KB
testcase_04 AC 30 ms
10,272 KB
testcase_05 AC 30 ms
10,272 KB
testcase_06 AC 30 ms
10,272 KB
testcase_07 AC 453 ms
30,784 KB
testcase_08 AC 328 ms
24,020 KB
testcase_09 AC 480 ms
35,696 KB
testcase_10 AC 349 ms
35,696 KB
testcase_11 AC 335 ms
25,012 KB
testcase_12 AC 353 ms
26,812 KB
testcase_13 AC 353 ms
26,256 KB
testcase_14 AC 352 ms
25,812 KB
testcase_15 AC 325 ms
24,156 KB
testcase_16 AC 30 ms
10,300 KB
testcase_17 AC 31 ms
10,464 KB
testcase_18 AC 29 ms
10,280 KB
testcase_19 AC 29 ms
10,276 KB
testcase_20 AC 486 ms
39,672 KB
testcase_21 AC 481 ms
39,496 KB
testcase_22 AC 324 ms
24,184 KB
testcase_23 AC 323 ms
24,184 KB
testcase_24 AC 480 ms
39,496 KB
testcase_25 AC 518 ms
46,156 KB
testcase_26 AC 530 ms
47,312 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
#input = sys.stdin.readline
input = sys.stdin.buffer.readline #文字列はダメ
#sys.setrecursionlimit(1000000)
#import bisect
#import itertools
#import random
#from heapq import heapify, heappop, heappush
#from collections import defaultdict 
#from collections import deque
#import copy
#import math
#from functools import lru_cache
#@lru_cache(maxsize=None)
#MOD = pow(10,9) + 7
#MOD = 998244353
#dx = [1,0,-1,0]
#dy = [0,1,0,-1]
#dx8 = [1,1,0,-1,-1,-1,0,1]
#dy8 = [0,1,1,1,0,-1,-1,-1]


def main():
    H,W = map(int,input().split()); INF = pow(10,18)
    A = [list(map(int,input().split())) for _ in range(H)]

    #dp0: 一度も死なずにi,jにいるときの攻撃力の最大値
    #dp1: 一度死んだときにi,jにいるときの攻撃力の最大値
    dp0 = [[-INF]*W for _ in range(H)]
    dp1 = [[-INF]*W for _ in range(H)]
    dp0[0][0] = A[0][0]
    for i in range(H):
        for j in range(W):
            #貰うDP
            #左からの遷移
            if i-1 >= 0:
                #dp0
                if dp0[i-1][j] > A[i][j]:
                    dp0[i][j] = max(dp0[i][j], dp0[i-1][j] + A[i][j])
                else:
                    dp1[i][j] = max(dp1[i][j], dp0[i-1][j])
                #dp1
                if dp1[i-1][j] > A[i][j]:
                    dp1[i][j] = max(dp1[i][j], dp1[i-1][j] + A[i][j])
            #上からの遷移
            if j-1 >= 0:
                if dp0[i][j-1] > A[i][j]:
                    dp0[i][j] = max(dp0[i][j], dp0[i][j-1] + A[i][j])
                else:
                    dp1[i][j] = max(dp1[i][j], dp0[i][j-1])
                #dp1
                if dp1[i][j-1] > A[i][j]:
                    dp1[i][j] = max(dp1[i][j], dp1[i][j-1] + A[i][j])
    
    #print(dp0)
    #print(dp1)

    if dp1[H-1][W-1] > A[H-1][W-1] or dp0[H-1][W-1] > 0:
        print('Yes')
    else:
        print('No')



if __name__ == '__main__':
    main()
0