結果

問題 No.1948 足し算するだけのパズルゲーム(1)
ユーザー siganaisiganai
提出日時 2022-05-20 22:55:38
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 150 ms / 2,000 ms
コード長 1,254 bytes
コンパイル時間 161 ms
コンパイル使用メモリ 81,788 KB
実行使用メモリ 84,412 KB
最終ジャッジ日時 2023-10-20 13:48:14
合計ジャッジ時間 4,164 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 62 ms
63,616 KB
testcase_01 AC 59 ms
63,616 KB
testcase_02 AC 57 ms
63,616 KB
testcase_03 AC 59 ms
63,616 KB
testcase_04 AC 57 ms
63,616 KB
testcase_05 AC 58 ms
63,616 KB
testcase_06 AC 58 ms
63,616 KB
testcase_07 AC 124 ms
83,372 KB
testcase_08 AC 109 ms
79,616 KB
testcase_09 AC 123 ms
79,720 KB
testcase_10 AC 113 ms
79,664 KB
testcase_11 AC 130 ms
80,628 KB
testcase_12 AC 128 ms
83,536 KB
testcase_13 AC 148 ms
84,352 KB
testcase_14 AC 150 ms
84,412 KB
testcase_15 AC 122 ms
83,452 KB
testcase_16 AC 59 ms
65,664 KB
testcase_17 AC 61 ms
65,664 KB
testcase_18 AC 59 ms
65,664 KB
testcase_19 AC 59 ms
63,668 KB
testcase_20 AC 147 ms
84,208 KB
testcase_21 AC 149 ms
84,016 KB
testcase_22 AC 102 ms
78,580 KB
testcase_23 AC 103 ms
78,608 KB
testcase_24 AC 111 ms
78,640 KB
testcase_25 AC 128 ms
83,316 KB
testcase_26 AC 143 ms
81,932 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env PyPy3

from collections import Counter, defaultdict, deque
import itertools
import re
import math
from functools import reduce
import operator
import bisect
from heapq import *
import functools
mod=998244353

import sys
input=sys.stdin.readline
h,w=map(int,input().split())
a=[list(map(int,input().split())) for _ in range(h)]
dp = [[[-1] * w for _ in range(h)] for _ in range(2)]
dp[0][0][0] = a[0][0]
for i in range(h):
    for j in range(w):
        if i == 0 and j == 0:
            continue
        if i != 0:
            if dp[0][i-1][j] > a[i][j]:
                dp[0][i][j] = dp[0][i-1][j] + a[i][j]
            elif dp[0][i-1][j] != -1:
                dp[1][i][j] = dp[0][i-1][j]
            if dp[1][i-1][j] > a[i][j]:
                dp[1][i][j] = max(dp[1][i-1][j] + a[i][j],dp[1][i][j])
        if j != 0:
            if dp[0][i][j-1] > a[i][j]:
                dp[0][i][j] = max(dp[0][i][j-1] + a[i][j],dp[0][i][j])
            elif dp[0][i][j-1] != -1:
                dp[1][i][j] = max(dp[0][i][j-1],dp[1][i][j])
            if dp[1][i][j-1] > a[i][j]:
                dp[1][i][j] = max(dp[1][i][j-1] + a[i][j],dp[1][i][j])
if dp[0][-1][-1] > a[-1][-1] or dp[1][-1][-1] > a[-1][-1]:
    print('Yes')
else:
    print('No')
0