結果

問題 No.5006 Hidden Maze
ユーザー titan23titan23
提出日時 2022-06-12 15:01:26
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 342 ms / 2,000 ms
コード長 3,967 bytes
コンパイル時間 410 ms
実行使用メモリ 100,448 KB
スコア 0
平均クエリ数 992.00
最終ジャッジ日時 2022-06-12 15:02:22
合計ジャッジ時間 34,974 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
純コード判定しない問題か言語
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 299 ms
98,908 KB
testcase_01 AC 278 ms
98,732 KB
testcase_02 AC 305 ms
99,944 KB
testcase_03 AC 306 ms
100,448 KB
testcase_04 AC 302 ms
99,280 KB
testcase_05 AC 299 ms
99,744 KB
testcase_06 AC 309 ms
99,856 KB
testcase_07 AC 308 ms
99,168 KB
testcase_08 AC 284 ms
99,152 KB
testcase_09 AC 284 ms
98,616 KB
testcase_10 AC 285 ms
99,156 KB
testcase_11 AC 309 ms
99,700 KB
testcase_12 AC 297 ms
99,804 KB
testcase_13 AC 315 ms
100,104 KB
testcase_14 AC 290 ms
99,820 KB
testcase_15 AC 309 ms
99,784 KB
testcase_16 AC 291 ms
99,564 KB
testcase_17 AC 304 ms
99,532 KB
testcase_18 AC 268 ms
99,304 KB
testcase_19 AC 304 ms
99,568 KB
testcase_20 AC 321 ms
100,308 KB
testcase_21 AC 304 ms
99,724 KB
testcase_22 AC 312 ms
99,476 KB
testcase_23 AC 312 ms
100,308 KB
testcase_24 AC 299 ms
99,696 KB
testcase_25 AC 318 ms
99,312 KB
testcase_26 AC 282 ms
98,840 KB
testcase_27 AC 298 ms
99,688 KB
testcase_28 AC 270 ms
99,536 KB
testcase_29 AC 288 ms
99,212 KB
testcase_30 AC 310 ms
98,752 KB
testcase_31 AC 312 ms
100,004 KB
testcase_32 AC 294 ms
99,672 KB
testcase_33 AC 310 ms
99,684 KB
testcase_34 AC 291 ms
99,488 KB
testcase_35 AC 298 ms
99,256 KB
testcase_36 AC 296 ms
99,472 KB
testcase_37 AC 301 ms
99,452 KB
testcase_38 AC 304 ms
99,596 KB
testcase_39 AC 286 ms
99,224 KB
testcase_40 AC 308 ms
99,840 KB
testcase_41 AC 296 ms
99,756 KB
testcase_42 AC 306 ms
99,084 KB
testcase_43 AC 307 ms
99,060 KB
testcase_44 AC 292 ms
98,968 KB
testcase_45 AC 307 ms
99,528 KB
testcase_46 AC 285 ms
98,748 KB
testcase_47 AC 293 ms
99,540 KB
testcase_48 AC 297 ms
99,264 KB
testcase_49 AC 267 ms
98,976 KB
testcase_50 AC 283 ms
99,724 KB
testcase_51 AC 316 ms
99,820 KB
testcase_52 AC 305 ms
99,476 KB
testcase_53 AC 299 ms
99,444 KB
testcase_54 AC 286 ms
99,624 KB
testcase_55 AC 309 ms
99,116 KB
testcase_56 AC 290 ms
99,416 KB
testcase_57 AC 286 ms
99,872 KB
testcase_58 AC 280 ms
99,240 KB
testcase_59 AC 281 ms
99,636 KB
testcase_60 AC 296 ms
99,468 KB
testcase_61 AC 289 ms
99,332 KB
testcase_62 AC 323 ms
99,552 KB
testcase_63 AC 279 ms
99,548 KB
testcase_64 AC 289 ms
99,328 KB
testcase_65 AC 296 ms
99,560 KB
testcase_66 AC 292 ms
99,336 KB
testcase_67 AC 284 ms
99,336 KB
testcase_68 AC 301 ms
99,748 KB
testcase_69 AC 281 ms
99,468 KB
testcase_70 AC 317 ms
100,184 KB
testcase_71 AC 342 ms
99,496 KB
testcase_72 AC 306 ms
99,996 KB
testcase_73 AC 298 ms
99,304 KB
testcase_74 AC 321 ms
99,420 KB
testcase_75 AC 289 ms
98,832 KB
testcase_76 AC 289 ms
99,904 KB
testcase_77 AC 271 ms
99,220 KB
testcase_78 AC 293 ms
99,356 KB
testcase_79 AC 276 ms
99,092 KB
testcase_80 AC 334 ms
99,920 KB
testcase_81 AC 314 ms
99,668 KB
testcase_82 AC 302 ms
99,264 KB
testcase_83 AC 299 ms
99,784 KB
testcase_84 AC 286 ms
99,576 KB
testcase_85 AC 289 ms
99,536 KB
testcase_86 AC 292 ms
99,388 KB
testcase_87 AC 296 ms
99,280 KB
testcase_88 AC 266 ms
98,704 KB
testcase_89 AC 311 ms
99,204 KB
testcase_90 AC 294 ms
99,068 KB
testcase_91 AC 289 ms
99,776 KB
testcase_92 AC 290 ms
100,236 KB
testcase_93 AC 302 ms
100,084 KB
testcase_94 AC 299 ms
99,784 KB
testcase_95 AC 287 ms
99,888 KB
testcase_96 AC 290 ms
99,452 KB
testcase_97 AC 277 ms
99,192 KB
testcase_98 AC 281 ms
99,620 KB
testcase_99 AC 286 ms
99,120 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
import math
from bisect import bisect_right, bisect_left
from itertools import *
from collections import *
from heapq import heapify, heappush, heappop
inf = float('inf')
# mod = 1000000007
# mod = 998244353
input = lambda: sys.stdin.readline().rstrip()
def error(*args, sep=' ', end='\n'):
  print(*args, sep=sep, end=end, file=sys.stderr)
