| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 2 초 | 2048 MB | 14 | 2 | 2 | 14.286% |
Marijn wrote an expression to calculate the answer to the ultimate question. Unfortunately, his friend Jeroen decided to pull a prank and shuffled all the characters in his expression!
The syntax of the expression is similar to that of most programming languages (in fact, the expression is valid Python):
(' and ')'), which are joined together by the operators '+' and '*'.0-9) and do not start with a leading '0', except for the number '0' itself.*' operator takes precedence over '+'.An example of a valid expression is "(abc+var0)*(12+0)", where the addition of two variables "abc" and "var0" is multiplied by the addition of "12" and "0".
Luckily, Marijn remembers that he did not use any unnecessary parentheses in his code. This means that for example "a+(b+c)" does not appear because the '+' operator is associative, nor does "(a*b)+c" since the '*' operator takes precedence over '+'. Note: it is not required that removing any of the parentheses actually changes the outcome of the expression.
Given a shuffled expression, help Marijn find any expression that could have been his original expression, if such an expression exists.
The input consists of:
()+*", digits (0-9), and English lowercase letters (a-z).If an expression exists that satisfies all the requirements, output "possible" followed by such a permutation of the input string. Otherwise, output "impossible".
If there are multiple valid solutions, you may output any one of them.
7 123test
possible test321
10 012var+*()
possible (var2+0)*1
7 (1+2)+3
impossible
7 (000+*)
possible (0+0)*0
2 00
impossible
9 ((1+2))*3
impossible
10 bilmseiops
possible impossible
ICPC > Regionals > Europe > Northwestern European Regional Contest > Benelux Algorithm Programming Contest > BAPC 2025 Preliminaries C번