結果
| 問題 | No.3504 Insert Maze |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-04-17 22:30:52 |
| 言語 | PyPy3 (7.3.17) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,969 bytes |
| 記録 | |
| コンパイル時間 | 390 ms |
| コンパイル使用メモリ | 85,376 KB |
| 実行使用メモリ | 945,388 KB |
| 最終ジャッジ日時 | 2026-04-17 22:32:29 |
| 合計ジャッジ時間 | 22,883 ms |
|
ジャッジサーバーID (参考情報) |
judge1_0 / judge1_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 24 WA * 3 TLE * 1 -- * 57 |
ソースコード
#--------------------------------------------------
import sys
import functools
#sys.setrecursionlimit(10**9)
#codon↓--------------------------------------------
_factorial=[1]
def factorial(n):
while len(_factorial)<=n:
_factorial.append((_factorial[-1]*len(_factorial))%mod)
return _factorial[n]
def binom(n,r):
if r>=mod:
raise ValueError("r is too big")
if n<0:
return 0
if r>n:
return 0
if r<0:
return 0
ans=((factorial(n)*pow(factorial(r),mod-2,mod))%mod*pow(factorial(n-r),mod-2,mod))%mod
return ans
import string
import itertools
alp_low=list(string.ascii_lowercase)
alp_up=list(string.ascii_uppercase)
dij=[[0,1],[1,0],[0,-1],[-1,0]]
mod=998244353
INF=10**18
def dijkstra(edges, num_node,start):
"""
[node_num,weight>0][
(example)
Edges = [
[[1, 4], [2, 3]],
[[0, 1], [3, 1]],
[[3, 2]],
[],
]
"""
import heapq;n=[INF]*num_node;n[start]=0;n_name=[];heapq.heappush(n_name,[0,start])
while len(n_name):
_,min_p=heapq.heappop(n_name)
for f in edges[min_p]:
g,c=f
if n[min_p]+c<n[g]:n[g]=n[min_p]+c;heapq.heappush(n_name,[n[min_p]+c,g])
return n
def nin():
return list(map(int,input().split()))
def deq(x):
return [i-1 for i in x]
def pop_cnt(n):
ans=0
while n:
if n%2:
ans+=1
n//=2
return ans
import queue
def main():
h,w=nin()
gr={i:[] for i in range((2*h-1)*(2*w-1))}
s=[list(input()) for i in range(h)]
hh=2*h-1
ww=2*w-1
ss=gg=-1
for i in range(h):
for j in range(w):
if s[i][j]=="S":
ss=2*i*ww+2*j
s[i][j]="."
elif s[i][j]=="G":
gg=2*i*ww+2*j
s[i][j]="."
d=[-1]*len(gr)
task=queue.Queue()
task.put(ss)
d[ss]=0
while not task.empty():
i=task.get()
rin=[]
ii,jj=i//ww,i%ww
for di,dj in dij:
if 0<=ii+di<hh and 0<=jj+dj<ww and (ii+di%2==1 or jj+dj%2==1 or s[(ii+di)//2][(jj+dj)//2]=="."):
rin.append((ii+di)*ww+(jj+dj))
if ii%2==jj%2==0:
for di,dj in dij:
di*=2
dj*=2
if 0<=ii+di<hh and 0<=jj+dj<ww and s[(ii+di)//2][(jj+dj)//2]==".":
rin.append((ii+di)*ww+(jj+dj))
if ii%2==0 and jj%2==1:
for di in [2,-2]:
if 0<=ii+di<hh:
rin.append((ii+di)*ww+(jj))
if ii%2==1 and jj%2==0:
for dj in [2,-2]:
if 0<=jj+dj<ww:
rin.append((ii)*ww+(jj+dj))
for j in rin:
if d[j]==-1:
d[j]=d[i]+1
#print(i,j,d[j])
if j==gg:
print(d[j])
return
task.put(j)
if __name__=="__main__":
main()