結果
問題 | No.1572 XI |
ユーザー | 👑 SPD_9X2 |
提出日時 | 2021-06-27 14:59:28 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 2,780 bytes |
コンパイル時間 | 590 ms |
コンパイル使用メモリ | 82,584 KB |
実行使用メモリ | 165,704 KB |
最終ジャッジ日時 | 2024-06-25 11:45:22 |
合計ジャッジ時間 | 29,948 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 41 ms
59,904 KB |
testcase_01 | AC | 41 ms
54,400 KB |
testcase_02 | AC | 43 ms
54,528 KB |
testcase_03 | AC | 42 ms
54,656 KB |
testcase_04 | AC | 1,979 ms
124,496 KB |
testcase_05 | TLE | - |
testcase_06 | AC | 1,939 ms
159,760 KB |
testcase_07 | AC | 435 ms
82,544 KB |
testcase_08 | TLE | - |
testcase_09 | AC | 1,192 ms
114,940 KB |
testcase_10 | TLE | - |
testcase_11 | AC | 908 ms
91,128 KB |
testcase_12 | AC | 1,846 ms
118,292 KB |
testcase_13 | AC | 1,019 ms
93,868 KB |
testcase_14 | AC | 1,085 ms
106,556 KB |
testcase_15 | AC | 1,015 ms
92,672 KB |
testcase_16 | AC | 1,747 ms
114,928 KB |
testcase_17 | AC | 370 ms
81,500 KB |
testcase_18 | AC | 1,899 ms
122,796 KB |
testcase_19 | TLE | - |
testcase_20 | TLE | - |
testcase_21 | TLE | - |
testcase_22 | TLE | - |
testcase_23 | AC | 361 ms
81,644 KB |
testcase_24 | AC | 42 ms
54,660 KB |
testcase_25 | AC | 41 ms
55,548 KB |
testcase_26 | AC | 43 ms
56,492 KB |
testcase_27 | AC | 41 ms
56,568 KB |
testcase_28 | AC | 44 ms
57,380 KB |
testcase_29 | AC | 41 ms
55,412 KB |
testcase_30 | AC | 43 ms
55,532 KB |
testcase_31 | AC | 41 ms
54,944 KB |
testcase_32 | AC | 42 ms
55,684 KB |
testcase_33 | AC | 43 ms
56,632 KB |
testcase_34 | TLE | - |
testcase_35 | -- | - |
testcase_36 | -- | - |
testcase_37 | -- | - |
testcase_38 | -- | - |
testcase_39 | -- | - |
testcase_40 | -- | - |
testcase_41 | -- | - |
testcase_42 | -- | - |
testcase_43 | -- | - |
testcase_44 | -- | - |
testcase_45 | -- | - |
testcase_46 | -- | - |
testcase_47 | -- | - |
testcase_48 | -- | - |
ソースコード
""" https://yukicoder.me/problems/no/1572 サイコロの向きは、6通りしかない 頑張って推移を書けばおk 0 表 1 上 2 右 3 下 4 左 5 裏 """ import sys from sys import stdin from collections import deque def encode(x,y,state): return H*W*state + y*H + x def decode(now): state = now // (H*W) y = (now % (H*W)) // H x = (now % (H*W)) % H return x,y,state def chdi(state,movedir): if state == 0: if movedir == "U": return 1 elif movedir == "R": return 2 elif movedir == "D": return 3 else: return 4 elif state == 1: #上 if movedir == "U": return 5 elif movedir == "D": return 0 else: return 1 elif state == 2: #右 if movedir == "R": return 5 elif movedir == "L": return 0 else: return 2 elif state == 3: #下 if movedir == "D": return 5 elif movedir == "U": return 0 else: return 3 elif state == 4: #左 if movedir == "L": return 5 elif movedir == "R": return 0 else: return 4 else: #裏 if movedir == "U": return 3 elif movedir == "R": return 4 elif movedir == "D": return 1 else: return 2 H,W = map(int,stdin.readline().split()) sx,sy = map(int,stdin.readline().split()) gx,gy = map(int,stdin.readline().split()) sx -= 1 sy -= 1 gx -= 1 gy -= 1 A = [ list(stdin.readline()[:-1]) for i in range(H) ] d = [float("inf")] * (H*W*6) q = deque([encode(sx,sy,0)]) d[encode(sx,sy,0)] = 0 while q: code = q.popleft() x,y,state = decode(code) if x != 0 and A[x-1][y] != "#": nx,ny,nstate = x-1,y,chdi(state,"U") ncode = encode(nx,ny,nstate) if d[ncode] > d[code] + 1: d[ncode] = d[code] + 1 q.append(ncode) if x != H-1 and A[x+1][y] != "#": nx,ny,nstate = x+1,y,chdi(state,"D") ncode = encode(nx,ny,nstate) if d[ncode] > d[code] + 1: d[ncode] = d[code] + 1 q.append(ncode) if y != 0 and A[x][y-1] != "#": nx,ny,nstate = x,y-1,chdi(state,"L") ncode = encode(nx,ny,nstate) if d[ncode] > d[code] + 1: d[ncode] = d[code] + 1 q.append(ncode) if y != W-1 and A[x][y+1] != "#": nx,ny,nstate = x,y+1,chdi(state,"R") ncode = encode(nx,ny,nstate) if d[ncode] > d[code] + 1: d[ncode] = d[code] + 1 q.append(ncode) ans = d[encode(gx,gy,0)] print (ans if ans != float("inf") else -1)