結果

問題 No.5006 Hidden Maze
ユーザー kyskys
提出日時 2022-06-12 17:08:56
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 921 ms / 2,000 ms
コード長 5,281 bytes
コンパイル時間 226 ms
実行使用メモリ 107,368 KB
スコア 0
平均クエリ数 1000.00
最終ジャッジ日時 2022-06-12 17:10:25
合計ジャッジ時間 84,341 ms
ジャッジサーバーID
(参考情報)
judge12 / judge10
純コード判定しない問題か言語
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 819 ms
103,300 KB
testcase_01 AC 697 ms
102,424 KB
testcase_02 AC 783 ms
102,620 KB
testcase_03 AC 718 ms
102,696 KB
testcase_04 AC 795 ms
103,092 KB
testcase_05 AC 786 ms
102,920 KB
testcase_06 AC 775 ms
102,432 KB
testcase_07 AC 763 ms
103,020 KB
testcase_08 AC 753 ms
103,296 KB
testcase_09 AC 751 ms
104,104 KB
testcase_10 AC 742 ms
102,764 KB
testcase_11 AC 731 ms
102,860 KB
testcase_12 AC 724 ms
103,252 KB
testcase_13 AC 783 ms
103,844 KB
testcase_14 AC 745 ms
103,408 KB
testcase_15 AC 799 ms
102,896 KB
testcase_16 AC 757 ms
103,232 KB
testcase_17 AC 794 ms
103,828 KB
testcase_18 AC 692 ms
103,108 KB
testcase_19 AC 736 ms
102,204 KB
testcase_20 AC 750 ms
103,900 KB
testcase_21 AC 780 ms
102,900 KB
testcase_22 AC 725 ms
102,000 KB
testcase_23 AC 792 ms
102,688 KB
testcase_24 AC 766 ms
103,944 KB
testcase_25 AC 806 ms
103,432 KB
testcase_26 AC 799 ms
103,608 KB
testcase_27 AC 921 ms
104,600 KB
testcase_28 AC 904 ms
107,368 KB
testcase_29 AC 757 ms
102,364 KB
testcase_30 AC 798 ms
103,036 KB
testcase_31 AC 838 ms
103,244 KB
testcase_32 AC 750 ms
102,484 KB
testcase_33 AC 823 ms
103,716 KB
testcase_34 AC 796 ms
103,304 KB
testcase_35 AC 858 ms
104,296 KB
testcase_36 AC 814 ms
102,544 KB
testcase_37 AC 738 ms
104,040 KB
testcase_38 AC 775 ms
102,888 KB
testcase_39 AC 756 ms
102,660 KB
testcase_40 AC 829 ms
103,308 KB
testcase_41 AC 756 ms
103,508 KB
testcase_42 AC 788 ms
102,956 KB
testcase_43 AC 785 ms
103,216 KB
testcase_44 AC 803 ms
102,892 KB
testcase_45 AC 791 ms
102,856 KB
testcase_46 AC 866 ms
105,308 KB
testcase_47 AC 785 ms
102,352 KB
testcase_48 AC 826 ms
104,640 KB
testcase_49 AC 754 ms
103,156 KB
testcase_50 AC 819 ms
103,644 KB
testcase_51 AC 779 ms
102,680 KB
testcase_52 AC 823 ms
103,152 KB
testcase_53 AC 834 ms
103,668 KB
testcase_54 AC 814 ms
103,216 KB
testcase_55 AC 737 ms
103,036 KB
testcase_56 AC 787 ms
104,724 KB
testcase_57 AC 771 ms
103,480 KB
testcase_58 AC 881 ms
105,108 KB
testcase_59 AC 714 ms
102,896 KB
testcase_60 AC 800 ms
102,356 KB
testcase_61 AC 869 ms
104,452 KB
testcase_62 AC 773 ms
103,836 KB
testcase_63 AC 771 ms
103,820 KB
testcase_64 AC 838 ms
104,724 KB
testcase_65 AC 815 ms
103,452 KB
testcase_66 AC 803 ms
102,268 KB
testcase_67 AC 705 ms
101,748 KB
testcase_68 AC 805 ms
105,044 KB
testcase_69 AC 792 ms
104,324 KB
testcase_70 AC 801 ms
103,652 KB
testcase_71 AC 714 ms
102,424 KB
testcase_72 AC 915 ms
106,080 KB
testcase_73 AC 752 ms
102,612 KB
testcase_74 AC 715 ms
102,412 KB
testcase_75 AC 735 ms
102,472 KB
testcase_76 AC 747 ms
104,664 KB
testcase_77 AC 735 ms
101,684 KB
testcase_78 AC 755 ms
104,496 KB
testcase_79 AC 771 ms
103,104 KB
testcase_80 AC 747 ms
102,124 KB
testcase_81 AC 779 ms
104,208 KB
testcase_82 AC 706 ms
103,336 KB
testcase_83 AC 809 ms
103,620 KB
testcase_84 AC 726 ms
102,440 KB
testcase_85 AC 733 ms
102,832 KB
testcase_86 AC 856 ms
104,320 KB
testcase_87 AC 795 ms
103,112 KB
testcase_88 AC 842 ms
103,888 KB
testcase_89 AC 819 ms
104,204 KB
testcase_90 AC 728 ms
102,732 KB
testcase_91 AC 813 ms
103,528 KB
testcase_92 AC 775 ms
103,036 KB
testcase_93 AC 788 ms
103,192 KB
testcase_94 AC 767 ms
102,732 KB
testcase_95 AC 791 ms
103,884 KB
testcase_96 AC 765 ms
103,296 KB
testcase_97 AC 778 ms
103,296 KB
testcase_98 AC 755 ms
102,820 KB
testcase_99 AC 795 ms
102,648 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque
import sys
from math import sqrt

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.99] * W for _ in [0] * H], [[0.99] * W for _ in [0] * H], [[0.99] * W for _ in [0] * H], [[0.99] * 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 = []
    seen = [[False] * W for _ in [0] * H]
    seen[0][0] = True
    for _ in [0] * 400:
        prob_tmp = []
        for i in range(4):
            try:
                dr, dc = direction_coord[i]
                nx = place[0] + dr
                ny = place[1] + dc
                if nx < 0 or nx >= H or ny < 0 or ny >= W or seen[nx][ny]:
                    prob_tmp.append(0)
                else:
                    prob_tmp.append(probability[i][place[0]][place[1]])
            except IndexError:
                print('IndexError', place)
        sum_prob = sum(prob_tmp)
        if sum_prob == 0:
            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
        seen[place[0]][place[1]] = True
        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 = sqrt((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()
0