結果

問題 No.5006 Hidden Maze
ユーザー brthyyjpbrthyyjp
提出日時 2022-06-12 17:06:51
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 357 ms / 2,000 ms
コード長 2,466 bytes
コンパイル時間 345 ms
実行使用メモリ 99,920 KB
スコア 36,950
平均クエリ数 631.50
最終ジャッジ日時 2022-06-12 17:07:25
合計ジャッジ時間 32,752 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
純コード判定しない問題か言語
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 272 ms
98,416 KB
testcase_01 AC 357 ms
99,392 KB
testcase_02 AC 253 ms
98,200 KB
testcase_03 AC 200 ms
97,056 KB
testcase_04 AC 243 ms
98,240 KB
testcase_05 AC 327 ms
99,204 KB
testcase_06 AC 326 ms
98,372 KB
testcase_07 AC 315 ms
98,712 KB
testcase_08 AC 317 ms
98,464 KB
testcase_09 AC 328 ms
98,684 KB
testcase_10 AC 181 ms
96,904 KB
testcase_11 AC 204 ms
97,332 KB
testcase_12 AC 293 ms
98,580 KB
testcase_13 AC 247 ms
98,252 KB
testcase_14 AC 309 ms
98,732 KB
testcase_15 AC 345 ms
99,020 KB
testcase_16 AC 332 ms
98,312 KB
testcase_17 AC 192 ms
97,256 KB
testcase_18 AC 318 ms
98,392 KB
testcase_19 AC 337 ms
98,828 KB
testcase_20 AC 198 ms
97,476 KB
testcase_21 AC 224 ms
98,228 KB
testcase_22 AC 186 ms
96,888 KB
testcase_23 AC 208 ms
97,688 KB
testcase_24 AC 326 ms
98,488 KB
testcase_25 AC 318 ms
98,912 KB
testcase_26 AC 326 ms
98,856 KB
testcase_27 AC 304 ms
97,916 KB
testcase_28 AC 334 ms
98,428 KB
testcase_29 AC 239 ms
97,780 KB
testcase_30 AC 186 ms
96,920 KB
testcase_31 AC 184 ms
97,396 KB
testcase_32 AC 342 ms
99,100 KB
testcase_33 AC 189 ms
97,428 KB
testcase_34 AC 209 ms
97,460 KB
testcase_35 AC 215 ms
97,560 KB
testcase_36 AC 226 ms
97,976 KB
testcase_37 AC 326 ms
98,564 KB
testcase_38 AC 309 ms
98,056 KB
testcase_39 AC 209 ms
98,112 KB
testcase_40 AC 162 ms
97,432 KB
testcase_41 AC 187 ms
96,952 KB
testcase_42 AC 262 ms
98,348 KB
testcase_43 AC 324 ms
98,236 KB
testcase_44 AC 155 ms
97,404 KB
testcase_45 AC 318 ms
98,608 KB
testcase_46 AC 310 ms
98,124 KB
testcase_47 AC 173 ms
97,164 KB
testcase_48 AC 325 ms
98,772 KB
testcase_49 AC 310 ms
99,736 KB
testcase_50 AC 216 ms
97,888 KB
testcase_51 AC 231 ms
98,144 KB
testcase_52 AC 248 ms
98,012 KB
testcase_53 AC 320 ms
98,684 KB
testcase_54 AC 354 ms
98,472 KB
testcase_55 AC 256 ms
98,304 KB
testcase_56 AC 238 ms
97,884 KB
testcase_57 AC 327 ms
98,264 KB
testcase_58 AC 314 ms
98,548 KB
testcase_59 AC 303 ms
98,800 KB
testcase_60 AC 153 ms
97,564 KB
testcase_61 AC 184 ms
96,952 KB
testcase_62 AC 352 ms
98,868 KB
testcase_63 AC 336 ms
98,388 KB
testcase_64 AC 329 ms
98,752 KB
testcase_65 AC 312 ms
98,672 KB
testcase_66 AC 253 ms
97,900 KB
testcase_67 AC 233 ms
98,212 KB
testcase_68 AC 303 ms
98,260 KB
testcase_69 AC 304 ms
98,624 KB
testcase_70 AC 175 ms
97,320 KB
testcase_71 AC 187 ms
97,068 KB
testcase_72 AC 252 ms
98,660 KB
testcase_73 AC 330 ms
99,040 KB
testcase_74 AC 320 ms
98,352 KB
testcase_75 AC 298 ms
98,260 KB
testcase_76 AC 344 ms
99,920 KB
testcase_77 AC 317 ms
98,932 KB
testcase_78 AC 329 ms
98,576 KB
testcase_79 AC 306 ms
98,192 KB
testcase_80 AC 243 ms
98,120 KB
testcase_81 AC 219 ms
97,616 KB
testcase_82 AC 305 ms
98,908 KB
testcase_83 AC 168 ms
97,340 KB
testcase_84 AC 161 ms
97,048 KB
testcase_85 AC 324 ms
99,024 KB
testcase_86 AC 262 ms
98,436 KB
testcase_87 AC 322 ms
98,524 KB
testcase_88 AC 302 ms
98,148 KB
testcase_89 AC 326 ms
98,592 KB
testcase_90 AC 342 ms
98,472 KB
testcase_91 AC 177 ms
97,104 KB
testcase_92 AC 348 ms
98,352 KB
testcase_93 AC 246 ms
98,156 KB
testcase_94 AC 305 ms
98,580 KB
testcase_95 AC 337 ms
98,664 KB
testcase_96 AC 165 ms
96,796 KB
testcase_97 AC 318 ms
98,464 KB
testcase_98 AC 313 ms
98,524 KB
testcase_99 AC 324 ms
98,412 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque

