No.1589 Bit Vector
Problem Statement
Suppose there is a bit sequence $a[0], a[1], \cdots, a[N]$ of length $N+1$ ($a[i] \in \{0, 1\}$). The initial values of the first $N$ elements are $B[0], B[1], \cdots, B[N-1]$ (these are not revealed to you), and the initial value of the remaining element is $0$. Your goal is to finally make $a[N]$ the following value.
- If at least $K$ of $B[0], B[1], \cdots, B[N-1]$ are $1$, then $a[N] = 1$
- Otherwise, $a[N] = 0$
UPD i x: Set $a[i] = x$.AND i j k: Set $a[i] = a[j] \ \rm{AND}$$\ a[k]$.XOR i j k: Set $a[i] = a[j] \ \rm{XOR}$$\ a[k]$.
Input
$N$ $K$
$T$
$C_{1,0}$ $C_{1,1}$ $C_{1,2}$ $\cdots$ $C_{1,N-1}$
$C_{2,0}$ $C_{2,1}$ $C_{2,2}$ $\cdots$ $C_{2,N-1}$
$\vdots$
$C_{T,0}$ $C_{T,1}$ $C_{T,2}$ $\cdots$ $C_{T,N-1}$
$T$ is the number of test cases, and $C_{i, j}$ is the value of $B[j]$ in the $i$-th test case.
Output
On line $1$, output the number of operations to perform. Then, output the operations to perform, each in one of the formats UPD i x, AND i j k, or XOR i j k.
Constraints
- $2 \leq N \leq 50$
- $1 \leq K \leq N$
- $1 \leq T \leq 100$
- $C_{i, j} \in \{0, 1\}$
- All inputs are integers
Sample
Sample 1
Input
2 1 3 0 0 0 1 1 1
Output
2 UPD 2 0 XOR 2 1 2
In test case $1$, the values of the array $A$ change as $(a[0], a[1], a[2]) = (0, 0, 0) \to (0, 0, 0) \to (0, 0, 0)$. (Finally, $a[2] = 0$.)
In test case $2$, the values of the array $A$ change as $(a[0], a[1], a[2]) = (0, 1, 0) \to (0, 1, 0) \to (0, 1, 1)$. (Finally, $a[2] = 1$.)
In test case $3$, the values of the array $A$ change as $(a[0], a[1], a[2]) = (1, 1, 0) \to (1, 1, 0) \to (1, 1, 1)$. (Finally, $a[2] = 1$.)
Since the answer is correct in every case, this is judged as correct for this test case.
However, note that if $(B[0], B[1]) = (1, 0)$, then finally $a[2] = 0$, which is not the correct answer.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。
e869120
沙耶花