問題一覧 > 通常問題

No.3219 Ruler to Maximize

レベル : / AI推定難易度 : 1250 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / スペシャルジャッジ問題 (複数の解が存在する可能性があります)
タグ : (AC するまで非表示) / 解いたユーザー数 76
作問者 : nauclhlt / テスター : 👑 p-adic
お気に入りにしたユーザー ProblemId : 12379 / 自分の提出
問題文最終更新日: 2025-08-01 21:38:53
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 476 (順位表) の他の問題:

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もしくは右上の雲マークをクリックしてアカウントを作成してください。