結果

問題 No.2708 Jewel holder
ユーザー ゆ
提出日時 2024-03-31 13:51:18
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 388 ms / 2,000 ms
コード長 1,148 bytes
コンパイル時間 163 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 141,720 KB
最終ジャッジ日時 2024-03-31 13:51:20
合計ジャッジ時間 2,401 ms
ジャッジサーバーID
(参考情報)
judge10 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 48 ms
55,760 KB
testcase_01 AC 46 ms
55,760 KB
testcase_02 AC 44 ms
55,760 KB
testcase_03 AC 43 ms
55,760 KB
testcase_04 AC 43 ms
55,760 KB
testcase_05 AC 43 ms
55,760 KB
testcase_06 AC 43 ms
55,756 KB
testcase_07 AC 44 ms
55,760 KB
testcase_08 AC 44 ms
55,760 KB
testcase_09 AC 44 ms
55,760 KB
testcase_10 AC 43 ms
55,760 KB
testcase_11 AC 60 ms
66,416 KB
testcase_12 AC 45 ms
55,760 KB
testcase_13 AC 61 ms
68,496 KB
testcase_14 AC 46 ms
55,760 KB
testcase_15 AC 44 ms
55,760 KB
testcase_16 AC 54 ms
64,196 KB
testcase_17 AC 388 ms
141,720 KB
testcase_18 AC 104 ms
76,776 KB
testcase_19 AC 107 ms
76,664 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# oj t -c "python3 main.py"
import sys,math
from collections import defaultdict,deque
from itertools import combinations,permutations,accumulate,product
from bisect import bisect,bisect_left,bisect_right
from heapq import heappop,heappush,heapify
#from sortedcontainers import SortedList,SortedSet
def input(): return sys.stdin.readline().rstrip()
def ii(): return int(input())
def ms(): return map(int, input().split())
def li(): return list(map(int,input().split()))
inf = pow(10,18)
#////////////////////////////////////
H,W = ms()
que = deque()
A = [input() for _ in range(H)]
DIJ = [(0,1),(1,0),(-1,0),(0,-1)]
que.append((0,0,0))
ans = 0
visited = [[-1]*W for _ in range(H)]
visited[0][0] = 0
while que:
  i,j,c = que.popleft()
  if A[i][j]=='o': c += 1
  else:
    c -= 1
    if c==-1: continue
  if i==H-1 and j==W-1:
    visited[i][j] = False
    ans += 1
  for di,dj in [(0,1),(1,0),(0,-1),(-1,0)]:
    ni,nj	= i+di,j+dj
    if 0<=ni<H and 0<=nj<W:
      if A[ni][nj]=='#': continue
      if visited[ni][nj]!=-1 and visited[ni][nj]<visited[i][j]+1: continue
      visited[ni][nj] = visited[i][j]+1
      que.append((ni,nj,c))


print(ans)
0