WorldQuant Round 1 (Codeforces Round 1128, Div. 1 + Div. 2)
F1
Plegma II: Ask Me Any Cell (Easy Version)
Codeforces
2500
原题
← EF2 →
翻译中…

There is a visualizer available for this problem. You can view it using this link.

翻译中…

Hacks are disabled on this problem.

翻译中…

This is the Easy Version of the problem. The only difference between the two versions is the constraints on $n$ and $k$.

翻译中…

Verity has a grid of $n$ rows and $n$ columns. The rows are numbered from $1$ to $n$ from top to bottom, and the columns are numbered from $1$ to $n$ from left to right. The cell on row $p$ and column $q$ is denoted by $(p, q)$.

翻译中…

Verity also has a robot, Circuity, with extremely simple functionality. Verity must program Circuity so it can automatically locate specific cells on the grid, while ensuring these cells stay hidden from foreign robots.

翻译中…

There are two phases in this problem.

翻译中…

Phase 1: Verity (Encoding)

翻译中…

In this phase, Verity tries to encode a given cell on the grid.

翻译中…

Verity receives a target cell $(r, c)$, and he assigns a binary value ($0$ or $1$) to each cell of the grid. On cells with value $1$, beacons that broadcast signal will be placed, while cells with value $0$ remain empty.

翻译中…

However, he believes that using too few beacons will make it easy for foreigners to also locate the target cell. Therefore, he has decided that it is safest to use at most $k$ zeros.

翻译中…

Phase 2: Circuity (Decoding)

翻译中…

In this phase, Circuity tries to find the cell Verity encoded, based on the grid he created. However, Circuity is unable to process large grids efficiently.

翻译中…

At each moment of time, Circuity suspects that the target cell lies in the subgrid bounded by the two cells $(x_0, y_0)$ and $(x_1, y_1)$. Initially, $(x_0, y_0) = (1, 1)$ and $(x_1, y_1) = (n, n)$.

翻译中…

Circuity locates the encoded cell by making exactly $2n-2$ decisions, one after another. Each decision works as follows.

翻译中…

Circuity can sense the number of beacons in the current subgrid. Let this number be $S$. Formally, $S$ is the number of cells with value $1$ inside the subgrid bounded by the cells $(x_0, y_0)$ and $(x_1, y_1)$.

翻译中…

Based solely on $S$, it will choose exactly one of the following actions:

翻译中…
  • Action U: increase $x_0$ by $1$
  • Action L: increase $y_0$ by $1$
  • Action D: decrease $x_1$ by $1$
  • Action R: decrease $y_1$ by $1$
翻译中…

Note that this decision does not rely on previous decisions, and it cannot directly rely on the values of $x_0, x_1, y_0$ or $y_1$. Circuity is memoriless, and the only parameter when making a decision must be $S$ in the current moment.

翻译中…

If at any point $x_0 \gt x_1$ or $y_0 \gt y_1$, the program bugs out and Circuity is unsuccessful.

翻译中…

The cell Verity encoded in this grid was some cell $(r, c)$. After all $2n-2$ decisions, it must hold that $x_0 = x_1 = r$ and $y_0 = y_1 = c$.

翻译中…

There exist only two tests:

翻译中…
  • $n = 3$ and $k = 9$;
  • $n = 20$ and $k = \color{red}{24}$.
翻译中…

Input

翻译中…

The only input contains one integer $n$.

翻译中…

It is guaranteed that $n = 3$ in the example, and $n = 20$ in the only main test.

翻译中…

Output

翻译中…
  • For Phase $1$:
翻译中…

Output $n^2$ binary grids.

翻译中…

The $i$-th grid is the grid Verity should choose when the target is $(r, c)$, where $r = \lfloor \frac{i-1}{n} \rfloor + 1$ and $c = ((i-1) \bmod n) + 1$.

翻译中…

In other words, the first grid corresponds to target $(1,1)$, the second grid corresponds to target $(1,2)$, the $(n+1)$-th grid corresponds to target $(2,1)$, and so on.

翻译中…

Each grid must contain at most $k$ zeros.

翻译中…
  • For Phase $2$:
翻译中…

Output a sequence of $n^2 + 1$ characters: $a_0, a_1, a_2, \ldots, a_{n^2}$. Each character must be one of U, D, L, or R. The $i$-th character means that if $S=i$, then Circuity performs action $a_i$.

翻译中…

Note

翻译中…

Consider the third grid as an example. The target cell is $(1,3)$.

翻译中…

Verity chooses the following grid:

翻译中…

110
110
110

翻译中…

The action sequence is:

翻译中…

DURLDULRUU

翻译中…

Initially, Circuity examines the subgrid bounded by $(1,1)$ and $(3,3)$.

翻译中…

It must locate cell $(1,3)$, so it will make $2 \cdot 3 - 2 = 4$ decisions.

翻译中…
  • Decision 1: there are $S=6$ ones in the current subgrid, so Circuity performs action $a_6=\mathtt{L}$. The new subgrid becomes $[(1,2),(3,3)]$.
  • Decision 2: there are $S=3$ ones in the current subgrid, so Circuity performs action $a_3=\mathtt{L}$. The new subgrid becomes $[(1,3),(3,3)]$.
  • Decision 3: there are $S=0$ ones in the current subgrid, so Circuity performs action $a_0=\mathtt{D}$. The new subgrid becomes $[(1,3),(2,3)]$.
  • Decision 4: there are again $S=0$ ones in the current subgrid, so Circuity performs action $a_0=\mathtt{D}$. The new subgrid becomes $[(1,3),(1,3)]$.
翻译中…

After all decisions, Circuity ends up at cell $(1,3)$, which is indeed the target cell.

翻译中…

样例

Input #1
3
Output #1
111
111
001

011
111
100

110
110
110

010
111
111

111
111
111

010
111
101

111
111
110

111
011
111

011
010
111

DURLDULRUU
InputCopy OutputCopy
题目信息
题号
2261F1
时间限制
2 s
内存限制
256 MB
标签
构造
贪心
数学

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。