結果
問題 | No.331 CodeRunnerでやれ |
ユーザー |
![]() |
提出日時 | 2015-12-25 01:16:39 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
RE
|
実行時間 | - |
コード長 | 2,275 bytes |
コンパイル時間 | 182 ms |
コンパイル使用メモリ | 12,928 KB |
実行使用メモリ | 28,888 KB |
平均クエリ数 | 104.71 |
最終ジャッジ日時 | 2024-07-16 08:25:55 |
合計ジャッジ時間 | 8,878 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 2 RE * 14 |
ソースコード
import sysimport collectionsdef navi(y,x,dy,dx,path):move = []ty = -1tx = -1while path:ty,tx = path.pop()if y+dy == ty and x+dx==tx:move += ['F']elif y-dy == ty and x-dx==tx:move += ['B']elif y-dx == ty and x+dy==tx:move += ['L','F']elif y+dx == ty and x-dy==tx:move += ['R','F']return movedef accessible(sy,sx,ty,tx,maze):visited = [[False for j in range(40)] for i in range(40)]path = [[[] for j in range(40)] for i in range(40)]visited[sy][sx] = Truedq = collections.deque()dq.append((sy,sx))D = [(1,0),(-1,0),(0,1),(0,-1)]while dq:y,x = dq.popleft()if y==ty and x ==tx:return path[ty][tx]for dy,dx in D:if 0<=y+dy<40 and 0<=x+dx<40 and not visited[y+dy][x+dx]:dq.append((y+dy,x+dx))visited[y+dy][x+dx] = Truepath[y+dy][x+dx] = path[y][x][:]+[(y,x)]return []maze = [[0 for j in range(40)] for i in range(40)]maze[19][19] = 1posx = 19posy = 19dx = 0dy = -1tx = 19ty = 19path = []move = []while True:s = input()if s == 'Merry Christmas!':exit()s = int(s)if s > 17:print('F')posy+=dyposx+=dxsys.stdout.flush()elif s == 0:maze[posy+dy][posx+dx] = -1print('L')posy-=dyposx-=dxsys.stdout.flush()else:for i in range(1,s+1):maze[posy+dy*i][posx+dx*i] = 1if move:m = move.pop()if m=='F':posy+=dyposx+=dxelif m=='B':posy-=dyposx-=dxelif m=='R':dy,dx = -dx,dyelif m=='L':dy,dx = dx,-dyprint(m)sys.stdout.flush()else:i = 0j = 0while not path:path = accessible(posy,posx,i,j,maze)j += 1if j == 40:j = 0i += 1move = navi(posy,posx,dy,dx,path)print(move.pop())sys.stdout.flush()