問題一覧 > 通常問題

No.1589 Bit Vector

レベル : / AI推定難易度 : 1900 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / スペシャルジャッジ問題 (複数の解が存在する可能性があります)
タグ : (AC するまで非表示) / 解いたユーザー数 45
作問者 : e869120 / テスター : 沙耶花
お気に入りにしたユーザー ProblemId : 6694 / 自分の提出
問題文最終更新日: 2021-07-09 00:15:14
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 303 (順位表) の他の問題:

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$
You can perform the following three types of operations (here $0 \leq i, j, k \leq N, x \in \{0, 1\}$, and $i, j, k$ may coincide):
  • 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]$.
Output a sequence of operations that gives the correct result for any values of $B[0], B[1], \cdots, B[N-1]$ $(B[i] \in \{0, 1\})$. However, the length of the sequence of operations must be at most $10000$ (operations). Note that the actual judge executes the sequence of operations on all of the $T$ given test cases, and it is judged as correct if the result is as expected for all of them.

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