#P13030. [GCJ 2021 #1B] Subtransmutation
[GCJ 2021 #1B] Subtransmutation
题目描述
As the most skilled alchemist in your country, you were summoned yet again because powers beyond science were needed to satisfy your country's leader's ever increasing greed for rare metals.
Each metal is represented by a positive integer. You need to create units of metal 1, units of metal 2, … and units of metal . Metals do exist, but you are not required to create any specific amount of them. You are allowed to create excess amounts of any metal, which can just be discarded.
Unfortunately, budget cuts have left you only the materials for a simple alchemy spell. For some fixed numbers and , with , you can take one unit of metal and destroy it to create one unit of metal and one unit of metal . If either of those integers is not positive, that specific unit is not created. In particular, if , the spell simply destroys the unit and creates nothing. If the spell destroys the unit and creates only a single unit of metal .
You have been assigned an expert miner to assist you. The expert miner can fetch a single unit of any metal you want. From that unit, you can use your spell to create other metals and then use the spell on the resulting metals to create even more units. The picture below shows a single unit of metal 4 being converted into one unit of metal 1 and two units of metal 2 using two spells with and .
Metals represented by larger integers are heavier and more difficult to handle, so you want to ask the expert miner for a single unit of metal represented by the smallest possible integer that is sufficient to complete your task, or say that there is no such metal.
输入格式
The first line of the input gives the number of test cases, . test cases follow. Each test case consists of two lines. The first line of a test case contains three integers , and , representing the largest metal number that you are required to create, and the two values that define the available spell as described above, respectively. The second line of a test case contains integers $\mathbf{U}_{1}, \mathbf{U}_{2}, \ldots, \mathbf{U}_{\mathbf{N}}$, representing the required units of metals , respectively.
输出格式
For each test case, output one line containing Case #x: y
, where is the test case number (starting from 1) and is IMPOSSIBLE if it is not possible to create all required units starting from a single unit of metal. Otherwise, is the smallest integer that represents a metal such that one unit of it is sufficient to create all the required units of metal.
3
2 1 2
1 2
5 1 2
2 0 0 0 1
3 1 2
1 1 1
Case #1: 4
Case #2: 6
Case #3: 5
3
3 2 4
1 1 1
3 2 4
1 0 1
5 2 5
1 0 0 0 1
Case #1: IMPOSSIBLE
Case #2: 5
Case #3: 10
提示
Sample Explanation
In Sample Case #1, we require one unit of metal 1 and two units of metal 2. If we start with a single unit of metal 3, then applying the spell once will give us one unit of metal 1 and one unit of metal 2. There is no way to get an additional unit of metal 2. Similarly, starting with a single unit of metals 1 or 2 is not sufficient. However, a single unit of metal 4 is sufficient as is demonstrated in the picture in the main part of the statement.
In Sample Case #2, we can start with a single unit of metal 6 and apply the following operations:
- Apply spell on 6: .
- Apply spell on 4: .
- Apply spell on 2: .
- Apply spell on 3: .
Note that even though we have an extra unit of metal 2 , this solution is valid.
In Sample Case #3, we can start with a single unit of metal 5 and apply the following operations:
- Apply spell on 5: .
- Apply spell on 4: .
- Apply spell on 2: .
- Apply spell on 3: .
There are other ways to apply spells which also work but they all require starting with a single unit of metal 5 or higher.
Sample Test Set 2 fits the limits of Test Set 2. It will not be run against your submitted solutions.
In the first Sample Case for Test Set 2, it is impossible to start with a single unit of any metal and apply the spell with and several times and be left with one unit of metals and .
Limits
- .
- .
- , for all .
- .
- $2 \leq \mathbf{U}_{1}+\mathbf{U}_{2}+\cdots+\mathbf{U}_{\mathbf{N}}$.
Test Set 1 (13 Pts, Visible Verdict)
- .
- .
Test Set 2 (18 Pts, Hidden Verdict)
- .