結果

問題 No.5006 Hidden Maze
ユーザー kyskys
提出日時 2022-06-12 16:01:34
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 733 ms / 2,000 ms
コード長 4,658 bytes
コンパイル時間 262 ms
実行使用メモリ 103,120 KB
スコア 0
平均クエリ数 1000.00
最終ジャッジ日時 2022-06-12 16:06:36
合計ジャッジ時間 73,164 ms
ジャッジサーバーID
(参考情報)
judge11 / judge10
純コード判定しない問題か言語
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 605 ms
101,364 KB
testcase_01 AC 625 ms
101,560 KB
testcase_02 AC 652 ms
101,304 KB
testcase_03 AC 636 ms
101,452 KB
testcase_04 AC 604 ms
101,068 KB
testcase_05 AC 633 ms
101,004 KB
testcase_06 AC 677 ms
102,588 KB
testcase_07 AC 614 ms
101,044 KB
testcase_08 AC 637 ms
101,124 KB
testcase_09 AC 613 ms
101,728 KB
testcase_10 AC 595 ms
101,568 KB
testcase_11 AC 671 ms
101,340 KB
testcase_12 AC 614 ms
101,116 KB
testcase_13 AC 673 ms
101,592 KB
testcase_14 AC 653 ms
102,384 KB
testcase_15 AC 640 ms
100,824 KB
testcase_16 AC 653 ms
101,620 KB
testcase_17 AC 598 ms
100,672 KB
testcase_18 AC 629 ms
101,968 KB
testcase_19 AC 700 ms
102,884 KB
testcase_20 AC 623 ms
101,200 KB
testcase_21 AC 641 ms
101,256 KB
testcase_22 AC 612 ms
100,996 KB
testcase_23 AC 629 ms
101,792 KB
testcase_24 AC 635 ms
101,468 KB
testcase_25 AC 606 ms
100,416 KB
testcase_26 AC 642 ms
101,628 KB
testcase_27 AC 649 ms
101,496 KB
testcase_28 AC 637 ms
101,148 KB
testcase_29 AC 697 ms
103,120 KB
testcase_30 AC 624 ms
101,668 KB
testcase_31 AC 695 ms
102,984 KB
testcase_32 AC 639 ms
102,108 KB
testcase_33 AC 666 ms
101,988 KB
testcase_34 AC 613 ms
100,968 KB
testcase_35 AC 703 ms
102,136 KB
testcase_36 AC 605 ms
101,464 KB
testcase_37 AC 605 ms
101,804 KB
testcase_38 AC 647 ms
102,816 KB
testcase_39 AC 652 ms
101,608 KB
testcase_40 AC 673 ms
101,736 KB
testcase_41 AC 628 ms
101,524 KB
testcase_42 AC 586 ms
101,012 KB
testcase_43 AC 672 ms
102,704 KB
testcase_44 AC 633 ms
101,696 KB
testcase_45 AC 641 ms
101,564 KB
testcase_46 AC 612 ms
100,852 KB
testcase_47 AC 655 ms
101,444 KB
testcase_48 AC 636 ms
101,056 KB
testcase_49 AC 641 ms
101,688 KB
testcase_50 AC 656 ms
100,684 KB
testcase_51 AC 592 ms
100,828 KB
testcase_52 AC 628 ms
101,340 KB
testcase_53 AC 643 ms
101,076 KB
testcase_54 AC 629 ms
102,244 KB
testcase_55 AC 610 ms
101,936 KB
testcase_56 AC 651 ms
102,048 KB
testcase_57 AC 632 ms
102,272 KB
testcase_58 AC 653 ms
101,996 KB
testcase_59 AC 639 ms
101,572 KB
testcase_60 AC 660 ms
101,180 KB
testcase_61 AC 718 ms
102,292 KB
testcase_62 AC 625 ms
101,540 KB
testcase_63 AC 692 ms
102,848 KB
testcase_64 AC 707 ms
101,268 KB
testcase_65 AC 629 ms
100,768 KB
testcase_66 AC 671 ms
101,644 KB
testcase_67 AC 630 ms
101,008 KB
testcase_68 AC 579 ms
101,052 KB
testcase_69 AC 684 ms
101,916 KB
testcase_70 AC 623 ms
102,152 KB
testcase_71 AC 586 ms
101,260 KB
testcase_72 AC 668 ms
100,760 KB
testcase_73 AC 643 ms
101,588 KB
testcase_74 AC 679 ms
102,124 KB
testcase_75 AC 626 ms
100,416 KB
testcase_76 AC 655 ms
101,744 KB
testcase_77 AC 693 ms
102,396 KB
testcase_78 AC 620 ms
100,740 KB
testcase_79 AC 640 ms
100,560 KB
testcase_80 AC 654 ms
100,924 KB
testcase_81 AC 669 ms
102,100 KB
testcase_82 AC 652 ms
101,788 KB
testcase_83 AC 647 ms
101,320 KB
testcase_84 AC 693 ms
103,012 KB
testcase_85 AC 698 ms
102,640 KB
testcase_86 AC 733 ms
103,100 KB
testcase_87 AC 650 ms
101,420 KB
testcase_88 AC 676 ms
102,080 KB
testcase_89 AC 638 ms
101,532 KB
testcase_90 AC 630 ms
100,460 KB
testcase_91 AC 684 ms
101,476 KB
testcase_92 AC 598 ms
101,348 KB
testcase_93 AC 656 ms
100,692 KB
testcase_94 AC 625 ms
101,068 KB
testcase_95 AC 638 ms
100,552 KB
testcase_96 AC 655 ms
101,756 KB
testcase_97 AC 649 ms
101,404 KB
testcase_98 AC 649 ms
101,228 KB
testcase_99 AC 721 ms
102,964 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict, deque
import sys

