結果

問題 No.5006 Hidden Maze
ユーザー brthyyjpbrthyyjp
提出日時 2022-06-12 15:02:24
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 285 ms / 2,000 ms
コード長 2,191 bytes
コンパイル時間 215 ms
実行使用メモリ 100,144 KB
スコア 15,806
平均クエリ数 842.11
最終ジャッジ日時 2022-06-12 15:02:54
合計ジャッジ時間 28,416 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
純コード判定しない問題か言語
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 267 ms
98,256 KB
testcase_01 AC 245 ms
98,688 KB
testcase_02 AC 169 ms
96,864 KB
testcase_03 AC 258 ms
99,004 KB
testcase_04 AC 257 ms
99,240 KB
testcase_05 AC 264 ms
99,680 KB
testcase_06 AC 245 ms
99,012 KB
testcase_07 AC 255 ms
99,328 KB
testcase_08 AC 247 ms
98,872 KB
testcase_09 AC 239 ms
97,952 KB
testcase_10 AC 173 ms
97,148 KB
testcase_11 AC 246 ms
98,788 KB
testcase_12 AC 272 ms
99,328 KB
testcase_13 AC 266 ms
99,612 KB
testcase_14 AC 245 ms
97,776 KB
testcase_15 AC 246 ms
98,388 KB
testcase_16 AC 238 ms
98,428 KB
testcase_17 AC 237 ms
98,468 KB
testcase_18 AC 238 ms
98,024 KB
testcase_19 AC 247 ms
98,368 KB
testcase_20 AC 250 ms
99,220 KB
testcase_21 AC 235 ms
98,028 KB
testcase_22 AC 156 ms
97,492 KB
testcase_23 AC 239 ms
98,584 KB
testcase_24 AC 250 ms
99,048 KB
testcase_25 AC 253 ms
98,944 KB
testcase_26 AC 241 ms
98,232 KB
testcase_27 AC 281 ms
99,416 KB
testcase_28 AC 241 ms
98,736 KB
testcase_29 AC 153 ms
97,336 KB
testcase_30 AC 252 ms
99,564 KB
testcase_31 AC 249 ms
99,548 KB
testcase_32 AC 239 ms
98,548 KB
testcase_33 AC 262 ms
98,708 KB
testcase_34 AC 246 ms
97,904 KB
testcase_35 AC 250 ms
99,224 KB
testcase_36 AC 266 ms
98,408 KB
testcase_37 AC 240 ms
98,656 KB
testcase_38 AC 232 ms
98,372 KB
testcase_39 AC 259 ms
99,000 KB
testcase_40 AC 154 ms
97,324 KB
testcase_41 AC 169 ms
96,868 KB
testcase_42 AC 262 ms
99,056 KB
testcase_43 AC 249 ms
98,184 KB
testcase_44 AC 241 ms
98,348 KB
testcase_45 AC 259 ms
98,212 KB
testcase_46 AC 241 ms
98,948 KB
testcase_47 AC 241 ms
97,908 KB
testcase_48 AC 258 ms
98,480 KB
testcase_49 AC 262 ms
99,200 KB
testcase_50 AC 255 ms
99,420 KB
testcase_51 AC 167 ms
97,632 KB
testcase_52 AC 271 ms
99,792 KB
testcase_53 AC 260 ms
99,536 KB
testcase_54 AC 260 ms
98,848 KB
testcase_55 AC 261 ms
98,696 KB
testcase_56 AC 241 ms
98,308 KB
testcase_57 AC 244 ms
98,220 KB
testcase_58 AC 253 ms
99,580 KB
testcase_59 AC 285 ms
98,592 KB
testcase_60 AC 147 ms
97,084 KB
testcase_61 AC 177 ms
97,516 KB
testcase_62 AC 235 ms
98,284 KB
testcase_63 AC 272 ms
99,384 KB
testcase_64 AC 270 ms
99,080 KB
testcase_65 AC 171 ms
97,024 KB
testcase_66 AC 168 ms
97,092 KB
testcase_67 AC 235 ms
98,916 KB
testcase_68 AC 251 ms
99,472 KB
testcase_69 AC 245 ms
98,724 KB
testcase_70 AC 179 ms
97,828 KB
testcase_71 AC 255 ms
99,204 KB
testcase_72 AC 265 ms
99,100 KB
testcase_73 AC 239 ms
98,236 KB
testcase_74 AC 244 ms
98,000 KB
testcase_75 AC 249 ms
98,216 KB
testcase_76 AC 254 ms
99,180 KB
testcase_77 AC 259 ms
98,088 KB
testcase_78 AC 245 ms
98,156 KB
testcase_79 AC 243 ms
98,388 KB
testcase_80 AC 158 ms
96,832 KB
testcase_81 AC 239 ms
98,616 KB
testcase_82 AC 236 ms
98,612 KB
testcase_83 AC 158 ms
97,268 KB
testcase_84 AC 160 ms
97,436 KB
testcase_85 AC 280 ms
100,144 KB
testcase_86 AC 253 ms
98,784 KB
testcase_87 AC 235 ms
98,144 KB
testcase_88 AC 255 ms
99,280 KB
testcase_89 AC 251 ms
98,816 KB
testcase_90 AC 268 ms
99,092 KB
testcase_91 AC 147 ms
97,516 KB
testcase_92 AC 264 ms
98,200 KB
testcase_93 AC 248 ms
99,832 KB
testcase_94 AC 249 ms
98,412 KB
testcase_95 AC 261 ms
99,196 KB
testcase_96 AC 166 ms
97,124 KB
testcase_97 AC 246 ms
98,760 KB
testcase_98 AC 249 ms
99,084 KB
testcase_99 AC 251 ms
98,772 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 = 1000

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//2):
    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)
        reconst(s, max(v0, v1))
    else:
        s = ['D']*(h-1)+['R']*(w-1)
        v0 = query(s)
        v1 = query(s)
        reconst(s, max(v0, v1))
0