結果
| 問題 |
No.1948 足し算するだけのパズルゲーム(1)
|
| コンテスト | |
| ユーザー |
ikoma
|
| 提出日時 | 2022-05-20 23:34:42 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 133 ms / 2,000 ms |
| コード長 | 1,152 bytes |
| コンパイル時間 | 155 ms |
| コンパイル使用メモリ | 82,084 KB |
| 実行使用メモリ | 83,184 KB |
| 最終ジャッジ日時 | 2024-09-20 10:00:37 |
| 合計ジャッジ時間 | 3,716 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 27 |
ソースコード
import sys
input = sys.stdin.readline
H,W=map(int,input().split())
A=[list(map(int,input().split())) for _ in range(H)]
INF=float("inf")
dp = [[0]*W for _ in range(H)]
dp2 = [[0]*W for _ in range(H)]
dp[0][0]=A[0][0]
for h in range(H):
for w in range(W):
if h==0 and w==0: continue
if h==0:
dp[h][w]=dp[h][w-1]
elif w==0:
dp[h][w]=dp[h-1][w]
else:
dp[h][w]=max(dp[h-1][w],dp[h][w-1])
if dp[h][w] > A[h][w]:
dp[h][w]+=A[h][w]
else:
if h<H-1:
dp2[h+1][w]=max(dp2[h+1][w], dp[h][w])
if w<W-1:
dp2[h][w+1]=max(dp2[h][w+1], dp[h][w])
dp[h][w]=0
for h in range(H):
for w in range(W):
if h==0 and w==0: continue
if h==0:
dp2[h][w]=max(dp2[h][w],dp2[h][w-1])
elif w==0:
dp2[h][w]=max(dp2[h][w],dp2[h-1][w])
else:
dp2[h][w]=max(dp2[h][w],dp2[h-1][w],dp2[h][w-1])
if dp2[h][w] > A[h][w]:
dp2[h][w]+=A[h][w]
else:
dp2[h][w]=0
print("Yes" if dp[-1][-1]>0 or dp2[-1][-1]>0 else "No")
ikoma