input = sys.stdin.readline
def iinput(): return int(input())
def sinput(): return input().rstrip()
def i0input(): return int(input()) - 1
def linput(): return list(input().split())
def liinput(): return list(map(int, input().split()))
def miinput(): return map(int, input().split())
def li0input(): return list(map(lambda x: int(x) - 1, input().split()))
def mi0input(): return map(lambda x: int(x) - 1, input().split())
INF = 10**20
MOD = 1000000007
from random import random, seed
seed(101010)

class UnionFindTree:
    def __init__(self, initial_size:int) -> None:
        self.n_nodes = initial_size
        self.parents = [i for i in range(initial_size)]
        self.ranks = [0 for i in range(initial_size)]
        self.size = [1 for i in range(initial_size)]
        self.n_roots = initial_size
    def root(self, n:int) -> int:
        if self.parents[n] == n:
            return n
        else:
            self.parents[n] = self.root(self.parents[n])
            return self.parents[n]
    def same(self, n:int, m:int) -> bool:
        return (self.root(n) == self.root(m))
    def unite(self, n:int, m:int) -> None:
        if self.same(n, m):
            return
        self.n_roots -= 1
        n, m = self.root(n), self.root(m)
        if self.ranks[n] < self.ranks[m]:
            self.parents[n] = m
            self.size[m] += self.size[n]
        else:
            self.parents[m] = n
            self.size[n] += self.size[m]
            if self.ranks[n] == self.ranks[m]:
                self.ranks[n] += 1
    def get_roots(self) -> set:
        return set([self.root(x) for x in range(self.n_nodes)])
    def count_roots(self) -> int:
        return self.n_roots
    def get_tree_size(self, n:int) -> int:
        return self.size[self.root(n)]

def random_direction(p):
    for i in range(3):
        p[i+1] += p[i]
    r = random()
    for i in range(4):
        if p[i] > r:
            return i

H, W, p = liinput()
# URDL
probability = [[[0.25] * W for _ in [0] * H], [[0.75] * W for _ in [0] * H], [[0.25] * W for _ in [0] * H], [[0.50] * W for _ in [0] * H]]
p /= 100
direction_inv = {'U': 0, 'R': 1, 'D': 2, 'L': 3}
direction = 'URDL'
direction_coord = [(-1, 0), (0, 1), (1, 0), (0, -1)]
uf = UnionFindTree(H * W)

for i in range(W):
    probability[0][0][i] = 0
    probability[2][-1][i] = 0

for i in range(H):
    probability[1][i][-1] = 0
    probability[3][i][0] = 0

for _ in [0] * 1000:
    place = [0, 0]
    res = []
    for _ in [0] * 400:
        prob_tmp = []
        for i in range(4):
            try:
                prob_tmp.append(probability[i][place[0]][place[1]])
            except IndexError:
                print('IndexError', place)
        sum_prob = sum(prob_tmp)
        for i in range(4):
            prob_tmp[i] /= sum_prob
        d = random_direction(prob_tmp)
        dr, dc = direction_coord[d]
        place[0] += dr
        place[1] += dc
        res.append(direction[d])
    print(''.join(res), flush=True)
    thr = iinput()
    if thr == -1:
        exit()
    place = [0, 0]
    for i in range(thr):
        d = direction_inv[res[i]]
        probability[d][place[0]][place[1]] = 1
        dr, dc = direction_coord[d]
        uf.unite(place[0] * W + place[1], (place[0] + dr) * W + place[1] + dc)
        place[0] += dr
        place[1] += dc
        probability[(d+2)%4][place[0]][place[1]] = 1
    if len(res) > thr:
        d = direction_inv[res[thr]]
        q = probability[d][place[0]][place[1]]
        if q < 1:
            new_p = (p * q) / (p * q + 1 - q)
            probability[d][place[0]][place[1]] = new_p
            dr, dc = direction_coord[d]
            place[0] += dr
            place[1] += dc
            probability[(d+2)%4][place[0]][place[1]] = new_p
    if uf.same(0, H*W-1):
        seen = [[None] * W for _ in [0] * H]
        seen[0][0] = ''
        que = deque()
        que.append((0, 0))
        while que:
            x, y = que.popleft()
            for i in range(4):
                dx, dy = direction_coord[i]
                nx = x + dx
                ny = y + dy
                if nx < 0 or nx >= H or ny < 0 or ny >= W or not uf.same(x * W + y, nx * W + ny):
                    continue
                if seen[nx][ny] is not None:
                    continue
                seen[nx][ny] = seen[x][y] + direction[i]
                que.append((nx, ny))
                if nx == H-1 and ny == W-1:
                    print(seen[nx][ny], flush=True)
                    g = iinput()
                    if g == -1:
                        exit()
        for s in seen:
            print(s)
0