結果
問題 | No.5006 Hidden Maze |
ユーザー |
|
提出日時 | 2022-06-12 14:34:00 |
言語 | PyPy3 (7.3.15) |
結果 |
RE
|
実行時間 | - |
コード長 | 2,360 bytes |
コンパイル時間 | 570 ms |
実行使用メモリ | 101,176 KB |
スコア | 0 |
平均クエリ数 | 1.00 |
最終ジャッジ日時 | 2022-06-12 14:34:26 |
合計ジャッジ時間 | 23,589 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge13 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | RE * 100 |
ソースコード
import sysimport mathfrom bisect import bisect_right, bisect_leftfrom itertools import *from collections import *from heapq import heapify, heappush, heappopinf = float('inf')# mod = 1000000007# mod = 998244353input = lambda: sys.stdin.readline().rstrip()def error(*args, end='\n'):print(*args, end=end, file=sys.stderr)# sys.setrecursionlimit(10**6)##################def can_move(x, y, d):if d == 'U':if y and not v[y-1][x]:return 1elif d == 'D':if y < 19 and not v[y][x]:return 1elif d == 'L':if x and not h[y][x-1]:return 1elif d == 'R':if x < 19 and not h[y][x]:return 1return 0H, W, P = map(int, input().split())h = [[-1]*W for _ in range(H)]v = [[-1]*W for _ in range(W)]DIRECT = ['U', 'D', 'L', 'R']dx = [0, 0, -1, 1]dy = [1, -1, 0, 0]def bfs(si, sj):dist = [[-1]*20 for _ in range_20]dq = deque([(si, sj)])dist[si][sj] = 0while dq:nowy, nowx = dq.popleft()d = dist[nowy][nowx] + 1if can_move(nowx, nowy, 'D') and dist[nowy+1][nowx] == -1:dq.append((nowy+1, nowx))dist[nowy+1][nowx] = dif can_move(nowx, nowy, 'U') and dist[nowy-1][nowx] == -1:dq.append((nowy-1, nowx))dist[nowy-1][nowx] = dif can_move(nowx, nowy, 'R') and dist[nowy][nowx+1] == -1:dq.append((nowy, nowx+1))dist[nowy][nowx+1] = dif can_move(nowx, nowy, 'L') and dist[nowy][nowx-1] == -1:dq.append((nowy, nowx-1))dist[nowy][nowx-1] = dreturn distdef get_root(dist):root = []nowx, nowy = 19, 19while True:d = dist[nowy][nowx]if d == 0:breakif nowy+1 < 20 and v[nowy][nowx] == 0 and dist[nowy+1][nowx] == d-1:root.append('U')nowy += 1elif nowy-1 >= 0 and v[nowy-1][nowx] == 0 and dist[nowy-1][nowx] == d-1:root.append('D')nowy -= 1elif nowx+1 < 20 and h[nowy][nowx] == 0 and dist[nowy][nowx+1] == d-1:root.append('L')nowx += 1elif nowx-1 >= 0 and h[nowy][nowx-1] == 0 and dist[nowy][nowx-1] == d-1:root.append('R')nowx -= 1return list(reversed(root))ok = []trynum = 0while trynum < 1000:dist = bfs(0, 0)# solve?if dist[19][19] != -1:print(get_root(dist), flush=True)input()break# searchres = []print(''.join(res), flush=True)resnum = int(input())