| 2026 USP Try-outs |
|---|
| Закончено |
After learning all competitive programming problems, GePeTo is now studying all board games in the world, and is particularly interested in a copy of Escape it found in your room.
In Escape, you have 5 identical six-sided dice, with the following faces:
In an important part of the game, you are given an objective, which is a multiset of up to 5 symbols selected from ATC. Your goal is to roll the dice and finish with their top faces showing at least the symbols required by the objective.
Starting from an initial roll of the 5 dice, you have a maximum of $$$K$$$ turns (rerolls) to achieve the objective. In each turn, you select a subset of the current dice and reroll them, subject to the following rules:
Assuming you play optimally, that is, making decisions each turn that maximize the probability of achieving the objective within $$$K$$$ turns, answer the following: What is the maximum probability of success, and what is an optimal first reroll?
The first line contains a single string $$$O$$$ consisting of characters from ATC, representing the objective. ($$$1 \leq |O| \leq 5$$$)
The second line contains an integer $$$T$$$, the number of test cases. ($$$1 \leq T \leq 10^4$$$)
Each of the next $$$T$$$ lines contains a string $$$S$$$ of exactly five characters from ATCND, representing your initial roll, and an integer $$$K$$$, the maximum number of rerolls you can perform. ($$$1 \leq K \leq 5$$$)
For each test case, print a string $$$R$$$ and a number $$$P$$$.
$$$R$$$ should be nonempty and contain up to five characters from ATCND, representing the dice that should be rerolled. It is guaranteed that the objective is not met initially, at least one reroll is possible, and the probability of winning is strictly positive (i.e., $$$P \gt 0$$$). The characters may be printed in any order.
The number $$$P$$$ should be the maximum probability of achieving the objective when playing optimally. The answer is considered correct if the absolute error does not exceed $$$10^{-4}$$$.
T4NNNNA 1NNNAA 1NNNNA 2AAAAA 1
A 0.1666666667 AA 0.3055555556 A 0.3202160494 AAAAA 0.5981224280
ATC4NTNAN 2TNCNT 1NTADD 1AATDT 5
AT 0.0543981481 T 0.3333333333 NDD 0.4212962963 AAT 0.9121533206
Here is an example of the game:
| Название |
|---|


