結果

問題 No.1572 XI
ユーザー persimmon-persimmonpersimmon-persimmon
提出日時 2021-07-02 10:23:37
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,385 bytes
コンパイル時間 360 ms
コンパイル使用メモリ 86,868 KB
実行使用メモリ 186,824 KB
最終ジャッジ日時 2023-09-11 06:07:28
合計ジャッジ時間 45,803 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 106 ms
75,956 KB
testcase_01 AC 96 ms
71,676 KB
testcase_02 AC 97 ms
71,596 KB
testcase_03 AC 96 ms
71,380 KB
testcase_04 AC 517 ms
95,696 KB
testcase_05 AC 1,006 ms
123,128 KB
testcase_06 AC 1,199 ms
134,832 KB
testcase_07 AC 145 ms
78,708 KB
testcase_08 AC 1,042 ms
123,796 KB
testcase_09 AC 570 ms
98,296 KB
testcase_10 AC 801 ms
114,716 KB
testcase_11 AC 168 ms
79,800 KB
testcase_12 AC 417 ms
91,712 KB
testcase_13 AC 192 ms
80,352 KB
testcase_14 AC 430 ms
92,512 KB
testcase_15 AC 188 ms
79,944 KB
testcase_16 AC 379 ms
89,872 KB
testcase_17 AC 146 ms
78,340 KB
testcase_18 AC 482 ms
95,848 KB
testcase_19 AC 1,068 ms
128,416 KB
testcase_20 AC 717 ms
109,124 KB
testcase_21 AC 1,204 ms
135,592 KB
testcase_22 AC 967 ms
122,660 KB
testcase_23 AC 138 ms
78,188 KB
testcase_24 AC 96 ms
71,512 KB
testcase_25 AC 96 ms
71,676 KB
testcase_26 AC 104 ms
75,960 KB
testcase_27 AC 97 ms
71,552 KB
testcase_28 AC 107 ms
77,152 KB
testcase_29 AC 104 ms
75,996 KB
testcase_30 AC 107 ms
76,816 KB
testcase_31 AC 97 ms
71,252 KB
testcase_32 AC 93 ms
71,668 KB
testcase_33 AC 102 ms
76,012 KB
testcase_34 AC 1,816 ms
174,728 KB
testcase_35 AC 1,828 ms
169,728 KB
testcase_36 AC 1,884 ms
171,308 KB
testcase_37 AC 1,973 ms
178,760 KB
testcase_38 AC 1,836 ms
174,400 KB
testcase_39 AC 1,953 ms
177,476 KB
testcase_40 AC 1,813 ms
171,148 KB
testcase_41 AC 1,870 ms
181,496 KB
testcase_42 AC 1,831 ms
174,220 KB
testcase_43 AC 1,815 ms
172,308 KB
testcase_44 TLE -
testcase_45 TLE -
testcase_46 TLE -
testcase_47 AC 136 ms
126,520 KB
testcase_48 AC 1,973 ms
179,580 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

"""
4 4
1 1
4 4
....
..##
#...
#...
->6
"""
h,w=map(int,input().split())
s=list(map(int,input().split()))
g=list(map(int,input().split()))
a=[input() for _ in range(h)]
s[0],s[1]=s[0]-1,s[1]-1
g[0],g[1]=g[0]-1,g[1]-1
seen=[-1]*(h*w*6)
# seen[(i*h+j)*6+x]:マス(i,j)でさいころの状態がx
# x=0:1が上,
# x=1:1が右側(wの+方向),
# x=2:1が左側(wの-方向),
# x=3:1が奥側(hの+方向),
# x=4:1が手前側(hの-方向),
# x=5:1が下
trans=lambda i,j,x:(i*w+j)*6+x
seen[trans(s[0],s[1],0)]=0
d={}
# 1上の状態から
d[(0,1,0)]=1
d[(0,-1,0)]=2
d[(1,0,0)]=3
d[(-1,0,0)]=4
# 1右の状態から
d[(0,1,1)]=5
d[(0,-1,1)]=0
d[(1,0,1)]=1
d[(-1,0,1)]=1
# 1左の状態から
d[(0,1,2)]=0
d[(0,-1,2)]=5
d[(1,0,2)]=2
d[(-1,0,2)]=2
# 1奥の状態から
d[(0,1,3)]=3
d[(0,-1,3)]=3
d[(1,0,3)]=5
d[(-1,0,3)]=0
# 1手前の状態から
d[(0,1,4)]=4
d[(0,-1,4)]=4
d[(1,0,4)]=0
d[(-1,0,4)]=5
# 1下の状態から
d[(0,1,5)]=2
d[(0,-1,5)]=1
d[(1,0,5)]=4
d[(-1,0,5)]=3


from collections import deque
todo=deque([[s[0],s[1],0]])
while todo:
  i,j,x=todo.popleft()
  for di,dj in ((0,1),(0,-1),(1,0),(-1,0)):
    ni,nj=i+di,j+dj
    if not 0<=ni<h:continue
    if not 0<=nj<w:continue
    if a[ni][nj]=="#":continue
    nx=d[(di,dj,x)]
    if seen[trans(ni,nj,nx)]==-1:
      seen[trans(ni,nj,nx)]=seen[trans(i,j,x)]+1
      todo.append([ni,nj,nx])
print(seen[trans(g[0],g[1],0)])

0