P6751 [IOI 2019] Vision Program
Background
[Evaluation method](https://www.luogu.com.cn/paste/5z13bn4l)
[Some notes ~~and nonsense~~](https://www.luogu.com.cn/paste/l6kcccs4)
Description
You are writing a vision program for a robot. Each time the robot’s camera takes a photo, the image is stored in the robot’s memory as a black-and-white image. Each image is a grid of pixels of size $H\times W$. The rows are numbered from $0$ to $H-1$, and the columns are numbered from $0$ to $W-1$. Each image contains **exactly two** black pixels, and all other pixels are white.
The robot can process images using a program made of simple instructions. Given $H$, $W$, and a positive integer $K$, your goal is to write a function that generates a program for the robot. This program must determine whether the distance between the two black pixels is exactly $K$. Here, the distance between the pixel at row $r_1$ and column $c_1$ and the pixel at row $r_2$ and column $c_2$ is defined as $|r_1-r_2|+|c_1-c_2|$. In this expression, $|x|$ denotes the absolute value of $x$: it equals $x$ when $x\ge0$, and equals $-x$ when $x
Input Format
N/A
Output Format
N/A
Explanation/Hint
#### Sample
Suppose $H=2$, $W=3$, and $K=3$. In this case, there are only two possible images where the distance between the two black pixels is $3$.

- Case 1: the black pixels are $0$ and $5$.
- Case 2: the black pixels are $2$ and $3$.
One feasible solution is to construct the robot program using the following calls:
1. `add_and([0, 5])`: adds an instruction whose output is $1$ if and only if the image matches case 1. The output will be stored in memory cell $6$.
1. `add_and([2, 3])`: adds an instruction whose output is $1$ if and only if the image matches case 2. The output will be stored in memory cell $7$.
1. `add_or([6, 7])`: adds an instruction whose output is $1$ if and only if at least one of the above two cases holds.
#### Constraints
For all data:
- $1\le H,W\le200$.
- $2\le H\cdot W$.
- $1\le K\le H+W-2$.
The additional constraints and scores for each subtask are as follows:
| Subtask ID | Additional Constraints | Score |
| :--------: | :--------------------: | :---: |
| $1$ | $\max(H,W) \le 3$ | $10$ |
| $2$ | $\max(H,W) \le 10$ | $11$ |
| $3$ | $\max(H,W) \le 30$ | $11$ |
| $4$ | $\max(H,W) \le 100$ | $15$ |
| $5$ | $\min(H,W) = 1$ | $12$ |
| $6$ | In every image, the pixel in row $0$ and column $0$ is black | $8$ |
| $7$ | $K = 1$ | $14$ |
| $8$ | No additional constraints | $19$ |
Translated by ChatGPT 5