結果
問題 | No.331 CodeRunnerでやれ |
ユーザー | matsu7874 |
提出日時 | 2015-12-25 01:26:59 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 2,722 bytes |
コンパイル時間 | 93 ms |
コンパイル使用メモリ | 13,056 KB |
実行使用メモリ | 28,792 KB |
平均クエリ数 | 163.24 |
最終ジャッジ日時 | 2024-07-16 08:25:43 |
合計ジャッジ時間 | 4,975 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 182 ms
27,360 KB |
testcase_01 | RE | - |
testcase_02 | RE | - |
testcase_03 | RE | - |
testcase_04 | RE | - |
testcase_05 | RE | - |
testcase_06 | RE | - |
testcase_07 | RE | - |
testcase_08 | RE | - |
testcase_09 | RE | - |
testcase_10 | RE | - |
testcase_11 | RE | - |
testcase_12 | RE | - |
testcase_13 | RE | - |
testcase_14 | RE | - |
testcase_15 | RE | - |
testcase_16 | RE | - |
ソースコード
import sys import collections def navi(y,x,dy,dx,path): move = [] ty = -1 tx = -1 while 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 move def 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] = True dq = 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] and maze[y+dy][x+dx]>=0: dq.append((y+dy,x+dx)) visited[y+dy][x+dx] = True path[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] = 1 posx = 19 posy = 19 dx = 0 dy = -1 tx = 19 ty = 19 path = [] move = [] while True: s = input() if s == 'Merry Christmas!': exit() s = int(s) if s > 17: maze[posy+dy][posx+dx] = 1 print('F') posy+=dy posx+=dx sys.stdout.flush() elif s == 0: maze[posy+dy][posx+dx] = -1 print('L') posy-=dy posx-=dx sys.stdout.flush() else: for i in range(1,s+1): maze[posy+dy*i][posx+dx*i] = 1 for j in range(40): print(''.join(str(e) for e in maze[j])) print() if move: m = move.pop() if m=='F': posy+=dy posx+=dx elif m=='B': posy-=dy posx-=dx elif m=='R': dy,dx = -dx,dy elif m=='L': dy,dx = dx,-dy print(m) sys.stdout.flush() else: i = 0 j = 0 while not path: path = accessible(posy,posx,i,j,maze) j += 1 if j == 40: j = 0 i += 1 move = navi(posy,posx,dy,dx,path) m = move.pop() if m=='F': posy+=dy posx+=dx elif m=='B': posy-=dy posx-=dx elif m=='R': dy,dx = -dx,dy elif m=='L': dy,dx = dx,-dy print(m) sys.stdout.flush()