結果
| 問題 |
No.1949 足し算するだけのパズルゲーム(2)
|
| コンテスト | |
| ユーザー |
lilictaka
|
| 提出日時 | 2022-05-20 23:42:29 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 855 bytes |
| コンパイル時間 | 262 ms |
| コンパイル使用メモリ | 12,672 KB |
| 実行使用メモリ | 25,856 KB |
| 最終ジャッジ日時 | 2024-09-20 10:09:33 |
| 合計ジャッジ時間 | 3,678 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 12 WA * 2 RE * 12 |
ソースコード
H,W,Y,X = map(int,input().split())
seen = [[False] * W for _ in range(H)]
INF = float('inf')
memo = [[-INF] * W for _ in range(H)]
A = []
for _ in range(H):
tmp = list(map(int,input().split()))
A.append(tmp)
def check(h,w):
if 0 <= h < H and 0 <= w < W:
return True
else:
return False
ans = False
def dfs(h,w,a):
global ans
if h == H -1 and w == W-1:
print('Yes')
exit()
seen[h][w] = True
if memo[h][w] >= a:
return
memo[h][w] = a
for dh,dw in [(-1,0),(1,0),(0,1),(0,-1)]:
nh = h + dh
nw = w + dw
if check(nh,nw) and not seen[nh][nw] and A[nh][nw] < a:
dfs(nh,nw,a + A[nh][nw])
seen[nh][nw] = False
if check(nh,nw) and seen[nh][nw] and memo[nh][nw] < a:
dfs(nh,nw,a)
dfs(Y-1,X-1,A[Y-1][X-1])
print('No')
lilictaka