Group Commands and Wall Planning

AtCoder
IDawtf2025heuristic_a
Time2000ms
Memory256MB
Difficulty
There is an $N \times N$ grid. The coordinate of the top-left cell is $(0, 0)$, and the coordinate of the cell $i$ rows down and $j$ columns to the right is $(i, j)$. There are walls between some adjacent cells. There are $K$ robots on the grid. The initial position of the $k$\-th robot is $(i_k, j_k)$, and its destination is $(i_k', j_k')$. Takahashi wants to operate these robots to bring all of them to their respective destinations. Before making any moves, the following two types of preparations can be made: 1. In addition to the existing walls, you may add walls between any adjacent cells. 2. Divide the robots into groups. Each robot belongs to exactly one group, and all robots in the same group can be operated simultaneously. These preparations must be completed before the first move. After that, no additional walls can be placed and the group assignments cannot be changed. Next, the robots can be moved by repeatedly performing the following two types of operations: 1. **Group Command**: Specify a group and a direction (up, down, left, or right). All robots in that group will attempt to move one cell in the specified direction. If there is a wall between the current and target cells, or if another robot is occupying the target cell, the robot does not move. Among the robots belonging to the group, those farthest in the direction of movement will attempt to move first. For example, if robots are at $(1, 0)$ and $(2, 0)$ and the direction is up, the robot at $(1, 0)$ will move to $(0, 0)$ first (since it has a smaller $i$ coordinate), and then the robot at $(2, 0)$ will move to the now-empty $(1, 0)$. 2. **Individual Command**: Specify a robot and a direction (up, down, left, or right). The specified robot will attempt to move one cell in the specified direction. If there is a wall between the current and target cells, or if another robot is occupying the target cell, the robot does not move. Even if a robot reaches its destination once, if it moves away from the destination due to subsequent operations, it is not considered to have reached its destination. You may perform at most $K N^2$ operations. Guide all robots to their destinations using as few operations as possible. ## Input Input is given from Standard Input in the following format. $N$ $K$ $i_0$ $j_0$ $i_0'$ $j_0'$ $\vdots$ $i_{K-1}$ $j_{K-1}$ $i_{K-1}'$ $j_{K-1}'$ $v_{0,0} \cdots v_{0,N-2}$ $\vdots$ $v_{N-1,0} \cdots v_{N-1,N-2}$ $h_{0,0} \cdots h_{0,N-1}$ $\vdots$ $h_{N-2,0} \cdots h_{N-2,N-1}$ * In all test cases, $N=30$ is fixed. * $10 \leq K \leq 100$ * $(i_k, j_k)$ represents the initial position of the $k$\-th robot. * $(i_k', j_k')$ represents the destination of the $k$\-th robot. * All initial positions and all destinations are each mutually distinct, but the initial position of robot $k$ may coincide with the destination of robot $k'$. * Each $v_{i,0} \cdots v_{i,N-2}$ is a binary string of length $N-1$. The $j$\-th character $v_{i,j}$ indicates whether there is a wall (`1`) or not (`0`) between cells $(i, j)$ and $(i, j+1)$. * Each $h_{i,0} \cdots h_{i,N-1}$ is a binary string of length $N$. The $j$\-th character $h_{i,j}$ indicates whether there is a wall (`1`) or not (`0`) between cells $(i, j)$ and $(i+1, j)$. * It is guaranteed that all cells are mutually reachable. ## Scoring Let $T$ be the number of operations performed, and let $d_k$ be the Manhattan distance between the final position and the destination of robot $k$. Then, you obtain the following absolute score: \\\[ T + 100 \\times \\sum_k d_k \\\] **The lower the absolute score, the better.** For each test case, we compute the **relative score** $\mathrm{round}(10^9\times \frac{\mathrm{MIN}}{\mathrm{YOUR}})$, where YOUR is your absolute score and MIN is the lowest absolute score among all competitors obtained on that test case. The score of the submission is the sum of the relative scores. The final ranking will be determined by the system test with more inputs which will be run after the contest is over. In both the provisional/system test, if your submission produces illegal output or exceeds the time limit for some test cases, only the score for those test cases will be zero, and your submission will be excluded from the MIN calculation for those test cases. The system test will be performed only for **the last submission which received a result other than CE** . Be careful not to make a mistake in the final submission. #### Number of test cases * Provisional test: 50 * System test: 2000. We will publish [seeds.txt](https://img.atcoder.jp/awtf2025heuristic/seeds.txt) (sha256=063a84b1c0dc9388b0996eed0bc645529c931c139bee6b8e0e84a4faf3e06c40) after the contest is over. #### About relative evaluation system In both the provisional/system test, the standings will be calculated using only the last submission which received a result other than CE. Only the last submissions are used to calculate the MIN for each test case when calculating the relative scores. The scores shown in the standings are relative, and whenever a new submission arrives, all relative scores are recalculated. On the other hand, the score for each submission shown on the submissions page is the sum of the absolute score for each test case, and the relative scores are not shown. In order to know the relative score of submission other than the latest one in the current standings, you need to resubmit it. If your submission produces illegal output or exceeds the time limit for some test cases, the score shown on the submissions page will be 0, but the standings show the sum of the relative scores for the test cases that were answered correctly. #### About execution time Execution time may vary slightly from run to run. In addition, since system tests simultaneously perform a large number of executions, it has been observed that execution time increases by several percent compared to provisional tests. For these reasons, submissions that are very close to the time limit may result in TLE in the system test. Please measure the execution time in your program to terminate the process, or have enough margin in the execution time. [samples]
Samples
Input #1
30 59
8 18 11 17
8 23 17 15
1 12 11 7
19 17 24 22
23 9 8 20
21 17 26 10
4 19 12 29
19 29 7 7
19 24 12 19
24 26 19 10
12 23 4 18
8 22 26 11
23 18 16 26
28 14 8 14
6 12 21 12
28 18 13 21
21 28 17 3
5 14 11 20
28 13 19 28
27 18 18 8
7 21 28 23
25 13 0 17
15 17 4 24
15 19 7 0
3 26 10 25
26 20 7 6
17 10 28 17
8 9 5 21
2 26 12 9
18 29 21 10
7 20 10 24
23 5 11 18
24 12 4 9
9 19 26 13
1 0 15 12
9 8 3 8
29 9 15 24
22 14 3 18
15 16 15 1
1 29 19 4
9 12 27 21
2 23 9 4
18 24 14 18
22 7 8 1
20 29 24 3
3 2 12 17
10 11 15 20
16 6 24 0
6 5 29 17
29 20 26 16
14 18 0 9
29 11 26 20
24 22 1 13
1 5 15 9
26 10 27 26
20 20 2 6
6 28 15 2
22 6 0 0
6 17 16 13
00000000000000000000000000000
00000000000000000000000000000
00000000000000000000000000000
00000000000000000000000000000
00000000000000000000000000000
00000000000000000000000000000
00000000000000000000000000000
00000000000000000000000000000
00000000000000000000000000000
00000000000000000000000000000
00000000000100000000000000000
00000000000100000000000000000
00000000000100000000000000000
00000000000100000000000000000
00000000000100000000000000000
00000000000100000000000000000
00000000000100000000000000000
00000000000100000000000000000
00000000000100000000000000000
00000000000100000000000000000
00000000000100000000000000000
00000000000100000000000000000
00000000000100000000000000000
00000000000100000000000000000
00000000000100000000000000000
00000000000100000000000000000
00000000000100000000000000000
00000000000100000000000000000
00000000000000000000000000000
00000000000000000000000000000
000000000000000000000000000000
000000000000000000000000000000
000000000000000000000000000000
000000000000000000000000000000
000000000000000000000000000000
000000000000000000000000000000
000000000000000000000000000000
000000000000000000000000000000
000000000000000000000000000000
000000000000000000000000000000
000000000000000000000000000000
000000000000000000000000000000
000000000000000000000000000000
000000000000000000000000000000
000000000000000000000000000000
000000000000000000000000000000
000000000000000000000000000000
000000000000000000000000000000
000000000000000000000000000000
000000000000000000000000000000
000000000000000000000000000000
000000000000000000000000000000
000000000000000000000000000000
000000000000000000000000000000
000000000000000000000000000000
000000000000000000000000000000
000000000000000000000000000000
000000000000000000000000000000
000000000000000000000000000000
Output #1
00000000000000000000000000000
01000000000000000000000000000
00000000000000000000000000000
00000000000000000000001000000
00000000000100000000000000000
00000000000000000000000000001
00000000000000000000000000000
00000000000000000000000000000
00000000000000000000000000000
00000000000000000000000000000
00000000000100000000000000000
00000000000100000000010000000
00000000000100000000000000000
00000000000100000000000000000
00000000000100001000000000000
00000000000100000000000100000
00000000000100000000000001000
00010000000100000000000000000
00000000000100000000000000000
00000010000100000000000000000
01000000000100000000000000000
00000000000100000000000000100
00000000000100000000000000000
00000001000100000000000000000
00000000000100000000000000000
00000000000100000000000001010
00000000000100000000000000000
00000000000100000000000000000
00000000000000000000000000000
00000000000000000000000000000
000000100000000000000000000000
000000000000000000000000000000
000000000000000000000000000000
000000000000000000000000000000
000000000000000000000100000000
000000000000000000000000000000
000000000000000000000000000000
000000000000000000000000000000
000000000000000000000000000000
000000000000000000000001000000
000000000000000000000000000000
000000000000000000000000000100
000001000000000000000000000000
000000000000000000000100100000
000000000000000000000000000000
000000000000000000000000000000
000000000000000000000000000000
000000000000000010000000000000
000000000000000000000000100000
000000000000000000000000000000
000000000000000000000000000000
000000000000000000000000010000
000000100000000000000000000000
000000000000000000000000000000
000000000000000010000000000000
000000000000000100000000000000
000000000000000000000000000000
000000000000000000000000000000
000000001000000000000000000000
6 2 3 3 8 9 0 1 8 0 9 7 5 6 3 6 7 5 4 6 7 3 0 1 5 8 3 4 5 6 7 0 0 3 9 5 4 6 2 8 8 6 6 0 9 7 2 1 3 9 3 6 2 6 5 4 0 3 8
i 16 D
g 0 U
i 27 U
g 1 L
i 0 D
g 5 D
i 58 D
i 52 U
i 44 D
i 17 D
g 0 U
g 4 U
i 32 U
g 2 U
i 31 U
g 9 L
g 0 U
g 2 L
i 30 D
g 3 D
i 48 D
g 2 L
i 14 D
i 1 D
g 7 D
g 3 D
i 14 D
g 1 L
i 32 U
i 57 U
i 56 D
i 21 U
g 6 D
i 4 U
i 20 D
g 7 D
i 7 U
i 39 D
i 42 U
g 7 D
i 15 U
i 32 U
i 6 D
g 6 D
i 50 U
g 5 D
g 4 U
g 2 L
i 40 D
g 2 L
i 29 D
i 1 D
g 7 D
g 7 D
i 41 D
g 9 L
i 48 D
i 16 D
g 8 L
g 5 D
g 6 D
i 14 D
i 50 L
g 6 U
i 29 D
i 46 R
g 6 L
i 9 D
g 6 D
i 16 L
i 7 U
i 2 D
g 9 D
g 5 D
g 8 L
g 8 L
i 4 R
i 40 D
i 10 U
g 4 R
i 50 L
g 9 L
i 28 L
i 32 U
g 3 D
i 4 U
i 6 D
i 35 U
i 33 D
g 0 U
g 7 R
i 23 U
g 4 R
g 6 D
i 7 U
i 57 U
g 0 U
g 5 D
g 6 D
g 3 D
API Response (JSON)
{
  "problem": {
    "name": "Group Commands and Wall Planning",
    "description": {
      "content": "There is an $N \\times N$ grid. The coordinate of the top-left cell is $(0, 0)$, and the coordinate of the cell $i$ rows down and $j$ columns to the right is $(i, j)$. There are walls between some adja",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "awtf2025heuristic_a"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "There is an $N \\times N$ grid. The coordinate of the top-left cell is $(0, 0)$, and the coordinate of the cell $i$ rows down and $j$ columns to the right is $(i, j)$. There are walls between some adja...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments