結果
問題 | No.2708 Jewel holder |
ユーザー |
![]() |
提出日時 | 2024-04-29 19:42:16 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 184 ms / 2,000 ms |
コード長 | 1,571 bytes |
コンパイル時間 | 416 ms |
コンパイル使用メモリ | 82,176 KB |
実行使用メモリ | 89,344 KB |
最終ジャッジ日時 | 2024-11-19 02:33:12 |
合計ジャッジ時間 | 4,892 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 17 |
ソースコード
from heapq import heappush, heappop, heapifyimport sysfrom collections import defaultdict, deque,Counterfrom math import ceil, floor, sqrt, factorial,gcdfrom itertools import permutations, combinations,productfrom bisect import bisect_left, bisect_rightfrom copy import deepcopyfrom functools import lru_cache #@lru_cache(maxsize=None)from fractions import Fractionsys.setrecursionlimit(10**6)# input = sys.stdin.readlinevector1 = [[0, -1], [1, 0], [0, 1], [-1, 0]]vector2 = [[0, 1], [1, 0], [-1, 0], [0, -1],[1,-1], [-1, 1], [1, 1], [-1, -1]]def main():h,w = map(int,input().split())a = [input() for i in range(h)]q = deque()q.append([0,0,1])memo = defaultdict(int)md = defaultdict(lambda:-1)memo[(0,0)] = 1md[(0,0)] = 0ans = 0while q:x,y,c = q.popleft()if x==h-1 and y==w-1:ans += 1for dx,dy in vector1:nx = x+dxny = y+dyif 0<=nx<h and 0<=ny<w and a[nx][ny] != "#"\and (md[(nx,ny)] ==-1 or md[(nx,ny)] == md[(x,y)]+1):if c == 0:if a[nx][ny] == "o":md[(nx,ny)] = md[(x,y)] + 1q.append([nx,ny,c+1])else:md[(nx,ny)] = md[(x,y)] + 1if a[nx][ny] == "o":q.append([nx,ny,c+1])else:q.append([nx,ny,c-1])print(ans)if __name__ == '__main__':main()