No.2143 Only One Bracket
タグ : / 解いたユーザー数 129
作問者 :
milkcoffee
/ テスター :
nok0
cpbm_p
Problem Statement
Find one tuple of $N$ strings $(S_1, S_2 , \dots , S_N)$ that satisfies all of the following conditions.
- $S_i$ consists of
(,). - $|S_i| \geq 1$
- $|S_1|+|S_2|+\dots + |S_N| \leq N^2$
- There exists exactly $1$ permutation $P=(P_1, P_2, \dots, P_N)$ of $(1,2, \dots, N)$ that satisfies the following.
- $S_{P_1} + S_{P_2} + \dots + S_{P_N}$ is a balanced bracket string.
Here, "$+$" on strings simply denotes string concatenation.
A balanced bracket string is defined as a string that satisfies one of the following conditions.
- The empty string
- A string obtained by concatenating $s,t$ in this order, where there exist non-empty balanced bracket strings $s,t$
- A string obtained by concatenating
(, $s$,)in this order, where there exists a balanced bracket string $s$
Input
$N$
- $2 \leq N \leq 8$
- $N$ is an integer
Output
Print $S_i$ on the $i$-th line.
If there are multiple solutions satisfying the conditions, any of them will be accepted.
Sample
Sample 1
Input
2
Output
) (()
When $P=(2,1)$, we have $S_{P_1}+S_{P_2}=$ (()), which is a balanced bracket string.
This is the only $1$ permutation $P$ for which $S_{P_1}+S_{P_2}$ is a balanced bracket string, so the last condition is satisfied.
The other conditions are also satisfied, so this output is accepted.
For example, if $S_1=$(), $S_2=$(), then the result is a balanced bracket string in $2$ cases, $S_1+S_2$ and $S_2+S_1$, so this would be judged incorrect.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。