結果
問題 | No.5006 Hidden Maze |
ユーザー |
|
提出日時 | 2022-06-12 15:29:13 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 689 ms / 2,000 ms |
コード長 | 2,456 bytes |
コンパイル時間 | 610 ms |
実行使用メモリ | 102,240 KB |
スコア | 0 |
平均クエリ数 | 1000.00 |
最終ジャッジ日時 | 2022-06-12 15:31:12 |
合計ジャッジ時間 | 62,463 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge14 |
純コード判定しない問題か言語 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 100 |
ソースコード
import sysinput = sys.stdin.readlinedef iinput(): return int(input())def sinput(): return input().rstrip()def i0input(): return int(input()) - 1def 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**20MOD = 1000000007from random import random, seedseed(101010)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 iH, W, p = liinput()# URDLprobability = [[[0.75] * W for _ in [0] * H] for _ in [0] * 4]p /= 100direction_inv = {'U': 0, 'R': 1, 'D': 2, 'L': 3}direction = 'URDL'direction_coord = [(-1, 0), (0, 1), (1, 0), (0, -1)]for i in range(W):probability[0][0][i] = 0probability[2][-1][i] = 0for i in range(H):probability[1][i][-1] = 0probability[3][i][0] = 0for _ 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_probd = random_direction(prob_tmp)dr, dc = direction_coord[d]place[0] += drplace[1] += dcres.append(direction[d])print(''.join(res), flush=True)thr = iinput()if thr == -1:exit()place = [0, 0]for i in range(thr):if place == [H-1, W-1]:print(''.join(res)[:i+1], flush=True)g = iinput()if g == -1:exit()d = direction_inv[res[i]]probability[d][place[0]][place[1]] = 1dr, dc = direction_coord[d]place[0] += drplace[1] += dcprobability[(d+2)%4][place[0]][place[1]] = 1if 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_pdr, dc = direction_coord[d]place[0] += drplace[1] += dcprobability[(d+2)%4][place[0]][place[1]] = new_p