#P7829. [CCO 2021] Weird Numeral System
[CCO 2021] Weird Numeral System
Problem Description
Alice is thinking about a problem involving base integers.
In standard base , an integer can be written as , satisfying:
- .
- .
However, standard base integers are too easy for Alice. Alice prefers weird base integers. The only difference from standard base integers is that the condition is replaced by , where is a sequence of length .
Now, a fixed sequence is given. Alice wants to convert decimal integers into weird base integers. This kind of problem is clearly more suitable to be solved by writing a program.
Input Format
The first line contains four integers .
The second line contains integers .
The next lines each contain one integer .
Output Format
Output lines. The -th line should be the result of converting . Output each digit from the highest power to the lowest power, separated by a single space.
When contains , your result may contain leading zeros, but it is better not to have too many. When , your result must not be empty.
If there are multiple valid answers, you may output any one of them. If it is impossible to convert, output IMPOSSIBLE.
3 3 3 1
-1 0 1
15
8
-5
1 -1 -1 0
1 0 -1
-1 1 1
10 1 3 2
0 2 -2
17
IMPOSSIBLE
Hint
**This problem is provided with an SPJ by
Constraints
For of the testdata, , , , , , .
Source
CCO2021 D1T2.
Translated by ChatGPT 5