No.3219 Ruler to Maximize
Problem Statement
There is a sequence $A=(A_1, A_2, \cdots, A_N)$ of length $N$.
Now, Shiki is going to settle the black and white of the sequence $A$.
Here, to settle the black and white of a sequence means the following operation.
- Assign white or black to each element of the sequence, so that the following condition is satisfied.
- Let $W, B$ be the total bitwise OR of the elements assigned white and black, respectively ($W=0$ if all elements are assigned black, and similarly $B=0$ if all are assigned white). Then $W\mathbin{\&}B=0$.
Here, $X\mathbin{\&}Y$ denotes the bitwise AND of $X$ and $Y$.
Find the maximum possible value of $W\times B$ when Shiki settles the black and white of the sequence $A$. Also, find one color assignment that achieves the maximum value.
Input
$N$ $A_1\ A_2\ \cdots\ A_N$
- $1\leq N\leq 100$
- $0\leq A_i\leq 4000$
- All inputs are integers.
Output
Let $M$ be the maximum possible value of $W\times B$. For a color assignment achieving it, let $S$ be the string such that $S_i=$W if the color assigned to $A_i$ is white and $S_i=$B if it is black. Output them in the following format.
If there are multiple possible $S$, you may output any of them.
$M$ $S$
Print a newline at the end.
Sample
Sample 1
Input
3 4 2 2
Output
8 WBB
If we assign white to $A_1$ and black to $A_2, A_3$, the total bitwise ORs are $4, 2$ respectively, and $W\times B=4\times 2=8$. No value greater than $8$ can be achieved, so the answer is $8$.
Sample 2
Input
3 60 3 64
Output
4032 BBW
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。
nauclhlt