結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 285 ms
98,528 KB
testcase_01 AC 364 ms
99,528 KB
testcase_02 AC 257 ms
98,196 KB
testcase_03 AC 198 ms
96,960 KB
testcase_04 AC 250 ms
98,656 KB
testcase_05 AC 334 ms
98,640 KB
testcase_06 AC 335 ms
98,576 KB
testcase_07 AC 346 ms
98,076 KB
testcase_08 AC 333 ms
98,260 KB
testcase_09 AC 345 ms
99,044 KB
testcase_10 AC 189 ms
97,272 KB
testcase_11 AC 222 ms
97,224 KB
testcase_12 AC 299 ms
98,360 KB
testcase_13 AC 271 ms
97,684 KB
testcase_14 AC 307 ms
98,304 KB
testcase_15 AC 336 ms
98,628 KB
testcase_16 AC 342 ms
98,704 KB
testcase_17 AC 193 ms
97,752 KB
testcase_18 AC 346 ms
98,148 KB
testcase_19 AC 340 ms
98,856 KB
testcase_20 AC 193 ms
97,464 KB
testcase_21 AC 221 ms
97,536 KB
testcase_22 AC 189 ms
97,196 KB
testcase_23 AC 220 ms
97,344 KB
testcase_24 AC 326 ms
98,656 KB
testcase_25 AC 349 ms
98,308 KB
testcase_26 AC 318 ms
98,852 KB
testcase_27 AC 304 ms
97,956 KB
testcase_28 AC 335 ms
98,708 KB
testcase_29 AC 221 ms
97,776 KB
testcase_30 AC 182 ms
97,000 KB
testcase_31 AC 183 ms
97,412 KB
testcase_32 AC 357 ms
98,900 KB
testcase_33 AC 196 ms
97,232 KB
testcase_34 AC 216 ms
97,832 KB
testcase_35 AC 217 ms
98,392 KB
testcase_36 AC 233 ms
97,540 KB
testcase_37 AC 329 ms
98,812 KB
testcase_38 AC 329 ms
98,668 KB
testcase_39 AC 219 ms
97,688 KB
testcase_40 AC 153 ms
96,880 KB
testcase_41 AC 177 ms
97,396 KB
testcase_42 AC 265 ms
98,392 KB
testcase_43 AC 330 ms
98,960 KB
testcase_44 AC 163 ms
97,256 KB
testcase_45 AC 332 ms
98,796 KB
testcase_46 AC 349 ms
97,864 KB
testcase_47 AC 177 ms
97,300 KB
testcase_48 AC 325 ms
98,676 KB
testcase_49 AC 319 ms
99,156 KB
testcase_50 AC 223 ms
97,908 KB
testcase_51 AC 233 ms
98,024 KB
testcase_52 AC 248 ms
98,308 KB
testcase_53 AC 320 ms
98,860 KB
testcase_54 AC 348 ms
98,900 KB
testcase_55 AC 267 ms
97,636 KB
testcase_56 AC 216 ms
97,260 KB
testcase_57 AC 333 ms
98,536 KB
testcase_58 AC 319 ms
98,320 KB
testcase_59 AC 329 ms
98,264 KB
testcase_60 AC 155 ms
97,020 KB
testcase_61 AC 213 ms
97,568 KB
testcase_62 AC 373 ms
99,608 KB
testcase_63 AC 347 ms
99,088 KB
testcase_64 AC 333 ms
98,488 KB
testcase_65 AC 313 ms
98,820 KB
testcase_66 AC 249 ms
97,908 KB
testcase_67 AC 264 ms
98,452 KB
testcase_68 AC 347 ms
98,784 KB
testcase_69 AC 331 ms
98,352 KB
testcase_70 AC 178 ms
97,068 KB
testcase_71 AC 191 ms
97,072 KB
testcase_72 AC 268 ms
98,028 KB
testcase_73 AC 346 ms
99,040 KB
testcase_74 AC 342 ms
98,240 KB
testcase_75 AC 339 ms
98,456 KB
testcase_76 AC 384 ms
99,484 KB
testcase_77 AC 335 ms
98,204 KB
testcase_78 AC 346 ms
98,628 KB
testcase_79 AC 321 ms
98,000 KB
testcase_80 AC 251 ms
97,956 KB
testcase_81 AC 224 ms
97,564 KB
testcase_82 AC 330 ms
98,784 KB
testcase_83 AC 169 ms
97,056 KB
testcase_84 AC 159 ms
97,124 KB
testcase_85 AC 338 ms
98,208 KB
testcase_86 AC 276 ms
98,336 KB
testcase_87 AC 327 ms
99,040 KB
testcase_88 AC 323 ms
98,244 KB
testcase_89 AC 372 ms
98,860 KB
testcase_90 AC 344 ms
98,296 KB
testcase_91 AC 172 ms
97,236 KB
testcase_92 AC 339 ms
98,448 KB
testcase_93 AC 246 ms
97,980 KB
testcase_94 AC 322 ms
98,732 KB
testcase_95 AC 354 ms
98,392 KB
testcase_96 AC 159 ms
97,244 KB
testcase_97 AC 328 ms
98,368 KB
testcase_98 AC 332 ms
98,128 KB
testcase_99 AC 351 ms
98,236 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//3):
        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