# sys.setrecursionlimit(10**6)
import random

random.seed = 148


##################

def can_move(x, y, d):
  if d == 'U':
    if y and v[y-1][x] == 0:
      return 1
  elif d == 'D':
    if y < 19 and v[y][x] == 0:
      return 1
  elif d == 'L':
    if x and h[y][x-1] == 0:
      return 1
  elif d == 'R':
    if x < 19 and h[y][x] == 0:
      return 1
  return 0

def cannot_move(x, y, d):
  if d == 'U':
    if y and v[y-1][x] == 1:
      return 1
  elif d == 'D':
    if y < 19 and v[y][x] == 1:
      return 1
  elif d == 'L':
    if x and h[y][x-1] == 1:
      return 1
  elif d == 'R':
    if x < 19 and h[y][x] == 1:
      return 1
  return 0

def change_yx(y, x, d):
  if d == 'U': y -= 1
  if d == 'D': y += 1
  if d == 'L': x -= 1
  if d == 'R': x += 1
  return (y, x)

def wall_nasi(res):
  dq = deque(res)
  nowy, nowx = 0, 0
  while dq:
    d = dq.popleft()
    move(nowx, nowy, d)
    nowy, nowx = change_yx(nowy, nowx, d)

def move(x, y, d):
  if d == 'U':
    v[y-1][x] = 0
  if d == 'D':
    v[y][x] = 0
  if d == 'L':
    h[y][x-1] = 0
  if d == 'R':
    h[y][x] = 0

def wall_ari(res):
  dq = deque(res)
  nowy, nowx = 0, 0
  while dq:
    d = dq.popleft()
    if cannot_move(nowx, nowy, d):
      move1(nowx, nowy, d)
      break
    nowy, nowx = change_yx(nowy, nowx, d)

def move1(x, y, d):
  if d == 'U':
    v[y-1][x] = 1
  if d == 'D':
    v[y][x] = 1
  if d == 'L':
    h[y][x-1] = 1
  if d == 'R':
    h[y][x] = 1


H, W, P = map(int, input().split())
h = [[-1]*20 for _ in range(20)]
v = [[-1]*20 for _ in range(20)]
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] = 0 
  while dq:
    nowy, nowx = dq.popleft()
    d = dist[nowy][nowx] + 1
    if can_move(nowx, nowy, 'D') and dist[nowy+1][nowx] == -1:
      dq.append((nowy+1, nowx))
      dist[nowy+1][nowx] = d
    if can_move(nowx, nowy, 'U') and dist[nowy-1][nowx] == -1:
      dq.append((nowy-1, nowx))
      dist[nowy-1][nowx] = d
    if can_move(nowx, nowy, 'R') and dist[nowy][nowx+1] == -1:
      dq.append((nowy, nowx+1))
      dist[nowy][nowx+1] = d
    if can_move(nowx, nowy, 'L') and dist[nowy][nowx-1] == -1:
      dq.append((nowy, nowx-1))
      dist[nowy][nowx-1] = d
  return dist
def get_root(dist, nowy, nowx):
  root = []
  while True:
    d = dist[nowy][nowx]
    if d == 0:
      break
    if   nowy+1 < 20 and v[nowy][nowx] == 0 and dist[nowy+1][nowx] == d-1:
      root.append('U')
      nowy += 1
    elif nowy-1 >= 0 and v[nowy-1][nowx] == 0 and dist[nowy-1][nowx] == d-1:
      root.append('D')
      nowy -= 1
    elif nowx+1 < 20 and h[nowy][nowx] == 0 and dist[nowy][nowx+1] == d-1:
      root.append('L')
      nowx += 1
    elif nowx-1 >= 0 and h[nowy][nowx-1] == 0 and dist[nowy][nowx-1] == d-1:
      root.append('R')
      nowx -= 1
  return list(reversed(root))

breakflag = False
ok = []
trynum = 0
while trynum < 990:
  dist = bfs(0, 0)
  # solve?
  if dist[19][19] != -1:
    print(get_root(dist, 19, 19), flush=True)
    input()
    break

  # search
  indx = []
  for i in range(20):
    for j in range(20):
      if dist[i][j] != -1:
        indx.append((i, j))
  gy, gx = random.choice(indx)
  ans = get_root(dist, gy, gx)
  # error(*dist, sep='\n')
  for i in range(4):
    res = ans[:]
    res.append(DIRECT[i])
    pred = len(res)
    print(''.join(res), flush=True)
    trynum += 1
    resnum = int(input())
    if resnum == -1:
      breakflag = True
      break
    if pred == resnum:
      wall_nasi(res)
    else:
      wall_ari(res)  
  if breakflag:
    break

0