結果

問題 No.1948 足し算するだけのパズルゲーム(1)
ユーザー terasaterasa
提出日時 2022-05-22 11:48:12
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 151 ms / 2,000 ms
コード長 1,283 bytes
コンパイル時間 156 ms
コンパイル使用メモリ 81,908 KB
実行使用メモリ 85,480 KB
最終ジャッジ日時 2023-10-20 16:55:34
合計ジャッジ時間 4,125 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 56 ms
66,328 KB
testcase_01 AC 60 ms
66,328 KB
testcase_02 AC 59 ms
66,328 KB
testcase_03 AC 55 ms
66,328 KB
testcase_04 AC 55 ms
66,328 KB
testcase_05 AC 55 ms
66,328 KB
testcase_06 AC 57 ms
66,328 KB
testcase_07 AC 123 ms
84,536 KB
testcase_08 AC 109 ms
80,164 KB
testcase_09 AC 123 ms
80,788 KB
testcase_10 AC 118 ms
80,124 KB
testcase_11 AC 131 ms
80,868 KB
testcase_12 AC 136 ms
85,020 KB
testcase_13 AC 148 ms
85,440 KB
testcase_14 AC 151 ms
85,480 KB
testcase_15 AC 119 ms
84,888 KB
testcase_16 AC 62 ms
68,568 KB
testcase_17 AC 60 ms
70,616 KB
testcase_18 AC 55 ms
66,328 KB
testcase_19 AC 57 ms
66,328 KB
testcase_20 AC 145 ms
85,096 KB
testcase_21 AC 140 ms
85,076 KB
testcase_22 AC 107 ms
84,460 KB
testcase_23 AC 106 ms
84,300 KB
testcase_24 AC 110 ms
84,280 KB
testcase_25 AC 128 ms
82,020 KB
testcase_26 AC 133 ms
81,056 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
import pypyjit
import itertools
import heapq
import math
from collections import deque, defaultdict, Counter
import string
import random

input = sys.stdin.readline
sys.setrecursionlimit(10 ** 6)
pypyjit.set_param('max_unroll_recursion=-1')


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

dp = [[[0 for _ in range(W)] for _ in range(H)] for _ in range(2)]
dp[1][0][0] = A[0][0]
for i in range(H):
    for j in range(W):
        if i > 0:
            if dp[1][i - 1][j] > A[i][j]:
                dp[1][i][j] = max(dp[1][i][j], dp[1][i - 1][j] + A[i][j])
            elif not (i == H - 1 and j == W - 1):
                dp[0][i][j] = max(dp[0][i][j], dp[1][i - 1][j])

            if dp[0][i - 1][j] > A[i][j]:
                dp[0][i][j] = max(dp[0][i][j], dp[0][i - 1][j] + A[i][j])

        if j > 0:
            if dp[1][i][j - 1] > A[i][j]:
                dp[1][i][j] = max(dp[1][i][j], dp[1][i][j - 1] + A[i][j])
            elif not (i == H - 1 and j == W - 1):
                dp[0][i][j] = max(dp[0][i][j], dp[1][i][j - 1])

            if dp[0][i][j - 1] > A[i][j]:
                dp[0][i][j] = max(dp[0][i][j], dp[0][i][j - 1] + A[i][j])
print('Yes' if dp[1][H - 1][W - 1] > 0 or dp[0][H - 1][W - 1] > 0 else 'No')
0