def query(s):
    print(''.join(s), flush = True)
    v = int(input())
    if v == -1:
        exit()
    return v

dys = (0, 1, 0, -1)
dxs = (-1, 0, 1, 0)
direcs = "LDRU"
toid = {'L':0, 'D':1, 'R':2, 'U':3}

def reconst(s, l):
    y, x = 0, 0
    for i in range(l):
        dir = toid[s[i]]
        if dir == 0:
            ver[y][x] = 0
        elif dir == 1:
            hor[y+1][x] = 0
        elif dir == 2:
            ver[y][x+1] = 0
        else:
            hor[y][x] = 0
        dy, dx = dys[dir], dxs[dir]
        y, x = y+dy, x+dx
    dir = toid[s[l]]
    if dir == 0:
        ver[y][x] = 1
    elif dir == 1:
        hor[y+1][x] = 1
    elif dir == 2:
        ver[y][x+1] = 1
    else:
        hor[y][x] = 1

h, w, p = map(int, input().split())

start = 0
goal = (h-1)*w+w-1
maxT = 1001
cnt = 0
while cnt < maxT:
    hor = [[-1]*w for i in range(h+1)]
    ver = [[-1]*(w+1) for i in range(h)]

    for x in range(w):
        hor[0][x] = 1
        hor[h][x] = 1

    for y in range(h):
        ver[y][0] = 1
        ver[y][w] = 1

    for iter in range(maxT):
        q = deque([])
        q.append(0)
        prev = [-1]*(h*w)
        direction = [-1]*(h*w)
        visit = [False]*(h*w)
        visit[0] = True
        while q:
            v = q.popleft()
            y, x = divmod(v, w)
            for i in range(4):
                dy, dx = dys[i], dxs[i]
                ny = y + dy
                nx = x + dx
                if not (0 <= ny < h and 0 <= nx < w):
                    continue
                if (dx==-1 and ver[y][x]!=1) or (dx==1 and ver[y][x+1] != 1) or (dy==-1 and hor[y][x]!=1) or (dy==1 and hor[y+1][x]!=1):
                    nv = ny*w+nx
                    if not visit[nv]:
                        q.append(nv)
                        prev[nv] = v
                        direction[nv] = i
                        visit[nv] = True
        if visit[goal]:
            cur = goal
            s = []
            while cur != -1:
                if cur != start:
                    dir = direction[cur]
                    s.append(direcs[dir])
                cur = prev[cur]
            s.reverse()
            v0 = query(s)
            v1 = query(s)
            if v0 == v1:
                reconst(s, max(v0, v1))
                cnt += 2
            else:
                v2 = query(s)
                reconst(s, max(v0, v1, v2))
                cnt += 3
        else:
            break
0