406789: GYM102556 E Riana's Excruciating Enhancement Enigma

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

E. Riana's Excruciating Enhancement Enigmatime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output

After a long week of orgwork and acads, Riana spends her Saturday evenings unwinding on the famous MMORPG Blue Eagle Online. Here, she is not Riana, CompSAt president and model student—she is the infamous $$$\texttt{r}\color{red}{\texttt{airay}}$$$, Lvl 420 Ranger, PvP Legendary Grandmaster, and highest-ranking solo player on the OBF server. Online, no one is dependent on her and she herself answers to no one. She can let go of her responsibilities and live only for the thrill of battle and the glory of triumph. She is one of only three people in the game to have a MAGIS Bow, a legendary weapon that requires you to trade in rare drops from five different insanely difficult raid bosses in order to get it (Ch'thon, Cyandragosa, Collector, Centennarius, and Chromewing).

Like many MMORPGs, Blue Eagle Online has a crafting system that allows players to enhance their weapons using ore. An ore can bestow different properties to a weapon, such as stat modifiers, elemental damage modifiers, immunity to status, increased movement speed, lowered cooldown for skills, and even specific skills or abilities that can only be used while the enhance weapon is equipped. Riana is primarily interested in an ore's Might Multiplier $$$v$$$. Each weapon has some initial value for its might. If the crafting with the ore succeeds, then the might of the weapon is multiplied by $$$v$$$. If the crafting fails, the might of the weapon gets multiplied by $$$\dfrac{1}{v}$$$ instead.

If, after a crafting attempt, Riana enhances her weapon with another ore, the process still works as detailed above, except now using the modified might of the weapon, i.e. the effects stack. For example, suppose Riana begins with a bow whose might is $$$9$$$. She successfully enhances it with an ore with Might Multiplier $$$2$$$, so the bow's new might is $$$18$$$. Then, she tries to enhance it with an ore with Might Multiplier $$$6$$$, but it fails, so the bow's new might is $$$3$$$. Note that even if the bow's might and the ore's Might Multiplier are both integers, it is possible that the might of the bow after crafting is no longer an integer. This RPG stores the exact rational number value, and does not round the might of the bow at any point.

The MAGIS Bow currently has a might value of $$$x$$$. Riana has a list of $$$m$$$ ores which she plans to use to upgrade it. Consider the set of all possible upgraded bows that could be the final result of all possible combinations of success and failure of the enhancing attempts. If there are $$$m$$$ ores, then there are $$$2^m$$$ possible upgraded bows that Riana could get, depending on the results of the crafting. Normally, Riana might want to find the arithmetic mean of the final mights of all of these bows, but she thinks that's too easy. Instead, as a challenge, she wants you to find their geometric mean instead.

The geometric mean of a set of $$$n$$$ non-negative numbers is the $$$n$$$th root of their product. So, if the final mights of each of the possible bows is $$$s_1, s_2, \dots, s_{2^m}$$$, then their geometric mean is computed as

$$$$$$ \sqrt[2^m]{s_1 \times s_2 \times \dots \times s_{2^m}}. $$$$$$

Given the current might $$$x$$$ of MAGIS Bow and the properties of $$$m$$$ different ores, compute the geometric mean of the might of all $$$2^m$$$ possible bows that could be the final result of crafting with all the ores.

Input

The first line of input consists of a single integer $$$x$$$, the initial might of the MAGIS Bow. It is guaranteed that $$$x$$$ is between $$$1$$$ and $$$10^{18}$$$ (inclusive).

The second line of input consists of a single integer $$$m$$$, the number of different ores. It is guaranteed that $$$m$$$ is between $$$1$$$ and $$$10$$$ (inclusive).

Each of the $$$m$$$ lines that follows contains the description of a given ore that will be used for enhancement. Each line will be in the following format,

name_of_ore + ":" + property1 + ";" + property2 + ";" + ... + ";" + final_property

The name of the ore and the description of each property are non-empty strings consisting of upper and lower case English letters, numbers, plus +, forward slash /, open and close square brackets [], period ., and/or space characters. There will never be two spaces in a row, and a name or property will never begin or end in a space. It is guaranteed that each ore has at least one property and exactly one of these properties is of the form "Might Multiplier x" + v, where $$$v$$$ is a real number between $$$0$$$ and $$$10$$$ (exclusive) indicating the Might Multiplier of that ore, given to at most one decimal point. This will be the only property which contains the string Might Multiplier. It is guaranteed that the line describing each ore is at most 1000 characters in length, including spaces and other punctuation.

Output

Output in a single line the geometric mean of the mights of all possible bows that could be a result of the enhancements. The answer will be accepted if it is no more than $$$10^{-9}$$$ away from the correct answer.

ExampleInput
6
2
Champion Dust:Might Multiplier x3;STA +2019;STR x5;[Skill] 5 Hit Sweeping Strikes;[Passive] Immunity
Lordlight Crystal:[Elemental Damage] Holy;RES +1859;Might Multiplier x1.5;[Passive] Cura Personalis;[Color] Ultramarine
Output
6
Note

If both enhancements succeed, the MAGIS Bow has might $$$27$$$. If both enhancements fail, the MAGIS Bow has might $$$\dfrac{4}{3}$$$. If only the first enhancement succeeds, its might is $$$12$$$, and if only the second enhancement succeeds, its might is $$$3$$$. Thus, the four possible mights of the bow, depending on the results of the enhancements, are $$$27$$$, $$$12$$$, $$$3$$$, and $$$\dfrac{4}{3}$$$. To get the geometric mean, we need the $$$4$$$th root of their product, which is $$$\sqrt[4]{27\times12\times3\times\dfrac{4}{3}} = \sqrt[4]{1296} = 6$$$.

加入题单

上一题 下一题 算法标签: