Skip to main content

Coding & Software

ALE-Bench

ALE-Bench: long-horizon, score-based algorithm engineering on AtCoder Heuristic Contest optimization problems. 40 problems; 102 frontier LLMs evaluated across 5 self-refinement budgets. Per-(model, problem) judge verdict reduced to binary ACCEPTED vs. not.

40items
102subjects
100%observed
CC-BY-4.0license
software_engineeringdomain
reasoningdomain
textmodality

Response matrix

Every model, scored item by item.

Each row is an AI model and each column an item, ordered so the strongest models and easiest items gather toward one corner. 102 subjects × 40 items, 100% of cells evaluated.

Fit to width. Hover for subject & item; click a cell for details.

ALE-Bench response matrix: AI models (rows) against items (columns)
Correct (1)Incorrect (0)Unobserved

Scale: 1 = correct · 0 = incorrect

Sample items

What the questions look like — and how subjects answer.

A spread of items across the difficulty range. This benchmark does not publish per-answer traces, so each item shows which subjects succeeded.

Item 151% solve rate

Story

Takahashi manages a transit warehouse for transporting containers. Today, many containers are scheduled to be brought into this warehouse, and tomorrow, all of these containers will be loaded onto trucks in a predetermined order for transportation. The order in which the containers will arrive is unknown, so please flexibly store them in appropriate locations in the warehouse, taking into account the order in which they will be transported out.

Problem Statement

There is a warehouse with a grid of D×DD\times D squares. Let (0,0)(0,0) be the coordinates of the northwesternmost square and (i,j)(i,j) be the coordinates of the squares located ii squares to the south and jj squares to the east from there. The warehouse entrance is in the square (0,(D1)/2)(0,(D-1)/2), where DD is an odd number. There are impassable obstacles placed in NN squares out the D24D^2-4 squares except for the entrance and its 33 adjacent squares.

D21ND^2-1-N containers are brought into the warehouse one by one. Each container is assigned a unique number from 00 to D22ND^2-2-N which indicates the order in which the containers are to be transported out. Information on the order of containers is not given in advance, and the number assigned to a container is revealed at the time it is brought in. Each D×D1ND\times D-1-N square other than the entrance and obstacles can hold at most 11 container. Each time a container is brought in, choose a square to store it. The chosen square must satisfy the following conditions.

  1. It is neither the entrance nor an obstacle square, and there are no other containers stored at the chosen square.
  2. It must be reachable from the entrance by only passing through adjacent empty squares in the four directions.

After all the containers are stored, please transport out all of them one by one. The container to be transported out must satisfy the following conditions.

  1. The square containing the container to be transported out must be reachable from the entrance by only passing through adjacent empty squares in the four directions.

Optimize the storage location of the containers and the order in which they are transported out so that the order is as close as possible to the specified order.

Scoring

Let bi(0biD22N)b_i (0\leq b_i\leq D^2-2-N) be the number assigned to the container transported out for the ii-th time (0iD22N0\leq i\leq D^2-2-N). Let BB be the number of inversions of b0,,bD22Nb_0,\cdots,b_{D^2-2-N}, that is, the total number of pairs (i,j)(i,j) such that i<ji < j and bi>bjb_i>b_j. Then, you will obtain the following score.

\[ \mathrm{round}\left(10^9\times \frac{(D^2-N)(D^2-1-N)/2-B}{(D^2-N)(D^2-1-N)/2}\right) \]

There are 3030 test cases for each N=0,1,,9N=0,1,\cdots,9, for a total of 300 test cases, and the score of a submission is the total score for each test case. If your submission produces an illegal output or exceeds the time limit for some test cases, the submission itself will be judged as <span class='label label-warning' data-toggle='tooltip' data-placement='top' title="Wrong Answer">WA</span> or <span class='label label-warning' data-toggle='tooltip' data-placement='top' title="Time Limit Exceeded">TLE</span> , and the score of the submission will be zero. The highest score obtained during the contest will determine the final ranking, and there will be no system test after the contest. If more than one participant gets the same score, they will be ranked in the same place regardless of the submission time.

Input and Output

First, the size of the warehouse, DD, the number of obstacles NN, and the coordinates (ri0,rj0),,(riN1,rjN1)(ri_0,rj_0),\cdots,(ri_{N-1},rj_{N-1}) of obstacles are given from Standard Input in the following format.

$D$ $N$
$ri_0$ $rj_0$
$\vdots$
$ri_{N-1}$ $rj_{N-1}$

For all test cases, we fix D=9D = 9. The number of obstacles NN satisfies 0ND0\leq N\leq D. The coordinates of each obstacle (rik,rjk)(ri_k,rj_k) are different from the entrance and any of its three adjacent squares, furthermore, all squares except the obstacles are guaranteed to be reachable from the entrance.

After reading the above information, repeat the following process D21ND^2-1-N times.

In the dd-th process (0dD22N0\leq d\leq D^2-2-N), the number tdt_d assigned to the dd-th container brought in is given on a single line from Standard Input. Each tdt_d is an integer value between 00 and D22ND^2-2-N, and each container has a unique number.

After reading the information of tdt_d, output the coordinates (pid,pjd)(pi_d,pj_d) of the square to store the container to Standard Output on a single line in the following format.

$pi_d$ $pj_d$

<font color="red">The output must be followed by a new line, and you have to flush Standard Output.</font> Otherwise, the submission might be judged as <span class='label label-warning' data-toggle='tooltip' data-placement='top' title="Time Limit Exceeded">TLE</span>. <font color="red">**Note that the input for the d+1d+1-th container will not be given until the dd-th output is given. **</font>

After all containers have been stored, determine the order in which the containers are to be transported out. Let (qik,qjk)(qi_k, qj_k) be the coordinates of the kk-th container to be transported out. Then, output to Standard Output in the following format.

$qi_0$ $qj_0$
$qi_1$ $qj_1$
$\vdots$
$qi_{D^2-2-N}$ $qj_{D^2-2-N}$

Your program may output comment lines starting with #. The web version of the visualizer displays the comment lines at the corresponding timing, which may be useful for debugging and analysis. Since the judge program ignores all comment lines, you can submit a program that outputs comment lines as is.

<table class="table table-bordered"> <thead> <tr> <th>$d$</th> <th>Input</th> <th>Output</th> </tr> </thead> <tbody> <tr> <td>Prior information</td> <td><pre>9 0 </pre></td> <td></td> </tr> <tr> <td>0</td> <td><pre>16</pre></td> <td><pre>8 0</pre></td> </tr> <tr> <td>1</td> <td><pre>13</pre></td> <td><pre>8 8</pre></td> </tr> <tr> <td>$\vdots$</td> <td></td> <td></td> </tr> <tr> <td>79</td> <td><pre>34</pre></td> <td><pre>0 5</pre></td> </tr> <tr> <td>Transporting order</td> <td></td> <td><pre>0 3 0 5 0 2 $\vdots$ 8 8</pre></td> </tr> </tbody> </table>

<a href="https://img.atcoder.jp/toyota2023summer-final/TqK1K6OG.html?lang=en&seed=0&output=sample">Show example</a>

Input Generation

The number of obstacles NN is generated uniformly at random from integers between 00 and DD, inclusive. A distinct set of NN coordinates for the obstacles are randomly chosen from squares other than the entrance and its three adjacent squares. The numbers t0,,tD22Nt_0,\cdots,t_{D^2-2-N} assigned to the containers are generated by randomly shuffling 0,1,,D22N0,1,\cdots,D^2-2-N.

Tools (Input generator and visualizer)

  • <a href="https://img.atcoder.jp/toyota2023summer-final/TqK1K6OG.html?lang=en">Web version</a>: This is more powerful than the local version providing animations and manual play.
  • <a href="https://img.atcoder.jp/toyota2023summer-final/TqK1K6OG.zip">Local version</a>: You need a compilation environment of <a href="https://www.rust-lang.org/">Rust language</a>.
    • <a href="https://img.atcoder.jp/toyota2023summer-final/TqK1K6OG_windows.zip">Pre-compiled binary for Windows</a>: If you are not familiar with the Rust language environment, please use this instead.

Please be aware that sharing visualization results or discussing solutions/ideas during the contest is prohibited.

Subject outcomes

  • deepseek-v4-pro-high correct
  • gemini-3-flash-preview-high correct
  • claude-fable-5-high correct
  • qwen3.6-flash incorrect
  • qwen3.6-plus incorrect
  • step-3.7-flash-medium incorrect
Item 266% solve rate

Story

AtCoder, a big tech company, has many offices. In order to securely share super-secret information of problem statements for future contests, we decided to set up private lines using quantum cryptography between the offices. There are several candidates for office pairs that can be connected by private lines, and we want to make sure that all offices are connected by private lines. The cost of setting up a private line is proportional to the length of the line, but due to physical limitations, it is not always possible to set up a straight line, so we have asked vendors to estimate the exact cost for each candidate. Since CEO Takahashi is impatient, once he receives the estimate for one candidate, he immediately decides whether to set up that line or not. Please support Takahashi and help him achieve his goal at a lower cost as possible.

Problem Statement

You are given an undirected graph with NN vertices and MM edges. Each vertex is on a two-dimensional plane, and the coordinates of the ii-th vertex is (xi,yi)(x_i, y_i). The ii-th edge connects vertices uiu_i and viv_i, and we know in advance that its length lil_i satisfies dili3did_i \leq l_i \leq 3 d_i, where di=round((xuixvi)2+(yuiyvi)2)d_i=\mathrm{round}(\sqrt{(x_{u_i}-x_{v_i})^2+(y_{u_i}-y_{v_i})^2}) is the Euclidean distance between the endpoints rounded to the nearest integer.

The true edge length lil_i will be given one by one in order from i=0i=0 to i=M1i=M-1. After receiving the length lil_i of the ii-th edge, you have to decide whether to adopt that edge or not before receiving the length li+1l_{i+1} of the next edge.

Let SS be the set edges you eventually adopt, then for every vertex pair (u,v)(u,v), SS must contain a path between uu and vv. Please make decisions so that the total length of the adopted edges is as short as possible.

Input and Output

For all test cases, we fix N=400N=400 and M=1995M=1995.

At the start of the execution, the coordinates of NN vertices (x0,y0),,(xN1,yN1)(x_0,y_0), \cdots, (x_{N-1},y_{N-1}) and the endpoints of MM edges (u0,v0),,(uM1,vM1)(u_0,v_0), \cdots, (u_{M-1},v_{M-1}) are given from Standard Input in the following format.

$x_0$ $y_0$
$\vdots$
$x_{N-1}$ $y_{N-1}$
$u_0$ $v_0$
$\vdots$
$u_{M-1}$ $v_{M-1}$

It is guaranteed to satisfy the following.

  • 0xi,yi8000\leq x_i,y_i\leq 800
  • 0ui<viN10\leq u_i<v_i\leq N-1
  • The same (ui,vi)(u_i,v_i) pair never appears more than once.
  • The graph is connected.

Then, repeat the following process MM times.

In the ii-th (0iM10\leq i\leq M-1) process, the length lil_i of the ii-th edge is generated uniformly at random from integers between did_i and 3di3 d_i, and given to Standard Input in a single line. After reading lil_i, output 1 if you adopt the ii-th edge, or 0 if you don't, in one line to Standard Output. <font color="red">Note that the next input is not given until your program outputs 0 or 1. After the output, you have to flush Standard Output.</font> Otherwise, the submission might be judged as <span class='label label-warning' data-toggle='tooltip' data-placement='top' title="Time Limit Exceeded">TLE</span> .

Example

<table class="table table-bordered"> <thead> <tr> <th align="left">$i$</th> <th align="left">Input</th> <th align="left">Output</th> </tr> </thead> <tbody> <tr> <td align="left">Prior information</td> <td align="left"><pre> 406 19 347 786 $\vdots$ 21 191 </pre></td> <td align="left"></td> <tr> <td align="left">$0$</td> <td align="left"><pre>69</pre></td> <td align="left"><pre>1</pre></td> </tr> <tr> <td align="left">$1$</td> <td align="left"><pre>89</pre></td> <td align="left"><pre>0</pre></td> </tr> <tr> <td align="center" colspan="3">$\vdots$</td> </tr> <tr> <td align="left">$M-1$</td> <td align="left"><pre>175</pre></td> <td align="left"><pre>0</pre></td> </tr> </tbody> </table>

Scoring

Let AA be the total length of the set of adopted edges, BB be the total length of the optimal set of edges under the condition that the true length lil_i of every edge is known in advance (<a href="https://en.wikipedia.org/wiki/Minimum_spanning_tree">minimum spanning tree</a>). Then, you will get a score of round(108×B/A)\mathrm{round}(10^8\times B/A). When the set of adopted edges does not make the graph connected, your submission will be judged as <span class='label label-warning' data-toggle='tooltip' data-placement='top' title="不正解">WA</span>. Note that if your program terminates abnormally, it may be judged as <span class='label label-warning' data-toggle='tooltip' data-placement='top' title="Wrong Answer">WA</span> instead of <span class='label label-warning' data-toggle='tooltip' data-placement='top' title="Runtime Error">RE</span>.

There are 150 test cases, and the score of a submission is the total score for each test case. If you get a result other than <span class='label label-success' data-toggle='tooltip' data-placement='top' title="Accepted">AC</span> for one or more test cases, the score of the submission will be zero. The highest score obtained during the contest time will determine the final ranking, and there will be no system test after the contest. If more than one participant gets the same score, the ranking will be determined by the submission time of the submission that received that score.

Input Generation

Let rand(L,U)\mathrm{rand}(L,U) be a function that generates a uniform random integer between LL and UU, inclusive.

Generation of (xi,yi)(x_i,y_i)

For each i=0,,N1i=0,\cdots,N-1, we generate xi=rand(0,800)x_i=\mathrm{rand}(0,800) and yi=rand(0,800)y_i=\mathrm{rand}(0,800). If the Euclidean distance to the coordinates (xj,yj)(x_j,y_j) of an already generated vertex (j<i)(j<i) is less than or equal to 55, we regenerate (xi,yi)(x_i,y_i).

Generation of (ui,vi)(u_i,v_i)

Let GG be a complete graph with edge length round((xixj)2+(yiyj)2)\mathrm{round}(\sqrt{(x_i-x_j)^2+(y_i-y_j)^2}) between vertex ii and jj. By repeating the following process 55 times, we generate a set EE of M=5(N1)M=5(N-1) edges.

We compute a minimum spanning tree TT of GG, and remove all edges in TT from GG and insert them to EE.

Finally, by randomly shuffling the order of edges in EE, we generate the list of edges (u0,v0),,(uM1,vM1)(u_0,v_0),\cdots,(u_{M-1},v_{M-1}).

Generation of lil_i

Let di=round((xuixvi)2+(yuiyvi)2)d_i=\mathrm{round}(\sqrt{(x_{u_i}-x_{v_i})^2+(y_{u_i}-y_{v_i})^2}) be the Euclidean distance between the endpoints rounded to the nearest integer. Then we generate li=rand(di,3di)l_i=\mathrm{rand}(d_i,3 d_i).

Tools (Input generator and visualizer)

  • <a href="https://img.atcoder.jp/ahc007/a855b6a456c9892b747e147001b0f89.zip">Local version</a>: You need a compilation environment of <a href="https://www.rust-lang.org/">Rust language</a>.
  • <a href="https://img.atcoder.jp/ahc007/a855b6a456c9892b747e147001b0f89.html?lang=en">Web version</a>: This is more powerful than the local version and can display animations.

<font color="red">You are allowed to share output images (png or gif) of the provided visualizer for seed=0 on twitter during the contest.</font> You have to use the specified hashtag and public account. <a href="https://twitter.com/search?q=%23AHC007%20%23visualizer&src=typed_query&f=live">List of shared images.</a>

Subject outcomes

  • claude-4.6-opus-no-thinking correct
  • claude-4.5-opus correct
  • gemini-3.1-flash-lite-preview-high correct
  • qwen3.6-flash incorrect
  • qwen3.7-max incorrect
  • step-3.7-flash-medium incorrect
Item 372% solve rate

Story

AtCoder's CEO, Takahashi, loves animals and has a number of pets running free in the AtCoder office. AtCoder's employees have trouble with the pets interrupting their work, so they have decided to place partitions in the office to create a space where pets cannot come in. Please create as large a space as possible.

Problem Statement

There are NN pets and MM people in a room with a floor of 30×3030 \times 30 squares. All squares are initially passable, and outside of the 30×3030 \times 30 squares are impassable. Let (x,y)(x, y) be the coordinates of the square in row xx from the top (1x301\leq x\leq 30) and column yy from the left (1y301\leq y\leq 30). Repeat the following process for 300300 turns.

First, you choose each person's action from the following three types, and perform each action simultaneously.

  • Do nothing and stay in the current position.
  • Choose a square adjacent to the current position and make it impassable. You cannot choose a square that contains pets or humans at the start of this turn. <b>You cannot choose a square whose adjacent square contains a pet, either.</b> If you choose a square that is already impassable, nothing happens.
  • Move to an adjacent passable square. It is not possible to move to a square that becomes impassable by another person's action in this turn.

After all the people have completed their actions for that turn, each pet moves independently. Rules for pet movement depend on the type of pet, and some pets may move multiple squares in a single turn. Details are described later.

Squares containing humans or pets are also passable, and each square can contain any number of humans and pets.

Scoring

At the end of 300300 turn, for each i=1,,Mi=1,\cdots,M, let RiR_i be the set of squares reachable from the final position of person ii through only passable squares, and nin_i be the number of pets whose final position is in RiR_i. Then, person ii obtains satisfaction of si=Ri900×2nis_i=\frac{|R_i|}{900}\times 2^{-n_i}. The score for the test case is round(108×1Mi=1Msi)\mathrm{round}\left(10^8\times\frac{1}{M}\sum_{i=1}^M s_i\right).

Number of test cases

  • Provisional test: 100
  • System test: 2000. We will publish <a href="https://img.atcoder.jp/ahc008/seeds.txt">seeds.txt</a> (md5=27bf0702bbe0265900374c3b6b9846b4, sha256=33973e4ded08e3a607fc2e841e14751ff110ae10154b286e7fd5f766ff86d706) after the contest is over.

The score of a submission is the total scores for each test case. In the provisional test, if your submission produces illegal output or exceeds the time limit for some test cases, the submission itself will be judged as <span class='label label-warning' data-toggle='tooltip' data-placement='top' title="Wrong Answer">WA</span> or <span class='label label-warning' data-toggle='tooltip' data-placement='top' title="Time Limit Exceeded">TLE</span> , and the score of the submission will be zero. In the 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. Note that if your program terminates abnormally, it may be judged as <span class='label label-warning' data-toggle='tooltip' data-placement='top' title="Wrong Answer">WA</span> instead of <span class='label label-warning' data-toggle='tooltip' data-placement='top' title="Runtime Error">RE</span>.

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 <span class='label label-warning' data-toggle='tooltip' data-placement='top' title="Time Limit Exceeded">TLE</span> in the system test. Please measure the execution time in your program to terminate the process, or have enough margin in the execution time.

Input and Output

First, the initial position and type of each pet, and the initial position of each person are given from Standard Input in the following format

$N$
$px_1$ $py_1$ $pt_1$
$\vdots$
$px_N$ $py_N$ $pt_N$
$M$
$hx_1$ $hy_1$
$\vdots$
$hx_M$ $hy_M$

NN is an integer between 1010 and 2020 representing the number of pets. (pxi,pyi)(px_i,py_i) represents the coordinates of the initial position of the ii-th pet, and ptipt_i is an integer between 11 and 55 representing the type of the ii-th pet. MM is an integer between 55 and 1010 representing the number of humans. (hxi,hyi)(hx_i,hy_i) represents the coordinates of the initial position of the ii-th human. The initial positions of all pets and humans are guaranteed to be distinct.

After reading the above information, repeat the following process 300300 turns.

First, output a string of length MM where the ii-th character represents the action of the iith person as follows on a single line to Standard Output. <font color="red">After the output, you have to flush Standard Output.</font> Otherwise, the submission might be judged as <span class='label label-warning' data-toggle='tooltip' data-placement='top' tit le="Time Limit Exceeded">TLE</span> .

  • .: Do nothing and stay in the current position.
  • u, d, l, r: Let (x,y)(x,y) be the current position. Make the square (x1,y)(x-1,y), (x+1,y)(x+1,y), (x,y1)(x,y-1), or (x,y+1)(x,y+1) impassable, respectively.
  • U, D, L, R: Let (x,y)(x,y) be the current position. Move to the the square (x1,y)(x-1,y), (x+1,y)(x+1,y), (x,y1)(x,y-1), or (x,y+1)(x,y+1), respectively.

After the output, NN strings are given to Standard Input in a single line, separated by spaces. The ii-th string represents movement of the ii-th pet in that turn. If the pet does not move, the string is .. If it does move, the string is a sequence of characters U, D, L, and R representing the movement of one square up, down, left, and right, respectively.

<a href="https://img.atcoder.jp/ahc008/f828b9475ffb41d54f05619db6ccbd4f.html?lang=en&show=example">Show example</a>

Pets Movement Rules

We define a basic move as follows: move to a square chosen at random among the adjacent passable squares. From the condition of the squares that can be made impassable, such squares always exist.

Each pet ii performs the following moves depending on ptipt_i, an integer value between 11 and 55 representing its type.

  1. <img src="./images/cow.png" width="30" height="30" style="background-color:silver;image-rendering:pixelated"> Cow: Perform one basic move.
  2. <img src="./images/pig.png" width="30" height="30" style="background-color:silver;image-rendering:pixelated"> Pig: Perform two basic moves.
  3. <img src="./images/rabbit.png" width="30" height="30" style="background-color:silver;image-rendering:pixelated"> Rabbit: Perform three basic moves.
  4. <img src="./images/dog.png" width="30" height="30" style="background-color:silver;image-rendering:pixelated"> Dog: Move toward a target person as follows. The first turn starts with no target. If it has no target, the target person is in the current position, or there exists no path to the target person, then it selects one person uniformly at random among those reachable from the current position, excluding those in the current position. If there is no such person, reset to no target and perform one basic move. Otherwise, move to an adjacent passable square that shortens the shortest distance to the target person (if there are multiple such squares, choose one of them uniformly at random), and then perform one basic move. If it reaches the destination after the first or the second move, reset to no target.
  5. <img src="./images/cat.png" width="30" height="30" style="background-color:silver;image-rendering:pixelated"> Cat: Move toward a target square as follows. The first turn starts with no target. If it has no target or there exists no path to the target square, then it selects one square uniformly at random among those reachable from the current position, excluding the current position. If there exists no such square, do nothing. Otherwise, move to an adjacent passable square that shortens the shortest distance to the target square (if there are multiple such squares, choose one of them uniformly at random), and then perform one basic move. If it reaches the destination after the first or the second move, reset to no target.

Input Generation

Let rand(L,U)\mathrm{rand}(L,U) be a function that generates a uniform random integer between LL and UU, inclusive.

We generate the number of pets by N=rand(10,20)N=\mathrm{rand}(10, 20). The initial position of each pet is chosen uniformly at random from the coordinates that have not been chosen yet. We generate the type of each pet by pti=rand(1,5)pt_i=\mathrm{rand}(1, 5).

We generate the number of humans by M=rand(5,10)M=\mathrm{rand}(5, 10). The initial position of each human is chosen uniformly at random from the coordinates that have not been chosen yet.

Tools

  • <a href="https://img.atcoder.jp/ahc008/tools_v3.zip">Local tester</a>: You need a compilation environment of <a href="https://www.rust-lang.org/">Rust language</a>.
    • For those who are not familiar with the Rust language environment, we have prepared a pre-compiled binary for Windows. <a href="https://img.atcoder.jp/ahc008/tools_x86_64-pc-windows-gnu_v3.zip">tools_x86_64-pc-windows-gnu.zip</a>
    • <font color="red">The first version contained a bug in the cat's movement, which has been fixed at 130 minutes after the contest started. Please re-download it.</font>
    • We have added more examples in README. If you don't know how to use the tools, please refer to README. Also, as stated in the rules, you are free to share information on how to run the provided tools.
  • <a href="https://img.atcoder.jp/ahc008/f828b9475ffb41d54f05619db6ccbd4f.html?lang=en">Web visualizer</a>: By pasting the output generated by the local tester into the Output field, you can display the animation of the execution result.

<font color="red">You are allowed to share output images (png or gif) of the provided visualizer for seed=0 on twitter during the contest.</font> You have to use the specified hashtag and public account. You can only share visualization results and scores for seed=0. Do not share scores for other seeds or mention solutions or discussions. <a href="https://twitter.com/search?q=%23AHC008%20%23visualizer&src=typed_query&f=live">List of shared images.</a>

Specification of input/output files used by the tools

Input files for the local tester consist of the prior information (the initial position and type of each pet, and the initial position of each person) followed by a random seed value to generate pet movements. Since the pet's movement depends on human actions, the input file contains only the random seed value and not specific movements. The local tester writes outputs from your program directly to the output file. Your program may output comment lines starting with #. The web version of the visualizer displays the comment lines at the time they are output, which may be useful for debugging and analysis. Since the judge program ignores all comment lines, you can submit a program that outputs comment lines as is.

Subject outcomes

  • claude-4.5-opus correct
  • claude-4.5-haiku correct
  • claude-4.6-opus-no-thinking correct
  • qwen3.6-flash incorrect
  • qwen3.6-plus incorrect
  • step-3.7-flash-medium incorrect
Item 476% solve rate

Story

You have been hired as a project leader of F Corporation. Your job is to assign tasks to team members appropriately. The current project consists of a number of tasks. The expected number of days for a team member to complete a task depends on skill levels of the team member and required skill levels for the task. You are highly experienced and can accurately estimate the required skill levels for each task, but since you have just joined the team, you do not yet know the skill levels of each team member at all. Please assign tasks appropriately while gradually evaluating the skill levels of team members.

Problem Statement

You want to assign NN tasks to MM team members. You can assign each task to at most one team member, and once you assign a task to a team member, you cannot assign another task to him/her until he/she completes the task. There are KK types of skills. Each team member jj has a non-negative integer vector sj=(sj,1,,sj,K)\bm{s_j} = (s_{j,1},\cdots,s_{j,K}) representing skill levels, and each task ii has a non-negative integer vector di=(di,1,,di,K)\bm{d_i} = (d_{i,1},\cdots,d_{i,K}) representing required skill levels. Among these, the skill levels s1,,sM\bm{s_1},\cdots,\bm{s_M} are not given as input.

We define wi,j:=k=1Kmax(0,di,ksj,k)w_{i,j}:=\sum_{k=1}^K \max(0,d_{i,k}-s_{j,k}). Then, it takes ti,jt_{i,j} days for team member jj to complete task ii, where ti,jt_{i,j} is defined as follows.

  1. If wi,j=0w_{i,j}=0, ti,j=1t_{i,j}=1.
  2. If wi,j>0w_{i,j}>0, ti,j=max(1,wi,j+ri)t_{i,j}=\max(1,w_{i,j}+r_i), where rir_i is a uniform random integer between 3-3 and 33, inclusive.

When a task taking tt days is started on day dd, the task will be completed at the end of day d+t1d+t-1. There are dependencies between tasks, and before starting a task, all of its dependent tasks must have been completed by the end of the previous day. Please complete all tasks in as few days as possible.

Input and Output

For the range of each input value, see Input Generation.

At the start of the execution, the number of tasks NN, the number of team members MM, the number of skills KK, the number of dependencies RR, required skill levels for each task d1,,dN\bm{d_1},\cdots,\bm{d_N}, and a list of pairs of dependent tasks (u1,v1),,(uR,vR)(u_1,v_1),\cdots,(u_R,v_R) are given from Standard Input in the following format.

$N$ $M$ $K$ $R$
$d_{1,1}$ $\cdots$ $d_{1,K}$
$\vdots$
$d_{N,1}$ $\cdots$ $d_{N,K}$
$u_1$ $v_1$
$\vdots$
$u_R$ $v_R$

(ui,vi)(u_i,v_i) indicates that the task viv_i (1viN1\leq v_i\leq N) depends on the task uiu_i (1uiN1\leq u_i\leq N) and that uiu_i must be completed before starting viv_i. It satisfies ui<viu_i<v_i, and the same (ui,vi)(u_i,v_i) pair appears at most once in the input.

Then, starting from day 1, do the following two processes every day.

First, output to Standard Output a list of pairs (a1,b1),,(am,bm)(a_1,b_1),\cdots,(a_m,b_m) such that team member aia_i (1aiM1\leq a_i\leq M) starts task bib_i (1biN1\leq b_i\leq N) on that day in one line in the following format.

$m$ $a_1$ $b_1$ $\cdots$ $a_m$ $b_m$

<font color="red">After the output, you have to flush Standard Output.</font> Otherwise, the submission might be judged as <span class='label label-warning' data-toggle='tooltip' data-placement='top' title="Time Limit Exceeded">TLE</span> .

Next, a list of team members who have completed their tasks at the end of that day f1,,fnf_1,\cdots,f_n (1f1<<fnM1\leq f_1<\cdots<f_n\leq M) is given in one line from Standard Input in the following format.

$n$ $f_1$ $\cdots$ $f_n$

If all tasks are completed or day 20002000 is over, a line containing only -1 will be given as input instead of the above input, and you should exit the program.

Example

<table class="table table-bordered"> <thead> <tr> <th align="left">Day</th> <th align="left">Output</th> <th align="left">Input</th> </tr> </thead> <tbody> <tr> <td align="left">Prior information</td> <td align="left"></td> <td align="left"><pre>3 2 2 1 0 1 2 0 1 1 2 3 </pre></td> <tr> <td align="left">Day 1</td> <td align="left"><pre>2 1 1 2 2</pre></td> <td align="left"><pre>1 1</pre></td> </tr> <tr> <td align="left">Day 2</td> <td align="left"><pre>0</pre></td> <td align="left"><pre>1 2</pre></td> </tr> <tr> <td align="left">Day 3</td> <td align="left"><pre>1 1 3</pre></td> <td align="left"><pre>0</pre></td> </tr> <tr> <td align="left">Day 4</td> <td align="left"><pre>0</pre></td> <td align="left"><pre>0</pre></td> </tr> <tr> <td align="left">Day 5</td> <td align="left"><pre>0</pre></td> <td align="left"><pre>-1</pre></td> </tr> </tbody> </table>

Scoring

If you complete all the tasks at the end of day DD (1D20001\leq D\leq 2000), you will get a score of N+2000DN+2000-D. If you fail to complete all the tasks within 20002000 days, you will get a score of TT, where T(<N)T(<N) is the total number of completed tasks.

Number of test cases

  • Provisional test: 50
  • System test: 3000. We will publish <a href="https://img.atcoder.jp/future-contest-2022-qual/seeds.txt">seeds.txt</a> (md5=a90d2e3883a546dfb66a4215b8d7a995) after the contest is over.

The score of a submission is the total scores for each test case. In the provisional test, if your submission produces illegal output or exceeds the time limit for some test cases, the submission itself will be judged as <span class='label label-warning' data-toggle='tooltip' data-placement='top' title="Wrong Answer">WA</span> or <span class='label label-warning' data-toggle='tooltip' data-placement='top' title="Time Limit Exceeded">TLE</span> , and the score of the submission will be zero. In the 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. Note that if your program terminates abnormally, it may be judged as <span class='label label-warning' data-toggle='tooltip' data-placement='top' title="Wrong Answer">WA</span> instead of <span class='label label-warning' data-toggle='tooltip' data-placement='top' title="Runtime Error">RE</span>.

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 <span class='label label-warning' data-toggle='tooltip' data-placement='top' title="Time Limit Exceeded">TLE</span> in the system test. Please measure the execution time in your program to terminate the process, or have enough margin in the execution time.

Input Generation

Let randint(L,U)\mathrm{randint}(L, U) be a function that generates a uniform random integer between LL and UU, inclusive. Let randdouble(L,U)\mathrm{randdouble}(L,U) be a function that generates a uniform random floating point number between LL and UU. Let randnormal()\mathrm{randnormal}() be a function that generates a random value from <a href="https://en.wikipedia.org/wiki/Normal_distribution#Standard_normal_distribution">the standard normal distribution</a>.

Generation of NN, MM, KK, and RR

  • N=1000N=1000 (fixed for all test cases)
  • M=20M=20 (fixed for all test cases)
  • K=randint(10,20)K=\mathrm{randint}(10, 20)
  • R=randint(1000,3000)R=\mathrm{randint}(1000, 3000)

Generation of di,jd_{i,j}

For each i=1,,Ni=1,\cdots,N, we generate di=(di,1,,di,K)\bm{d_i} = (d_{i,1},\cdots,d_{i,K}) as follows.

We generate KK-dimensional vector (di,1,,di,K)(d_{i,1}',\cdots,d_{i,K}') by generating di,j=randnormal()d_{i,j}'=|\mathrm{randnormal}()|. Let pi=randdouble(10,40)j=1Kdi,j2p_i=\frac{\mathrm{randdouble}(10,40)}{\sqrt{\sum_{j=1}^K d_{i,j}'^2}}. Then, we set di,j=round(pidi,j)d_{i,j}=\mathrm{round}(p_i d'_{i,j}).

Generation of si,js_{i,j}

For each i=1,,Mi=1,\cdots,M, we generate si=(si,1,,si,K)\bm{s_i} = (s_{i,1},\cdots,s_{i,K}) as follows.

We generate KK-dimensional vector (si,1,,si,K)(s_{i,1}',\cdots,s_{i,K}') by generating si,j=randnormal()s_{i,j}'=|\mathrm{randnormal}()|. Let qi=randdouble(20,60)j=1Ksi,j2q_i=\frac{\mathrm{randdouble}(20,60)}{\sqrt{\sum_{j=1}^K s_{i,j}'^2}}. Then, we set si,j=round(qisi,j)s_{i,j}=\mathrm{round}(q_i s'_{i,j}).

Generation of (ui,vi)(u_i,v_i)

Starting from an empty set E=E=\emptyset, we generate a set of dependent task pairs E=(u1,v1),,(uR,vR)E=\\{(u_1,v_1),\cdots,(u_R,v_R)\\} by repeating the following process until E=R|E|=R.

Generate h=randint(1,100)h=\mathrm{randint}(1,100) and v=randint(h+1,N)v=\mathrm{randint}(h+1,N). Let u=vhu=v-h and insert (u,v)(u,v) into EE.

Tools

  • <a href="https://img.atcoder.jp/future-contest-2022-qual/f4ca7c3336de23e5c8d1338981e38375.zip">Local Tester</a>: You need a compilation environment of <a href="https://www.rust-lang.org/">Rust language</a>.
  • <a href="https://img.atcoder.jp/future-contest-2022-qual/f4ca7c3336de23e5c8d1338981e38375_en.html">Visualizer on the web</a>

Specification of input/output files used by the tools

<details> These tools use an input file of the following format that contains, in addition to the prior information, the hidden information: skill level $\bm{s_i}$ and the number of days $t_{i,j}$ it actually takes for team member $j$ to complete task $i$. ~~~ $N$ $M$ $K$ $R$ $d_{1,1}$ $\cdots$ $d_{1,K}$ $\vdots$ $d_{N,1}$ $\cdots$ $d_{N,K}$ $u_1$ $v_1$ $\vdots$ $u_R$ $v_R$ $s_{1,1}$ $\cdots$ $s_{1,K}$ $\vdots$ $s_{M,1}$ $\cdots$ $s_{M,K}$ $t_{1,1}$ $\cdots$ $t_{1,M}$ $\vdots$ $t_{N,1}$ $\cdots$ $t_{N,M}$ ~~~

With this information, instead of using the provided tester, you can implement your own tester that is equivalent to the provided one.

In outputs of your program, lines starting with # are ignored as comments. In particular, lines starting with #s are interpreted as predictions of skill levels described in the following format, and are used for visualization.

<pre> \#s $i$ $s_{i,1}$ $\cdots$ $s_{i,K}$ </pre>

Predictions can be output as many times as you like, and predictions for the same ii will be overwritten. The visualizer on the web provides an animation of the predictions.

For example, by inserting comment lines in the output shown in Example as follows, you can update the prediction of s1s_1 to (0,1)(0, 1) on day 1, and the prediction of s2s_2 to (1,0)(1, 0) on day 2.

<pre> 2 1 1 2 2 \#s 1 0 1 0 \#s 2 1 0 1 1 3 0 0 </pre>

Comment lines are also ignored in the judge, so you can submit the same program.

</details>

Sample Program(Python)

# assign random tasks to team member 1.
import sys
import random
# Prior information
n, m, d, r = list(map(int, input().split()))
task_difficulty = []
for i in range(n):
    task_difficulty.append(list(map(int, input().split())))
task_dependency = [[] for _ in range(n)]
for i in range(r):
    temp = list(map(int, input().split()))
    task_dependency[temp[1] - 1].append(temp[0] - 1)
# -1: not started
#  0: started
#  1: completed
task_status = [-1] * n
# -1: not assigned
#  k: assigned task k (1 <= k <= N)
member_status = -1
day = 0
while True:
    day += 1
    output = [0]
    # random search for tasks
    if member_status < 0:
        tasklist = list(range(n))
        random.shuffle(tasklist)
        for task in tasklist:
            if task_status[task] != -1:
                continue
            ok = True
            for necessary in task_dependency[task]:
                if task_status[necessary] != 1:
                    # the dependent tasks have not been completed
                    ok = False
                    break
            if ok:
                # assign the task to team member 1
                task_status[task] = 0
                member_status = task
                output = [1, 1, task + 1]
                break
    str_output = map(str, output)
    print(" ".join(str_output))
    # After the output, you have to flush Standard Output
    sys.stdout.flush()
    temp = list(map(int, input().split()))
    if len(temp) == 1:
        if temp[0] == -1:
            # elapsed days == 2000, or all the tasks have been completed
            exit()
        else:
            # no change in state
            pass
    else:
        # one task has been completed
        task = member_status
        task_status[task] = 1
        member_status = -1

Subject outcomes

  • claude-4-sonnet correct
  • claude-4.1-opus correct
  • claude-4.5-opus correct
  • qwen3.5-flash incorrect
  • qwen3.6-plus incorrect
  • qwen3.6-flash incorrect
Item 579% solve rate

Story

Takahashi loves puzzles and is playing with the following famous sliding puzzle.

There are N21N^2-1 tiles on an N×NN \times N board. There is a single empty square, and you can slide an adjacent tile in any of the four directions into the empty square. Some picture is divided into each tile. By repeatedly sliding the tiles, please align the picture.

The trouble is, Takahashi had thrown away the instruction manual, so he lost the target picture. According to his memory, the target picture was a <a href="https://en.wikipedia.org/wiki/Tree_(graph_theory)">tree</a>. By repeating the sliding operation, please complete a tree.

example

Problem Statement

There are N21N^2-1 tiles on an N×NN \times N board. Let (i,j)(i, j) denote the coordinates of row ii (0iN1)(0\leq i \leq N-1) from the top and column jj (0jN1)(0\leq j\leq N-1) from the left. Each tile contains a figure with lines from its center towards one or more of four directions: up, down, left, and right. We represent each tile using a bitmask with 1 for left, 2 for up, 4 for right, and 8 for down, as follows.

<table> <tr align="center"> <td> Tile </td> <td> <svg height="50" id="vis" viewBox="-5 -5 50 50" width="50" xmlns="http://www.w3.org/2000/svg"> <rect fill="white" height="50" width="50" x="-5" y="-5"/> <line stroke="lightgray" stroke-width="1" x1="0" x2="40" y1="0" y2="0"/> <line stroke="lightgray" stroke-width="1" x1="0" x2="0" y1="0" y2="40"/> <line stroke="lightgray" stroke-width="1" x1="0" x2="40" y1="40" y2="40"/> <line stroke="lightgray" stroke-width="1" x1="40" x2="40" y1="0" y2="40"/> <rect fill="lightgray" height="40" width="40" x="0" y="0"/> </svg> </td> <td> <svg height="50" id="vis" viewBox="-5 -5 50 50" width="50" xmlns="http://www.w3.org/2000/svg"> <rect fill="white" height="50" width="50" x="-5" y="-5"/> <line stroke="lightgray" stroke-width="1" x1="0" x2="40" y1="0" y2="0"/> <line stroke="lightgray" stroke-width="1" x1="0" x2="0" y1="0" y2="40"/> <line stroke="lightgray" stroke-width="1" x1="0" x2="40" y1="40" y2="40"/> <line stroke="lightgray" stroke-width="1" x1="40" x2="40" y1="0" y2="40"/> <g transform="translate(0,0)"> <line stroke="#905020" stroke-width="10" x1="20" x2="0" y1="20" y2="20"/> <circle cx="20" cy="20" fill="#905020" r="5"/> </g> </svg> </td> <td> <svg height="50" id="vis" viewBox="-5 -5 50 50" width="50" xmlns="http://www.w3.org/2000/svg"> <rect fill="white" height="50" width="50" x="-5" y="-5"/> <line stroke="lightgray" stroke-width="1" x1="0" x2="40" y1="0" y2="0"/> <line stroke="lightgray" stroke-width="1" x1="0" x2="0" y1="0" y2="40"/> <line stroke="lightgray" stroke-width="1" x1="0" x2="40" y1="40" y2="40"/> <line stroke="lightgray" stroke-width="1" x1="40" x2="40" y1="0" y2="40"/> <g transform="translate(0,0)"> <line stroke="#905020" stroke-width="10" x1="20" x2="20" y1="20" y2="0"/> <circle cx="20" cy="20" fill="#905020" r="5"/> </g> </svg> </td> <td> <svg height="50" id="vis" viewBox="-5 -5 50 50" width="50" xmlns="http://www.w3.org/2000/svg"> <rect fill="white" height="50" width="50" x="-5" y="-5"/> <line stroke="lightgray" stroke-width="1" x1="0" x2="40" y1="0" y2="0"/> <line stroke="lightgray" stroke-width="1" x1="0" x2="0" y1="0" y2="40"/> <line stroke="lightgray" stroke-width="1" x1="0" x2="40" y1="40" y2="40"/> <line stroke="lightgray" stroke-width="1" x1="40" x2="40" y1="0" y2="40"/> <g transform="translate(0,0)"> <line stroke="#905020" stroke-width="10" x1="20" x2="0" y1="20" y2="20"/> <line stroke="#905020" stroke-width="10" x1="20" x2="20" y1="20" y2="0"/> <circle cx="20" cy="20" fill="#905020" r="5"/> </g> </svg> </td> <td> <svg height="50" id="vis" viewBox="-5 -5 50 50" width="50" xmlns="http://www.w3.org/2000/svg"> <rect fill="white" height="50" width="50" x="-5" y="-5"/> <line stroke="lightgray" stroke-width="1" x1="0" x2="40" y1="0" y2="0"/> <line stroke="lightgray" stroke-width="1" x1="0" x2="0" y1="0" y2="40"/> <line stroke="lightgray" stroke-width="1" x1="0" x2="40" y1="40" y2="40"/> <line stroke="lightgray" stroke-width="1" x1="40" x2="40" y1="0" y2="40"/> <g transform="translate(0,0)"> <line stroke="#905020" stroke-width="10" x1="20" x2="40" y1="20" y2="20"/> <circle cx="20" cy="20" fill="#905020" r="5"/> </g> </svg> </td> <td> <svg height="50" id="vis" viewBox="-5 -5 50 50" width="50" xmlns="http://www.w3.org/2000/svg"> <rect fill="white" height="50" width="50" x="-5" y="-5"/> <line stroke="lightgray" stroke-width="1" x1="0" x2="40" y1="0" y2="0"/> <line stroke="lightgray" stroke-width="1" x1="0" x2="0" y1="0" y2="40"/> <line stroke="lightgray" stroke-width="1" x1="0" x2="40" y1="40" y2="40"/> <line stroke="lightgray" stroke-width="1" x1="40" x2="40" y1="0" y2="40"/> <g transform="translate(0,0)"> <line stroke="#905020" stroke-width="10" x1="20" x2="0" y1="20" y2="20"/> <line stroke="#905020" stroke-width="10" x1="20" x2="40" y1="20" y2="20"/> <circle cx="20" cy="20" fill="#905020" r="5"/> </g> </svg> </td> <td> <svg height="50" id="vis" viewBox="-5 -5 50 50" width="50" xmlns="http://www.w3.org/2000/svg"> <rect fill="white" height="50" width="50" x="-5" y="-5"/> <line stroke="lightgray" stroke-width="1" x1="0" x2="40" y1="0" y2="0"/> <line stroke="lightgray" stroke-width="1" x1="0" x2="0" y1="0" y2="40"/> <line stroke="lightgray" stroke-width="1" x1="0" x2="40" y1="40" y2="40"/> <line stroke="lightgray" stroke-width="1" x1="40" x2="40" y1="0" y2="40"/> <g transform="translate(0,0)"> <line stroke="#905020" stroke-width="10" x1="20" x2="20" y1="20" y2="0"/> <line stroke="#905020" stroke-width="10" x1="20" x2="40" y1="20" y2="20"/> <circle cx="20" cy="20" fill="#905020" r="5"/> </g> </svg> </td> <td> <svg height="50" id="vis" viewBox="-5 -5 50 50" width="50" xmlns="http://www.w3.org/2000/svg"> <rect fill="white" height="50" width="50" x="-5" y="-5"/> <line stroke="lightgray" stroke-width="1" x1="0" x2="40" y1="0" y2="0"/> <line stroke="lightgray" stroke-width="1" x1="0" x2="0" y1="0" y2="40"/> <line stroke="lightgray" stroke-width="1" x1="0" x2="40" y1="40" y2="40"/> <line stroke="lightgray" stroke-width="1" x1="40" x2="40" y1="0" y2="40"/> <g transform="translate(0,0)"> <line stroke="#905020" stroke-width="10" x1="20" x2="0" y1="20" y2="20"/> <line stroke="#905020" stroke-width="10" x1="20" x2="20" y1="20" y2="0"/> <line stroke="#905020" stroke-width="10" x1="20" x2="40" y1="20" y2="20"/> <circle cx="20" cy="20" fill="#905020" r="5"/> </g> </svg> </td> <td> <svg height="50" id="vis" viewBox="-5 -5 50 50" width="50" xmlns="http://www.w3.org/2000/svg"> <rect fill="white" height="50" width="50" x="-5" y="-5"/> <line stroke="lightgray" stroke-width="1" x1="0" x2="40" y1="0" y2="0"/> <line stroke="lightgray" stroke-width="1" x1="0" x2="0" y1="0" y2="40"/> <line stroke="lightgray" stroke-width="1" x1="0" x2="40" y1="40" y2="40"/> <line stroke="lightgray" stroke-width="1" x1="40" x2="40" y1="0" y2="40"/> <g transform="translate(0,0)"> <line stroke="#905020" stroke-width="10" x1="20" x2="20" y1="20" y2="40"/> <circle cx="20" cy="20" fill="#905020" r="5"/> </g> </svg> </td> <td> <svg height="50" id="vis" viewBox="-5 -5 50 50" width="50" xmlns="http://www.w3.org/2000/svg"> <rect fill="white" height="50" width="50" x="-5" y="-5"/> <line stroke="lightgray" stroke-width="1" x1="0" x2="40" y1="0" y2="0"/> <line stroke="lightgray" stroke-width="1" x1="0" x2="0" y1="0" y2="40"/> <line stroke="lightgray" stroke-width="1" x1="0" x2="40" y1="40" y2="40"/> <line stroke="lightgray" stroke-width="1" x1="40" x2="40" y1="0" y2="40"/> <g transform="translate(0,0)"> <line stroke="#905020" stroke-width="10" x1="20" x2="0" y1="20" y2="20"/> <line stroke="#905020" stroke-width="10" x1="20" x2="20" y1="20" y2="40"/> <circle cx="20" cy="20" fill="#905020" r="5"/> </g> </svg> </td> <td> <svg height="50" id="vis" viewBox="-5 -5 50 50" width="50" xmlns="http://www.w3.org/2000/svg"> <rect fill="white" height="50" width="50" x="-5" y="-5"/> <line stroke="lightgray" stroke-width="1" x1="0" x2="40" y1="0" y2="0"/> <line stroke="lightgray" stroke-width="1" x1="0" x2="0" y1="0" y2="40"/> <line stroke="lightgray" stroke-width="1" x1="0" x2="40" y1="40" y2="40"/> <line stroke="lightgray" stroke-width="1" x1="40" x2="40" y1="0" y2="40"/> <g transform="translate(0,0)"> <line stroke="#905020" stroke-width="10" x1="20" x2="20" y1="20" y2="0"/> <line stroke="#905020" stroke-width="10" x1="20" x2="20" y1="20" y2="40"/> <circle cx="20" cy="20" fill="#905020" r="5"/> </g> </svg> </td> <td> <svg height="50" id="vis" viewBox="-5 -5 50 50" width="50" xmlns="http://www.w3.org/2000/svg"> <rect fill="white" height="50" width="50" x="-5" y="-5"/> <line stroke="lightgray" stroke-width="1" x1="0" x2="40" y1="0" y2="0"/> <line stroke="lightgray" stroke-width="1" x1="0" x2="0" y1="0" y2="40"/> <line stroke="lightgray" stroke-width="1" x1="0" x2="40" y1="40" y2="40"/> <line stroke="lightgray" stroke-width="1" x1="40" x2="40" y1="0" y2="40"/> <g transform="translate(0,0)"> <line stroke="#905020" stroke-width="10" x1="20" x2="0" y1="20" y2="20"/> <line stroke="#905020" stroke-width="10" x1="20" x2="20" y1="20" y2="0"/> <line stroke="#905020" stroke-width="10" x1="20" x2="20" y1="20" y2="40"/> <circle cx="20" cy="20" fill="#905020" r="5"/> </g> </svg> </td> <td> <svg height="50" id="vis" viewBox="-5 -5 50 50" width="50" xmlns="http://www.w3.org/2000/svg"> <rect fill="white" height="50" width="50" x="-5" y="-5"/> <line stroke="lightgray" stroke-width="1" x1="0" x2="40" y1="0" y2="0"/> <line stroke="lightgray" stroke-width="1" x1="0" x2="0" y1="0" y2="40"/> <line stroke="lightgray" stroke-width="1" x1="0" x2="40" y1="40" y2="40"/> <line stroke="lightgray" stroke-width="1" x1="40" x2="40" y1="0" y2="40"/> <g transform="translate(0,0)"> <line stroke="#905020" stroke-width="10" x1="20" x2="40" y1="20" y2="20"/> <line stroke="#905020" stroke-width="10" x1="20" x2="20" y1="20" y2="40"/> <circle cx="20" cy="20" fill="#905020" r="5"/> </g> </svg> </td> <td> <svg height="50" id="vis" viewBox="-5 -5 50 50" width="50" xmlns="http://www.w3.org/2000/svg"> <rect fill="white" height="50" width="50" x="-5" y="-5"/> <line stroke="lightgray" stroke-width="1" x1="0" x2="40" y1="0" y2="0"/> <line stroke="lightgray" stroke-width="1" x1="0" x2="0" y1="0" y2="40"/> <line stroke="lightgray" stroke-width="1" x1="0" x2="40" y1="40" y2="40"/> <line stroke="lightgray" stroke-width="1" x1="40" x2="40" y1="0" y2="40"/> <g transform="translate(0,0)"> <line stroke="#905020" stroke-width="10" x1="20" x2="0" y1="20" y2="20"/> <line stroke="#905020" stroke-width="10" x1="20" x2="40" y1="20" y2="20"/> <line stroke="#905020" stroke-width="10" x1="20" x2="20" y1="20" y2="40"/> <circle cx="20" cy="20" fill="#905020" r="5"/> </g> </svg> </td> <td> <svg height="50" id="vis" viewBox="-5 -5 50 50" width="50" xmlns="http://www.w3.org/2000/svg"> <rect fill="white" height="50" width="50" x="-5" y="-5"/> <line stroke="lightgray" stroke-width="1" x1="0" x2="40" y1="0" y2="0"/> <line stroke="lightgray" stroke-width="1" x1="0" x2="0" y1="0" y2="40"/> <line stroke="lightgray" stroke-width="1" x1="0" x2="40" y1="40" y2="40"/> <line stroke="lightgray" stroke-width="1" x1="40" x2="40" y1="0" y2="40"/> <g transform="translate(0,0)"> <line stroke="#905020" stroke-width="10" x1="20" x2="20" y1="20" y2="0"/> <line stroke="#905020" stroke-width="10" x1="20" x2="40" y1="20" y2="20"/> <line stroke="#905020" stroke-width="10" x1="20" x2="20" y1="20" y2="40"/> <circle cx="20" cy="20" fill="#905020" r="5"/> </g> </svg> </td> <td> <svg height="50" id="vis" viewBox="-5 -5 50 50" width="50" xmlns="http://www.w3.org/2000/svg"> <rect fill="white" height="50" width="50" x="-5" y="-5"/> <line stroke="lightgray" stroke-width="1" x1="0" x2="40" y1="0" y2="0"/> <line stroke="lightgray" stroke-width="1" x1="0" x2="0" y1="0" y2="40"/> <line stroke="lightgray" stroke-width="1" x1="0" x2="40" y1="40" y2="40"/> <line stroke="lightgray" stroke-width="1" x1="40" x2="40" y1="0" y2="40"/> <g transform="translate(0,0)"> <line stroke="#905020" stroke-width="10" x1="20" x2="0" y1="20" y2="20"/> <line stroke="#905020" stroke-width="10" x1="20" x2="20" y1="20" y2="0"/> <line stroke="#905020" stroke-width="10" x1="20" x2="40" y1="20" y2="20"/> <line stroke="#905020" stroke-width="10" x1="20" x2="20" y1="20" y2="40"/> <circle cx="20" cy="20" fill="#905020" r="5"/> </g> </svg> </td> </tr> <tr align="center"> <td> Binary </td> <td> 0000 </td> <td> 0001 </td> <td> 0010 </td> <td> 0011 </td> <td> 0100 </td> <td> 0101 </td> <td> 0110 </td> <td> 0111 </td> <td> 1000 </td> <td> 1001 </td> <td> 1010 </td> <td> 1011 </td> <td> 1100 </td> <td> 1101 </td> <td> 1110 </td> <td> 1111 </td> </tr> <tr align="center"> <td> Hex </td> <td> 0 </td> <td> 1 </td> <td> 2 </td> <td> 3 </td> <td> 4 </td> <td> 5 </td> <td> 6 </td> <td> 7 </td> <td> 8 </td> <td> 9 </td> <td> a </td> <td> b </td> <td> c </td> <td> d </td> <td> e </td> <td> f </td> </tr> </table>

The number 0 represents an empty square, and there is exactly one empty square. With a single operation, you can slide one of the tiles adjacent to the empty square in the four directions to the location of the empty square. After the move, the square from which the tile was moved becomes an empty square. You can repeat the sliding operation at most T=2×N3T=2\times N^3 times.

After finishing the operations, consider a graph with N21N^2-1 squares other than the empty square as vertices and the following edges.

  • For each (i,j)(i, j) (0iN2,0jN1)(0\leq i\leq N-2, 0\leq j\leq N-1), if (i,j)(i,j) is a tile with a downward line and (i+1,j)(i+1,j) is a tile with an upward line, then construct an edge between (i,j)(i,j) and (i+1,j)(i+1,j).
  • For each (i,j)(i, j) (0iN1,0jN2)(0\leq i\leq N-1, 0\leq j\leq N-2), if (i,j)(i,j) is a tile with a rightward line and (i,j+1)(i,j+1) is a tile with a leftward line, then construct an edge between (i,j)(i,j) and (i,j+1)(i,j+1).

Your task is to find a short sequence of operations such that the size of the largest tree in this graph, i.e., the number of vertices of the largest connected component without cycles, is as large as possible. It is guaranteed that within TT operations you can construct a tree of size N21N^2-1 with the empty square in (N1,N1)(N-1,N-1). Note that the final position of the empty square is arbitrary and you do not have to move it to (N1,N1)(N-1,N-1).

Scoring

Let KK be the number of operations and SS be the size of the largest tree painted on the board after applying the sequence of operations. Then, you will get the following score.

  • If S<N21S<N^2-1, round(500000×SN21)\mathrm{round}\left(500000\times \frac{S}{N^2-1}\right)
  • If S=N21S=N^2-1, round(500000×(2KT))\mathrm{round}\left(500000\times (2-\frac{K}{T})\right)

If the number of operations exceeds TT or you perform an illegal operation to move a non-existent tile to the empty square, it will be judged as <span class='label label-warning' data-toggle='tooltip' data-placement='top' title="不正解">WA</span> .

Number of test cases

  • Provisional test: 50
  • System test: 3000. We will publish <a href="https://img.atcoder.jp/ahc011/seeds.txt">seeds.txt</a> (sha256=041256f962c6ba1a60294ad7a575684d6e401163cba316cf978f2e66a4f7b0e3) after the contest is over.
  • Both provisional and system tests contain the same number of inputs for each N=6,7,8,9,10N=6,7,8,9,10.

The score of a submission is the total scores for each test case. In the provisional test, if your submission produces illegal output or exceeds the time limit for some test cases, the submission itself will be judged as <span class='label label-warning' data-toggle='tooltip' data-placement='top' title="Wrong Answer">WA</span> or <span class='label label-warning' data-toggle='tooltip' data-placement='top' title="Time Limit Exceeded">TLE</span> , and the score of the submission will be zero. In the 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.

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 <span class='label label-warning' data-toggle='tooltip' data-placement='top' title="Time Limit Exceeded">TLE</span> in the s ystem test. Please measure the execution time in your program to terminate the process, or have enough margin in the execution time.

Input

Input is given from Standard Input in the following format:

$N$ $T$
$t_{0,0}$ $\cdots$ $t_{0,N-1}$
$\vdots$
$t_{N-1,0}$ $\cdots$ $t_{N-1,N-1}$

NN is an integer representing the height and width of the board, satisfying 6N106\leq N\leq 10. In all test cases, T=2×N3T=2\times N^3. ti,0t_{i,0} \cdots ti,N1t_{i,N-1} is a string of length NN. The jj-th character ti,jt_{i,j} is 0-9 or a-f which is the hexadecimal representation of the figure contained in the tile (i,j)(i,j).

Output

By representing each operation of sliding the upward, downward, leftward, or rightward adjacent tile into the empty square by a single character U, D, L or R, respectively, output the sequence of KK operations as a string of length KK in one line to Standard Output.

<a href="https://img.atcoder.jp/ahc011/df8bb452a2.html?lang=en&seed=0&output=RRRDLUULDDDDLUUUR">Show example</a>

Input Generation

<details>

Generation of NN and TT

We generate NN as the remainder of the seed value divided by 5 + 6. Hence, you can generate inputs with a specific NN value by adjusting the seed value. We set T=2×N3T=2\times N^3.

Generation of ti,jt_{i,j}

Let [k]=0,1,,k1[k]=\\{0,1,\cdots,k-1\\}. We randomly generate a spanning tree (V,F)(V,F) with vertices V=[N]×[N](N1,N1)V=[N]\times [N]\setminus \\{(N-1,N-1)\\} as follows.

  1. First, we randomly shuffle edges (i,j),(i+1,j)(i,j)[N1]×[N](N2,N1)(i,j),(i,j+1)(i,j)[N]×[N1](N1,N2)\\{\\{(i,j),(i+1,j)\\}\mid (i,j)\in [N-1]\times [N]\setminus \\{(N-2,N-1)\\}\\}\cup\\{\\{(i,j),(i,j+1)\\}\mid (i,j)\in [N]\times [N-1]\setminus \\{(N-1,N-2)\\}\\} and obtain an ordered edge list e0,e1,e_0, e_1, \cdots.
  2. Starting from F=F=\emptyset, for each ek=(i,j),(i,j)e_k=\\{(i,j),(i',j')\\}, we insert eke_k into FF if (i,j)(i,j) and (i,j)(i',j') are not connected in (V,F)(V,F).

From the obtained spanning tree, we construct tiles on which a tree of size N21N^2-1 is drawn, as follows.

  1. For each (i,j)(i,j), if (i,j),(i+1,j)F\\{(i,j),(i+1,j)\\}\in F, then draw a downward line on tile (i,j)(i, j) and an upward line on tile (i+1,j)(i+1,j).
  2. For each (i,j)(i,j), if (i,j),(i,j+1)F\\{(i,j),(i,j+1)\\}\in F, then draw a rightward line on tile (i,j)(i, j) and a leftward line on tile (i,j+1)(i,j+1).

Finally, starting from the constructed tile layout, randomly perform T=2×N3T=2\times N^3 sliding operations, and let tt be the tile layout after the operations. Here, the k(2)k (\geq 2)-th operation is chosen uniformly at random from at most three directions excluding the direction that reverts the (k1)(k-1)-th operation.

</details>

Tools (Input generator and visualizer)

  • <a href="https://img.atcoder.jp/ahc011/df8bb452a2.html?lang=en">Web version</a>: This is more powerful than the local version and can display animations.
  • <a href="https://img.atcoder.jp/ahc011/df8bb452a2.zip">Local version</a>: You need a compilation environment of <a href="https://www.rust-lang.org/">Rust language</a>.
    • <a href="https://img.atcoder.jp/ahc011/df8bb452a2_windows.zip">Pre-compiled binary for Windows</a>: If you are not familiar with the Rust language environment, please use this instead.
<font color="red"> You are allowed to share output images (PNG) of the provided visualizer for seed=0 on twitter during the contest. Note that sharing in video format is prohibited. </font> You have to use the specified hashtag and public account. You can only share visualization results and scores for seed=0. Do not share GIFs, output itself, scores for other seeds or mention solutions or discussions. <font color="red"> (Added) The visualizer has a feature to change the value of N, but sharing visualization results for changed inputs is also prohibited. </font>

<a href="https://twitter.com/search?q=%23AHC011%20%23visualizer&src=typed_query&f=live">List of shared images</a>

{sample example}

Subject outcomes

  • claude-4-sonnet correct
  • claude-4.5-haiku correct
  • claude-4.5-sonnet correct
  • qwen3.5-35b-a3b incorrect
  • qwen3.6-plus incorrect
  • step-3.7-flash-medium incorrect
Item 681% solve rate

Problem Statement

There is a floor consisting of 50×5050\times 50 squares. The floor is covered with rectangular tiles without any gaps. Each tile has a size of either 1×11\times 1, 1×21\times 2, or 2×12\times 1 squares. Let (0,0)(0, 0) denote the top-left square, and (i,j)(i, j) denote the square at the ii-th row from the top and jj-th column from the left. Takahashi starts from (si,sj)(si, sj) and walks along a path satisfying the following conditions.

  • From (i,j)(i, j), he can move to (i1,j)(i-1,j), (i+1,j)(i+1,j), (i,j1)(i,j-1), or (i,j+1)(i,j+1) in one step.
  • He can step on the same tile only once. The tile at the initial position is assumed to have already been stepped on.

Each square has an integer value, and the score of a path is the sum of the values of the visited squares, including the square at the initial position. Your goal is to find a path with as high a score as possible.

Examples

<img src="./images/out1.svg" width=200> <img src="./images/out2.svg" width=200> <img src="./images/out3.svg" width=200>

Of the above three figures, only the path in the left figure satisfies the conditions. In the middle figure, the same tile is stepped on twice in a row. In the right figure, he left a tile once and then came back to the same tile.

<img src="./images/out.min.svg" width=1002>

Visualization result of the sample output. The red circle represents the initial position, and the green circle represents the final position. The tiles stepped on are painted in light blue.

Scoring

The score of the output path is the score for the test case. If the output does not satisfy the conditions, it is judged as WA. There are 100 test cases, and the score of a submission is the total score for each test case. If you get a result other than AC for one or more test cases, the score of the submission will be zero. The highest score obtained during the contest time will determine the final ranking, and there will be no system test after the contest. If more than one participant gets the same score, the ranking will be determined by the submission time of the submission that received that score.

Input

Input is given from Standard Input in the following format:

$si$ $sj$
$t_{0,0}$ $t_{0,1}$ $\ldots$ $t_{0,49}$
$\vdots$
$t_{49,0}$ $t_{49,1}$ $\ldots$ $t_{49,49}$
$p_{0,0}$ $p_{0,1}$ $\ldots$ $p_{0,49}$
$\vdots$
$p_{49,0}$ $p_{49,1}$ $\ldots$ $p_{49,49}$
  • (si,sj)(si,sj) denotes the initial position and satisfies 0si,sj490\leq si,sj\leq 49.
  • ti,jt_{i,j} is an integer representing the tile placed on (i,j)(i,j). (i,j)(i,j) and (i,j)(i',j') are covered by the same tile if and only if ti,j=ti,jt_{i,j}=t_{i',j'} holds. Let the total number of tiles be MM, then 0ti,jM10\leq t_{i,j}\leq M-1 is satisfied.
  • pi,jp_{i,j} is an integer value satisfying 0pi,j990\leq p_{i,j}\leq 99 which represents the score obtained when visiting (i,j)(i,j).

Output

Let U, D, L, and R represent the movement from (i,j)(i,j) to (i1,j)(i-1,j), (i+1,j)(i+1,j), (i,j1)(i,j-1), and (i,j+1)(i,j+1), respectively. Output a string representing a path in one line.

Input Generation

Generation of si,sjsi,sj

Generate an integer between 00 and 4949 uniformly at random.

Generation of ti,jt_{i,j}

We start from an initial configuration where tiles of size 1×11\times 1 are placed on all squares. We shuffle the 50x50 squares in random order and perform the following process for each square in order.

  • If the tile placed on the current square is 1×11\times 1, we randomly select one of the adjacent squares whose tile is 1×11\times 1 and connect the two tiles into one tile. If there are no such adjacent squares, we do nothing.
  • If the tile placed on the current square is not 1×11\times 1, we do nothing.

Generation of pi,jp_{i,j}

Generate an integer between 00 and 9999 uniformly at random independently for each square.

Tools

  • <a href="https://img.atcoder.jp/ahc002/8c847d8177acc2dd417be4327252e39e.zip">Inputs</a>: A set of 100 inputs (seed 0-99) for local testing, including the sample input (seed 0). These inputs are different from the actual test case.
  • <a href="https://img.atcoder.jp/ahc002/e5b2b399792299b5b35543c219e89601.html">Visualizer on the web</a>
  • <a href="https://img.atcoder.jp/ahc002/c993bb7f09d9f8857fc90951fc6af11d.zip">Input generator and visualizer</a>: If you want to use more inputs, or if you want to visualize your output locally, you can use this program. You need a compilation environment of <a href="https://www.rust-lang.org/ja">Rust language</a>.

{sample example}

Subject outcomes

  • claude-4.1-opus correct
  • claude-4.5-opus correct
  • claude-4.6-opus-no-thinking correct
  • qwen3-max incorrect
  • qwen3.5-35b-a3b incorrect
  • qwen3.6-flash incorrect
Item 782% solve rate

Story

F Corporation developed a robotic vacuum cleaner, Takahashi-kun cleaner No.2, and decided to entrust it with the cleaning of their office. Takahashi-kun cleaner No.2 can operate indefinitely through solar power and repeats cleaning on a predetermined route indefinitely. The office has varying levels of susceptibility to dirt in different areas, and by frequently cleaning the areas that are more prone to dirt, the entire office can be kept cleaner.

Problem Statement

There is an N×NN\times N square board. Let (0,0)(0, 0) be the coordinates of the top-left square, and (i,j)(i, j) be the coordinates of the square located ii squares down and jj squares to the right from there. The perimeter of the N×NN\times N board is surrounded by walls, and there may also be walls between adjacent squares.

Each square (i,j)(i,j) is assigned a value di,jd_{i,j} which represents its susceptibility to dirt. Your task is to clean these squares by moving around the board. You can move to an adjacent square that is not blocked by a wall. After the move, the dirtiness of the square you moved to becomes 00, and the dirtiness of all other squares (i,j)(i, j) increases by di,jd_{i, j}. Consider a cleaning route that starts and ends at (0,0)(0, 0), with a length (number of moves) not exceeding 10510^5. The cleaning route may pass through the same square multiple times, but must visit each square at least once.

Let at,i,ja_{t,i,j} denote the dirtiness of each square (i,j)(i,j) after the tt-th move, and let St=i=0N1j=0N1at,i,jS_t=\sum_{i=0}^{N-1}\sum_{j=0}^{N-1} a_{t,i,j} denote the total dirtiness. At t=0t=0, we assume that the dirtiness of all squares is a0,i,j=0a_{0,i,j}=0. Define the average dirtiness as \[ \bar{S}=\frac{1}{L}\sum_{t=L}^{2L-1}S_t, \] which is the average of the total dirtiness during the period t=L,L+1,,2L1t=L,L+1,\cdots,2L-1 when the cleaning route of length LL is repeated infinitely.

Please find a cleaning route that minimizes the average dirtiness as much as possible.

The Meaning of Average Dirtiness

We can prove that at,i,j=at+L,i,ja_{t,i,j}=a_{t+L,i,j} for tLt\geq L when the cleaning route of length LL is repeated infinitely. Therefore, considering the average 1Tt=0T1St\frac{1}{T} \sum_{t=0}^{T-1} S_t of the total dirtiness up to TT turns, its limit as TT \to \infty coincides with the average dirtiness.

Scoring

Let Sˉ\bar{S} be the average dirtiness of the output cleaning route. Then you will obtain an absolute score of round(Sˉ)\mathrm{round}(\bar{S}). The lower the absolute score, the better. If you output an illegal cleaning route (length exceeds 10510^5, does not return to (0,0)(0,0), there is an unvisited square, or it hits a wall), it will be judged as <span class='label label-warning' data-toggle='tooltip' data-placement='top' title="Wrong Answer">WA</span>.

For each test case, we compute the <font color="red"><strong>relative score</strong></font> round(109×MINYOUR)\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 <font color="red"><strong>the last submission which received a result other than <span class="label label-warning" data-toggle="tooltip" data-placement="top" title="" data-original-title="Compilation Error">CE</span> </strong></font>. Be careful not to make a mistake in the final submission.

Number of test cases

  • Provisional test: 50
  • System test: 2000. We will publish <a href="https://img.atcoder.jp/ahc027/seeds.txt">seeds.txt</a> (sha256=cdea33a6050850bf1387e2191b802a1df7e43fcb969fd6c3bf9cbd96a4d790d7) 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 <span class="label label-warning" data-toggle="tooltip" data-placement="top" title="" data-original-title="Compilation Error">CE</span>. 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 <span class='label label-warning' data-toggle='tooltip' data-placement='top' title="Time Limit Exceeded">TLE</span> in the system test. Please measure the execution time in your program to terminate the process, or have enough margin in the execution time.

Input

Input is given from Standard Input in the following format.

$N$
$h_{0,0}\cdots h_{0,N-1}$
$\vdots$
$h_{N-2,0} \cdots h_{N-2,N-1}$
$v_{0,0} \cdots v_{0,N-2}$
$\vdots$
$v_{N-1,0} \cdots v_{N-1,N-2}$
$d_{0,0}$ $\cdots$ $d_{0,N-1}$
$\vdots$
$d_{N-1,0}$ $\cdots$ $d_{N-1,N-1}$
  • NN is the horizontal and vertical size of the board and satisfies 20N4020\leq N\leq 40.
  • hi,0hi,N1h_{i,0}\cdots h_{i,N-1} is a string of length NN consisting of only 0 and 1. hi,j=1h_{i,j}=1 if and only if there is a wall between square (i,j)(i,j) and its lower neighbor (i+1,j)(i+1,j).
  • vi,0vi,N2v_{i,0}\cdots v_{i,N-2} is a string of length N1N-1 consisting of only 0 and 1. vi,j=1v_{i,j}=1 if and only if there is a wall between square (i,j)(i,j) and its right neighbor (i,j+1)(i,j+1).
  • All squares are guaranteed to be reachable from (0,0)(0, 0).
  • di,jd_{i,j} is an integer value representing the susceptibility to dirt of square (i,j)(i,j) and satisfies 1di,j1031\leq d_{i,j}\leq 10^3.

Output

Represent a move up, down, left, or right by U, D, L, or R, respectively. Represent the cleaning route of length LL as a string of LL characters corresponding to each move, and output it in a single line to Standard Output.

<a href="https://img.atcoder.jp/ahc027/aPdjCUIZ.html?lang=en&seed=0&output=sample">Show example</a>

Sample Solution

<details> This is a sample solution in Python. In this program, by moving along the depth-first search tree starting from (0,0), each edge in the tree is passed twice, once on the way there and once on the way back, and the program outputs a cleaning route that returns to (0,0). <pre class="prettyprint linenums"> import sys sys.setrecursionlimit(1000000)

N = int(input()) h = [input() for _ in range(N-1)] v = [input() for _ in range(N)] d = [list(map(int, input().split())) for _ in range(N)]

visited = [[False for _ in range(N)] for _ in range(N)] DIJ = [(0, 1), (1, 0), (0, -1), (-1, 0)] DIR = "RDLU"

def dfs(i, j): visited[i][j] = True for dir in range(4): di, dj = DIJ[dir] i2 = i + di j2 = j + dj if 0 <= i2 < N and 0 <= j2 < N and not visited[i2][j2]: if di == 0 and v[i][min(j, j2)] == '0' or dj == 0 and h[min(i, i2)][j] == '0': print(DIR[dir], end='') dfs(i2, j2) print(DIR[(dir + 2) % 4], end='')

dfs(0, 0) print() </pre>

</details>

Input Generation

<details> Let $\mathrm{randint}(L,U)$ be a function that generates a uniform random integer between $L$ and $U$, inclusive. Let $\mathrm{randdouble}(L,U)$ be a function that generates a uniform random floating-point number at least $L$ and less than $U$.

Generation of NN

N=randint(20,40)N=\mathrm{randint}(20,40).

Generation of hh and vv

Generate a parameter w=randint(1,N)w=\mathrm{randint}(1,N) that controls the number of walls. Starting from a state with no walls, generate walls by repeating the following operation ww times.

Randomly select one of the four directions (up, down, left, right). For the left direction, generate i=randint(0,N2)i=\mathrm{randint}(0,N-2), j=randint(0,N1)j=\mathrm{randint}(0,N-1), and k=randint(3,N/2)k=\mathrm{randint}(3,\lfloor N/2\rfloor). Then, set hi,jhi,max(jk+1,0)h_{i,j}\cdots h_{i,\max(j-k+1, 0)} to 11. Similarly, for the right direction, generate values in the same manner, and set hi,jhi,min(j+k1,N1)h_{i,j}\cdots h_{i,\min(j+k-1, N-1)} to 11. For the upward direction, generate i=randint(0,N1)i=\mathrm{randint}(0,N-1), j=randint(0,N2)j=\mathrm{randint}(0,N-2), and k=randint(3,N/2)k=\mathrm{randint}(3,\lfloor N/2\rfloor). Then, set vi,jvmax(ik+1,0),jv_{i,j}\cdots v_{\max(i-k+1, 0),j} to 11. Similarly, for the downward direction, generate values in the same manner, and set vi,jvmin(i+k1,N1),jv_{i,j}\cdots v_{\min(i+k-1, N-1),j} to 11.

After ww iterations are completed, check if all squares are reachable from (0,0)(0, 0), and if there are unreachable squares, remove all walls and redo the ww iterations.

Generation of dd

Generate a parameter c=randint(1,N/2)c=\mathrm{randint}(1,\lfloor N/2\rfloor) that determines the number of susceptible regions. Create an array dd' with di,j=0d'_{i,j}=0 for all (i,j)(i,j), and update dd' by repeating the following process cc times.

Generate i=randint(0,N1)i=\mathrm{randint}(0,N-1), j=randint(0,N1)j=\mathrm{randint}(0,N-1), m=randint(N,N2/c)m=\mathrm{randint}(N,\lfloor N^2/c\rfloor), and b=randdouble(0,2)b=\mathrm{randdouble}(0,2). Generate a set SS by starting from S=(i,j)S=\\{(i,j)\\} and repeating the following process until the size of SS becomes mm.

Randomly choose pSp\in S, and randomly choose one of the four directions (up, down, left, or right). If there is no wall in that direction from pp, add the adjacent square qq to SS.

For each square (i,j)S(i',j')\in S contained in the generated SS, overwrite di,j=bd'_{i',j'}=b.

After cc iterations are completed, generate di,j=round(10di,j+randdouble(0,1))d_{i,j}=\mathrm{round}(10^{d'_{i,j}+\mathrm{randdouble}(0,1)}) for each (i,j)(i,j).

</details>

Tools (Input generator and visualizer)

  • <a href="https://img.atcoder.jp/ahc027/aPdjCUIZ.html?lang=en">Web version</a>: This is more powerful than the local version providing animations.
  • <a href="https://img.atcoder.jp/ahc027/aPdjCUIZ_v2.zip">Local version</a>: You need a compilation environment of <a href="https://www.rust-lang.org/">Rust language</a>.
    • <a href="https://img.atcoder.jp/ahc027/aPdjCUIZ_windows_v2.zip">Pre-compiled binary for Windows</a>: If you are not familiar with the Rust language environment, please use this instead.

Please be aware that sharing visualization results or discussing solutions/ideas during the contest is prohibited.

{sample example}

Subject outcomes

  • claude-4-sonnet correct
  • claude-4.1-opus correct
  • claude-4.5-haiku correct
  • qwen3.6-flash incorrect
  • qwen3.7-max incorrect
  • step-3.7-flash-medium incorrect
Item 884% solve rate

Problem Statement

AtCoder Inc. operates a food delivery service, AtCoder Foods, that leisurely delivers food that tastes good even if it gets cold. This service receives a large number of delivery orders in advance, and processes multiple deliveries simultaneously to improve efficiency. The current service area is represented as a square area (x,y)0x,y800\\{(x,y)\mid 0\leq x, y\leq 800\\} on a two-dimensional plane, with AtCoder's office located at the center (400,400)(400, 400). There are 1000 orders today, and the ii (1i10001\leq i\leq 1000)-th order is a food delivery request from a restaurant in (ai,bi)(a_i, b_i) to a location in (ci,di)(c_i, d_i).

Today's quota for Takahashi, a delivery man, is to process 50 orders. He can freely choose a subset S1,,1000S\subseteq\\{1,\cdots,1000\\} of size exactly 50 from the 1000 orders and deliver on a route (x1,y1),,(xn,yn)(x_1,y_1),\cdots,(x_n,y_n) satisfying the following conditions.

  1. For each iSi\in S, visit (ci,di)(c_i, d_i) after visiting (ai,bi)(a_i,b_i). That is, there exists an integer pair (s,t)(s, t) such that (xs,ys)=(ai,bi)(x_s,y_s)=(a_i,b_i), (xt,yt)=(ci,di)(x_t,y_t)=(c_i,d_i), and s<ts<t.
  2. (x1,y1)=(xn,yn)=(400,400)(x_1,y_1)=(x_n,y_n)=(400, 400).

After picking up food at one restaurant, he may pick up food at another restaurant or deliver food to another destination before delivering that food to the destination. He is so powerful that he can carry arbitrary numbers of dishes simultaneously.

Moving from (xi,yi)(x_i,y_i) to (xi+1,yi+1)(x_{i+1},y_{i+1}) takes time equal to the Manhattan distance xixi+1+yiyi+1|x_i-x_{i+1}|+|y_i-y_{i+1}|, and the total travel time for the delivery route is T=i=1n1xixi+1+yiyi+1T=\sum_{i=1}^{n-1} |x_i - x_{i+1}|+|y_i - y_{i+1}|. Please optimize SS and delivery routes so that the total travel time is as short as possible.

Scoring

For the total travel time TT of the output delivery route, you will get a score of round(108/(1000+T))\mathrm{round}(10^8/(1000+T)).

There are 100 test cases, and the score of a submission is the total score for each test case. If you get a result other than <span class='label label-success' data-toggle='tooltip' data-placement='top' title="Accepted">AC</span> for one or more test cases, the score of the submission will be zero. The highest score obtained during the contest time will determine the final ranking, and there will be no system test after the contest. If more than one participant gets the same score, the ranking will be determined by the submission time of the submission that received that score.

Input

Input is given from Standard Input in the following format:

$a_1$ $b_1$ $c_1$ $d_1$
$\vdots$
$a_{1000}$ $b_{1000}$ $c_{1000}$ $d_{1000}$

Each ai,bi,ci,dia_i, b_i, c_i, d_i is an integer between 00 and 800800, inclusive, where (ai,bi)(a_i, b_i) represents the coordinates of the restaurant, and (ci,di)(c_i, d_i) represents the coordinates of the destination. (ai,bi)(ci,di)(a_i,b_i)\neq (c_i,d_i) is satisfied, but for different orders jj, there is a possibility that (ai,bi),(ci,di)(aj,bj),(cj,dj)\\{(a_i,b_i),(c_i,d_i)\\}\cap\\{(a_j,b_j),(c_j,d_j)\\}\neq\emptyset.

Output

Let the set of chosen orders be r1,,rmr_1,\cdots,r_m (1ri10001\leq r_i\leq 1000), and the delivery route be (x1,y1),,(xn,yn)(x_1,y_1),\cdots,(x_n,y_n) (0xi,yi8000\leq x_i,y_i\leq 800), output to Standard Output in the following format.

$m$ $r_1$ $\cdots$ $r_m$
$n$ $x_1$ $y_1$ $\cdots$ $x_n$ $y_n$

You may output multiple times for visualization purposes. If your program outputs multiple times, only the last output will be used for scoring. The final output must satisfy m=50m=50, but intermediate outputs with m50m\neq 50 are allowed for visualization.

Input Generation

Let rand(L,U)\mathrm{rand}(L,U) be a function that generates a uniform random integer between LL and UU, inclusive. For each i=1,,1000i=1,\cdots,1000, we generate an order (ai,bi,ci,di)(a_i, b_i, c_i, d_i) as follows.

We generate ai=rand(0,800)a_i=\mathrm{rand}(0, 800), bi=rand(0,800)b_i=\mathrm{rand}(0, 800), ci=rand(0,800)c_i=\mathrm{rand}(0, 800), and di=rand(0,800)d_i=\mathrm{rand}(0, 800). Redo the generation as long as the Manhattan distance aici+bidi|a_i-c_i|+|b_i-d_i| is less than 100.

Tools (Input generator and visualizer)

  • <a href="https://img.atcoder.jp/ahc006/c21daebb77aa4d38d65f4d7f7c7249.zip">Local version</a>: You need a compilation environment of <a href="https://www.rust-lang.org/">Rust language</a>.
  • <a href="https://img.atcoder.jp/ahc006/c21daebb77aa4d38d65f4d7f7c7249.html">Web version</a>: This is more powerful than the local version and can display animations.

**Sharing visualization results is not allowed until the end of the contest. **

{sample example}

Subject outcomes

  • claude-4-sonnet correct
  • claude-4.1-opus correct
  • claude-4.5-haiku correct
  • qwen3.5-flash incorrect
  • qwen3.6-plus incorrect
  • qwen3.6-flash incorrect
Item 987% solve rate

Story

Takahashi, who loves loop lines, is playing with a toy train. As shown in the figure below, this toy consists of square tiles containing railroad lines. By rotating the tiles, he can connect lines and play with toy trains running on the lines. Because Takahashi has two toy trains, please create two large loop lines as much as possible.

<table> <tr align="center"> <td> <svg height="100" id="vis" viewBox="-5 -5 100 100" width="100" xmlns="http://www.w3.org/2000/svg"> <rect fill="white" height="100" width="100" x="-5" y="-5"/> <line stroke="lightgray" stroke-width="1" x1="0" x2="90" y1="0" y2="0"/> <line stroke="lightgray" stroke-width="1" x1="0" x2="0" y1="0" y2="90"/> <line stroke="lightgray" stroke-width="1" x1="0" x2="90" y1="30" y2="30"/> <line stroke="lightgray" stroke-width="1" x1="30" x2="30" y1="0" y2="90"/> <line stroke="lightgray" stroke-width="1" x1="0" x2="90" y1="60" y2="60"/> <line stroke="lightgray" stroke-width="1" x1="60" x2="60" y1="0" y2="90"/> <line stroke="lightgray" stroke-width="1" x1="0" x2="90" y1="90" y2="90"/> <line stroke="lightgray" stroke-width="1" x1="90" x2="90" y1="0" y2="90"/> <defs> <g id="rail1" stroke-width="2"> <line x1="12" x2="12" y1="0" y2="30"/> <line x1="18" x2="18" y1="0" y2="30"/> <line x1="12" x2="18" y1="3" y2="3"/> <line x1="12" x2="18" y1="9" y2="9"/> <line x1="12" x2="18" y1="15" y2="15"/> <line x1="12" x2="18" y1="21" y2="21"/> <line x1="12" x2="18" y1="27" y2="27"/> </g> <g fill="none" id="rail2" stroke-width="2"> <path d="M12,0 A12,12 0 0,1 0,12"/> <path d="M18,0 A18,18 0 0,1 0,18"/> <line x1="12" x2="18" y1="2" y2="3"/> <line x1="11" x2="16" y1="5" y2="8"/> <line x1="8" x2="13" y1="8" y2="13"/> <line x1="5" x2="8" y1="11" y2="16"/> <line x1="2" x2="3" y1="12" y2="18"/> </g> </defs> <use href="#rail1" stroke="silver" x="0" y="0"/> <use href="#rail2" stroke="silver" x="30" y="0"/> <use href="#rail2" stroke="silver" transform="rotate(180,45,15)" x="30" y="0"/> <use href="#rail2" stroke="silver" x="60" y="0"/> <use href="#rail2" stroke="silver" x="0" y="30"/> <use href="#rail2" stroke="silver" transform="rotate(180,15,45)" x="0" y="30"/> <use href="#rail2" stroke="silver" x="30" y="30"/> <use href="#rail2" stroke="silver" transform="rotate(180,45,45)" x="30" y="30"/> <use href="#rail2" stroke="silver" transform="rotate(180,75,45)" x="60" y="30"/> <use href="#rail2" stroke="silver" transform="rotate(270,15,75)" x="0" y="60"/> <use href="#rail2" stroke="silver" transform="rotate(90,15,75)" x="0" y="60"/> <use href="#rail2" stroke="silver" x="30" y="60"/> <use href="#rail2" stroke="silver" transform="rotate(180,45,75)" x="30" y="60"/> <use href="#rail2" stroke="silver" x="60" y="60"/> </svg> </td> <td> <svg height="100" id="vis" viewBox="-5 -5 100 100" width="100" xmlns="http://www.w3.org/2000/svg"> <rect fill="white" height="100" width="100" x="-5" y="-5"/> <line stroke="lightgray" stroke-width="1" x1="0" x2="90" y1="0" y2="0"/> <line stroke="lightgray" stroke-width="1" x1="0" x2="0" y1="0" y2="90"/> <line stroke="lightgray" stroke-width="1" x1="0" x2="90" y1="30" y2="30"/> <line stroke="lightgray" stroke-width="1" x1="30" x2="30" y1="0" y2="90"/> <line stroke="lightgray" stroke-width="1" x1="0" x2="90" y1="60" y2="60"/> <line stroke="lightgray" stroke-width="1" x1="60" x2="60" y1="0" y2="90"/> <line stroke="lightgray" stroke-width="1" x1="0" x2="90" y1="90" y2="90"/> <line stroke="lightgray" stroke-width="1" x1="90" x2="90" y1="0" y2="90"/> <defs> <g id="rail1" stroke-width="2"> <line x1="12" x2="12" y1="0" y2="30"/> <line x1="18" x2="18" y1="0" y2="30"/> <line x1="12" x2="18" y1="3" y2="3"/> <line x1="12" x2="18" y1="9" y2="9"/> <line x1="12" x2="18" y1="15" y2="15"/> <line x1="12" x2="18" y1="21" y2="21"/> <line x1="12" x2="18" y1="27" y2="27"/> </g> <g fill="none" id="rail2" stroke-width="2"> <path d="M12,0 A12,12 0 0,1 0,12"/> <path d="M18,0 A18,18 0 0,1 0,18"/> <line x1="12" x2="18" y1="2" y2="3"/> <line x1="11" x2="16" y1="5" y2="8"/> <line x1="8" x2="13" y1="8" y2="13"/> <line x1="5" x2="8" y1="11" y2="16"/> <line x1="2" x2="3" y1="12" y2="18"/> </g> </defs> <use href="#rail1" stroke="silver" x="0" y="0"/> <use href="#rail2" stroke="silver" x="30" y="0"/> <g> <use href="#rail2" stroke="brown" transform="rotate(180,45,15)" x="30" y="0"/> </g> <g> <use href="#rail2" stroke="brown" transform="rotate(270,75,15)" x="60" y="0"/> </g> <use href="#rail2" stroke="silver" x="0" y="30"/> <g> <use href="#rail2" stroke="brown" transform="rotate(180,15,45)" x="0" y="30"/> </g> <g> <use href="#rail2" stroke="brown" x="30" y="30"/> </g> <g> <use href="#rail2" stroke="brown" transform="rotate(180,45,45)" x="30" y="30"/> </g> <g> <use href="#rail2" stroke="brown" x="60" y="30"/> </g> <use href="#rail2" stroke="silver" transform="rotate(270,15,75)" x="0" y="60"/> <g> <use href="#rail2" stroke="brown" transform="rotate(90,15,75)" x="0" y="60"/> </g> <g> <use href="#rail2" stroke="brown" x="30" y="60"/> </g> <use href="#rail2" stroke="silver" transform="rotate(180,45,75)" x="30" y="60"/> <use href="#rail2" stroke="silver" x="60" y="60"/> </svg> </td> </tr> <tr align="center"> <td> Initial State. </td> <td> After rotating the top-right tile and the middle-right tile. </td> </tr> </table>

Problem Statement

You are given tiles containing railroad lines arranged in a 30 x 30 square. There are 8 types of tiles by distinguishing rotations which are numbered as follows.

<svg height="70" id="vis" viewBox="-5 -5 250 70" width="250" xmlns="http://www.w3.org/2000/svg"> <rect fill="white" height="70" width="250" x="-5" y="-5"/> <line stroke="lightgray" stroke-width="1" x1="0" x2="240" y1="0" y2="0"/> <line stroke="lightgray" stroke-width="1" x1="0" x2="0" y1="0" y2="60"/> <line stroke="lightgray" stroke-width="1" x1="0" x2="240" y1="30" y2="30"/> <line stroke="lightgray" stroke-width="1" x1="30" x2="30" y1="0" y2="60"/> <line stroke="lightgray" stroke-width="1" x1="0" x2="240" y1="60" y2="60"/> <line stroke="lightgray" stroke-width="1" x1="60" x2="60" y1="0" y2="60"/> <line stroke="lightgray" stroke-width="1" x1="90" x2="90" y1="0" y2="60"/> <line stroke="lightgray" stroke-width="1" x1="120" x2="120" y1="0" y2="60"/> <line stroke="lightgray" stroke-width="1" x1="150" x2="150" y1="0" y2="60"/> <line stroke="lightgray" stroke-width="1" x1="180" x2="180" y1="0" y2="60"/> <line stroke="lightgray" stroke-width="1" x1="210" x2="210" y1="0" y2="60"/> <line stroke="lightgray" stroke-width="1" x1="240" x2="240" y1="0" y2="60"/> <text font-size="22" text-anchor="middle" x="15" y="55"> 0 </text> <text font-size="22" text-anchor="middle" x="45" y="55"> 1 </text> <text font-size="22" text-anchor="middle" x="75" y="55"> 2 </text> <text font-size="22" text-anchor="middle" x="105" y="55"> 3 </text> <text font-size="22" text-anchor="middle" x="135" y="55"> 4 </text> <text font-size="22" text-anchor="middle" x="165" y="55"> 5 </text> <text font-size="22" text-anchor="middle" x="195" y="55"> 6 </text> <text font-size="22" text-anchor="middle" x="225" y="55"> 7 </text> <defs> <g id="rail1" stroke-width="2"> <line x1="12" x2="12" y1="0" y2="30"/> <line x1="18" x2="18" y1="0" y2="30"/> <line x1="12" x2="18" y1="3" y2="3"/> <line x1="12" x2="18" y1="9" y2="9"/> <line x1="12" x2="18" y1="15" y2="15"/> <line x1="12" x2="18" y1="21" y2="21"/> <line x1="12" x2="18" y1="27" y2="27"/> </g> <g fill="none" id="rail2" stroke-width="2"> <path d="M12,0 A12,12 0 0,1 0,12"/> <path d="M18,0 A18,18 0 0,1 0,18"/> <line x1="12" x2="18" y1="2" y2="3"/> <line x1="11" x2="16" y1="5" y2="8"/> <line x1="8" x2="13" y1="8" y2="13"/> <line x1="5" x2="8" y1="11" y2="16"/> <line x1="2" x2="3" y1="12" y2="18"/> </g> </defs> <use href="#rail2" stroke="silver" x="0" y="0"/> <use href="#rail2" stroke="silver" transform="rotate(270,45,15)" x="30" y="0"/> <use href="#rail2" stroke="silver" transform="rotate(180,75,15)" x="60" y="0"/> <use href="#rail2" stroke="silver" transform="rotate(90,105,15)" x="90" y="0"/> <use href="#rail2" stroke="silver" x="120" y="0"/> <use href="#rail2" stroke="silver" transform="rotate(180,135,15)" x="120" y="0"/> <use href="#rail2" stroke="silver" transform="rotate(270,165,15)" x="150" y="0"/> <use href="#rail2" stroke="silver" transform="rotate(90,165,15)" x="150" y="0"/> <use href="#rail1" stroke="silver" transform="rotate(90,195,15)" x="180" y="0"/> <use href="#rail1" stroke="silver" x="210" y="0"/> </svg>

Tiles 0 to 3 contain one curved line, tiles 4 and 5 contain two curved lines, and tiles 6 and 7 contain one straight line. Each tile can be rotated every 90 degrees. By rotating a tile 90 degrees counterclockwise, the tile will become as follows.

<svg height="70" id="vis" viewBox="-5 -5 250 70" width="250" xmlns="http://www.w3.org/2000/svg"> <rect fill="white" height="70" width="250" x="-5" y="-5"/> <line stroke="lightgray" stroke-width="1" x1="0" x2="240" y1="0" y2="0"/> <line stroke="lightgray" stroke-width="1" x1="0" x2="0" y1="0" y2="60"/> <line stroke="lightgray" stroke-width="1" x1="0" x2="240" y1="30" y2="30"/> <line stroke="lightgray" stroke-width="1" x1="30" x2="30" y1="0" y2="60"/> <line stroke="lightgray" stroke-width="1" x1="0" x2="240" y1="60" y2="60"/> <line stroke="lightgray" stroke-width="1" x1="60" x2="60" y1="0" y2="60"/> <line stroke="lightgray" stroke-width="1" x1="90" x2="90" y1="0" y2="60"/> <line stroke="lightgray" stroke-width="1" x1="120" x2="120" y1="0" y2="60"/> <line stroke="lightgray" stroke-width="1" x1="150" x2="150" y1="0" y2="60"/> <line stroke="lightgray" stroke-width="1" x1="180" x2="180" y1="0" y2="60"/> <line stroke="lightgray" stroke-width="1" x1="210" x2="210" y1="0" y2="60"/> <line stroke="lightgray" stroke-width="1" x1="240" x2="240" y1="0" y2="60"/> <text font-size="22" text-anchor="middle" x="15" y="55"> 1 </text> <text font-size="22" text-anchor="middle" x="45" y="55"> 2 </text> <text font-size="22" text-anchor="middle" x="75" y="55"> 3 </text> <text font-size="22" text-anchor="middle" x="105" y="55"> 0 </text> <text font-size="22" text-anchor="middle" x="135" y="55"> 5 </text> <text font-size="22" text-anchor="middle" x="165" y="55"> 4 </text> <text font-size="22" text-anchor="middle" x="195" y="55"> 7 </text> <text font-size="22" text-anchor="middle" x="225" y="55"> 6 </text> <defs> <g id="rail1" stroke-width="2"> <line x1="12" x2="12" y1="0" y2="30"/> <line x1="18" x2="18" y1="0" y2="30"/> <line x1="12" x2="18" y1="3" y2="3"/> <line x1="12" x2="18" y1="9" y2="9"/> <line x1="12" x2="18" y1="15" y2="15"/> <line x1="12" x2="18" y1="21" y2="21"/> <line x1="12" x2="18" y1="27" y2="27"/> </g> <g fill="none" id="rail2" stroke-width="2"> <path d="M12,0 A12,12 0 0,1 0,12"/> <path d="M18,0 A18,18 0 0,1 0,18"/> <line x1="12" x2="18" y1="2" y2="3"/> <line x1="11" x2="16" y1="5" y2="8"/> <line x1="8" x2="13" y1="8" y2="13"/> <line x1="5" x2="8" y1="11" y2="16"/> <line x1="2" x2="3" y1="12" y2="18"/> </g> </defs> <use href="#rail2" stroke="silver" transform="rotate(270,15,15)" x="0" y="0"/> <use href="#rail2" stroke="silver" transform="rotate(180,45,15)" x="30" y="0"/> <use href="#rail2" stroke="silver" transform="rotate(90,75,15)" x="60" y="0"/> <use href="#rail2" stroke="silver" x="90" y="0"/> <use href="#rail2" stroke="silver" transform="rotate(270,135,15)" x="120" y="0"/> <use href="#rail2" stroke="silver" transform="rotate(90,135,15)" x="120" y="0"/> <use href="#rail2" stroke="silver" x="150" y="0"/> <use href="#rail2" stroke="silver" transform="rotate(180,165,15)" x="150" y="0"/> <use href="#rail1" stroke="silver" x="180" y="0"/> <use href="#rail1" stroke="silver" transform="rotate(90,225,15)" x="210" y="0"/> </svg>

Since there are no branches on the lines, each line is part of a path or cycle. A set of lines forming a cycle is called a "loop line," and its length is defined as the number of times to move from a tile to its adjacent tile in a round trip along the loop line. For example, the loop line below consists of 7 tiles, but its length is 8 because it passes through the center tile twice.

<svg height="100" id="vis" viewBox="-5 -5 100 100" width="100" xmlns="http://www.w3.org/2000/svg"> <rect fill="white" height="100" width="100" x="-5" y="-5"/> <line stroke="lightgray" stroke-width="1" x1="0" x2="90" y1="0" y2="0"/> <line stroke="lightgray" stroke-width="1" x1="0" x2="0" y1="0" y2="90"/> <line stroke="lightgray" stroke-width="1" x1="0" x2="90" y1="30" y2="30"/> <line stroke="lightgray" stroke-width="1" x1="30" x2="30" y1="0" y2="90"/> <line stroke="lightgray" stroke-width="1" x1="0" x2="90" y1="60" y2="60"/> <line stroke="lightgray" stroke-width="1" x1="60" x2="60" y1="0" y2="90"/> <line stroke="lightgray" stroke-width="1" x1="0" x2="90" y1="90" y2="90"/> <line stroke="lightgray" stroke-width="1" x1="90" x2="90" y1="0" y2="90"/> <defs> <g id="rail1" stroke-width="2"> <line x1="12" x2="12" y1="0" y2="30"/> <line x1="18" x2="18" y1="0" y2="30"/> <line x1="12" x2="18" y1="3" y2="3"/> <line x1="12" x2="18" y1="9" y2="9"/> <line x1="12" x2="18" y1="15" y2="15"/> <line x1="12" x2="18" y1="21" y2="21"/> <line x1="12" x2="18" y1="27" y2="27"/> </g> <g fill="none" id="rail2" stroke-width="2"> <path d="M12,0 A12,12 0 0,1 0,12"/> <path d="M18,0 A18,18 0 0,1 0,18"/> <line x1="12" x2="18" y1="2" y2="3"/> <line x1="11" x2="16" y1="5" y2="8"/> <line x1="8" x2="13" y1="8" y2="13"/> <line x1="5" x2="8" y1="11" y2="16"/> <line x1="2" x2="3" y1="12" y2="18"/> </g> </defs> <use href="#rail1" stroke="silver" x="0" y="0"/> <use href="#rail2" stroke="silver" x="30" y="0"/> <g> <use href="#rail2" stroke="brown" transform="rotate(180,45,15)" x="30" y="0"/> </g> <g> <use href="#rail2" stroke="brown" transform="rotate(270,75,15)" x="60" y="0"/> </g> <use href="#rail2" stroke="silver" x="0" y="30"/> <g> <use href="#rail2" stroke="brown" transform="rotate(180,15,45)" x="0" y="30"/> </g> <g> <use href="#rail2" stroke="brown" x="30" y="30"/> </g> <g> <use href="#rail2" stroke="brown" transform="rotate(180,45,45)" x="30" y="30"/> </g> <g> <use href="#rail2" stroke="brown" x="60" y="30"/> </g> <use href="#rail2" stroke="silver" transform="rotate(270,15,75)" x="0" y="60"/> <g> <use href="#rail2" stroke="brown" transform="rotate(90,15,75)" x="0" y="60"/> </g> <g> <use href="#rail2" stroke="brown" x="30" y="60"/> </g> <use href="#rail2" stroke="silver" transform="rotate(180,45,75)" x="30" y="60"/> <use href="#rail2" stroke="silver" x="60" y="60"/> </svg>

Your task is to determine the number of times to rotate each tile.

Scoring

Let L1L_1 be the length of the longest loop line obtained by rotating the tiles according to the output, and L2L_2 be the length of the second longest one (L1=L2L_1=L_2 if there is more than one longest one). Then, you will get a score of L1×L2L_1\times L_2. If the number of loop lines is less than or equal to 11, the score for that test case is 00.

There are 100 test cases, and the score of a submission is the total score for each test case. If you get a result other than <span class='label label-success' data-toggle='tooltip' data-placement='top' title="Accepted">AC</span> for one or more test cases, the score of the submission will be zero. The highest score obtained during the contest time will determine the final ranking, and there will be no system test after the contest. If more than one participant gets the same score, the ranking will be determined by the submission time of the submission that received that score.

Hints on how to compute the length of a loop line.

<details> <font color="red"> Pseudo code has been updated. </font> You can compute the length of a loop line, for example, as follows. Let `tiles` be a two-dimensional array containing the tile states. By numbering the directions 0, 1, 2, 3 in order of left, up, right, and down, the change in coordinates is represented by the arrays `di = [0, -1, 0, 1]` and `dj = [-1, 0, 1, 0]`. When a train enters a tile of state `t` from its adjacent tile in direction `d`, let `to[t][d]` be the direction to the next tile, or `-1` if the train cannot enter from such a direction, then we obtain the following two-dimensional array. ``` to = [ [1, 0, -1, -1], [3, -1, -1, 0], [-1, -1, 3, 2], [-1, 2, 1, -1], [1, 0, 3, 2], [3, 2, 1, 0], [2, -1, 0, -1], [-1, 3, -1, 1], ]; ``` When a train enters tile at position `(i, j)` from its adjacent tile in direction `d`, you can update these variables as follows.
d2 = to[tiles[i][j]][d]; // Direction to the next tile
if (d2 == -1) return 0; // The line is broken.
i += di[d2];
j += dj[d2];
if (i < 0 || i >= 30 || j < 0 || j >= 30) return 0; // The line is broken.
d = (d2 + 2) % 4; // Direction to the previous tile.

After repeating this process until the train returns to its initial position and direction (note that it may pass through the same tile twice), the number of iterations is the length of the loop line.

// Suppose that a train enters a tile (si, sj) from direction sd.
i = si;
j = sj;
d = sd;
length = 0;
loop {
	d2 = to[tiles[i][j]][d];
	if (d2 == -1) return 0;
	i += di[d2];
	j += dj[d2];
	if (i < 0 || i >= 30 || j < 0 || j >= 30) return 0;
	d = (d2 + 2) % 4;
	length += 1;
	if (i == si && j == sj && d == sd) return length;
}
</details>

Input

Input is given from Standard Input in the following format:

$t_{0,0}$ $\cdots$ $t_{0,29}$
$\vdots$
$t_{29,0}$ $\cdots$ $t_{29,29}$

Each ti,0ti,29t_{i,0}\cdots t_{i,29} is a string of 3030 characters. Let (i,j)(i,j) denote the ii-th (0i29)(0\leq i\leq 29) tile from the top and jj-th (0j29)(0\leq j\leq 29) tile from the left. Then, ti,jt_{i,j} is an integer between 00 and 77 representing the state of the tile (i,j)(i, j).

Output

Let ri,jr_{i,j} (0ri,j30\leq r_{i,j}\leq 3) be the number of times the tile (i,j)(i,j) is rotated 90 degrees counterclockwise. Output a string of length 900900 such that the 30i+j30i+j-th character is ri,jr_{i,j} in one line to Standard Output.

<a href="https://img.atcoder.jp/ahc010/d3a6c91ee76cb8.html?lang=en&show=example">Show example</a>

Input Generation

Let rand(L,U)\mathrm{rand}(L,U) be a function that generates a uniform random integer between LL and UU, inclusive.

Each ti,jt_{i,j} is independently generated as follows.

  • With probability 25%, ti,j=rand(0,3)t_{i,j}=\mathrm{rand}(0, 3).
  • With probability 50%, ti,j=rand(4,5)t_{i,j}=\mathrm{rand}(4, 5).
  • With probability 25%, ti,j=rand(6,7)t_{i,j}=\mathrm{rand}(6, 7).

Tools (Input generator and visualizer)

  • <a href="https://img.atcoder.jp/ahc010/d3a6c91ee76cb8.html?lang=en">Web version</a>: This is more powerful than the local version and can display animations.
  • <a href="https://img.atcoder.jp/ahc010/d3a6c91ee76cb8.zip">Local version</a>: You need a compilation environment of <a href="https://www.rust-lang.org/">Rust language</a>.
    • <a href="https://img.atcoder.jp/ahc010/d3a6c91ee76cb8_windows.zip">Pre-compiled binary for Windows</a>: If you are not familiar with the Rust language environment, please use this instead.

<font color="red">**Sharing visualization results is not allowed until the end of the contest. **</font>

{sample example}

Subject outcomes

  • claude-4.1-opus correct
  • claude-4.5-haiku correct
  • claude-4.5-sonnet correct
  • nova-premier-v1 incorrect
  • qwen3.5-35b-a3b incorrect
  • qwen3.6-flash incorrect
Item 1089% solve rate

Problem Statement

There is a skating rink consisting of N×NN \times N squares. Let (0,0)(0, 0) be the coordinates of the top-left square, and (i,j)(i, j) be the coordinates of the square located ii squares down and jj squares to the right from there. All squares outside the N×NN \times N area are covered with blocks and are impassable. Initially, there are no blocks inside the N×NN \times N area.

You start at the initial position (i0,j0)(i_0, j_0) and must visit the specified target squares (i1,j1),,(iM1,jM1)(i_1, j_1), \dots, (i_{M-1}, j_{M-1}) in the given order.

At each turn, you may choose one of the four cardinal directions and perform one of the following actions:

  • Move: Move one square in the specified direction. You cannot move into a square containing a block.
  • Slide: Continue sliding in the specified direction until you hit a block.
  • Alter: Place a block on the adjacent square in the specified direction if it does not already contain one; otherwise, remove the existing block. You may not specify a square outside the N×NN \times N area. It is also allowed to place a block on a current or future target square; however, you must remove the block in order to visit that square.

If you slide over a target square without stopping on it, it is not considered visited. A target square is considered visited only if you either stop on it after a Slide, or move onto it directly via a Move.

You must visit the target squares in the given order. Even if you pass over a later target square before visiting earlier ones, it is not considered visited at that time. You will need to visit it again when its turn in the sequence arrives.

You may perform at most 2NM2NM actions. Visit all target squares in the specified order using as few turns as possible.

Scoring

Let TT be the length of the output action sequence, and mm be the number of target squares successfully visited. Then, you will obtain the following score.

  • If m<M1m<M-1, m+1m+1
  • If m=M1m=M-1, M+2NMTM+2NM-T

There are 150150 test cases, and the score of a submission is the total score for each test case. If your submission produces an illegal output or exceeds the time limit for some test cases, the submission itself will be judged as <span class='label label-warning' data-toggle='tooltip' data-placement='top' title="Wrong Answer">WA</span> or <span class='label label-warning' data-toggle='tooltip' data-placement='top' title="Time Limit Exceeded">TLE</span> , and the score of the submission will be zero. The highest score obtained during the contest will determine the final ranking, and there will be no system test after the contest. If more than one participant gets the same score, they will be ranked in the same place regardless of the submission time.

Input

Input is given from Standard Input in the following format:

$N$ $M$
$i_0$ $j_0$
$\vdots$
$i_{M-1}$ $j_{M-1}$
  • In all test cases, N=20N = 20 and M=40M = 40 are fixed.
  • The coordinates (ik,jk)(i_k, j_k) of the initial position and each target square are integers satisfying 0ik,jkN10 \leq i_k, j_k \leq N-1, and all coordinates are distinct.

Output

At each turn, represent the selected action and direction using a single uppercase alphabet letter as follows.

Actions

  • Move: M
  • Slide: S
  • Alter: A

Directions

  • Up: U
  • Down: D
  • Left: L
  • Right: R

Let ata_t and dtd_t denote the action and direction selected at turn tt (t=0,1,,T1t = 0, 1, \dots, T-1), respectively.
Then, output to Standard Output in the following format:

$a_0$ $d_0$
$\vdots$
$a_{T-1}$ $d_{T-1}$

<a href="https://img.atcoder.jp/ahc046/EuNd3uow.html?lang=en&seed=0&output=sample">Show example</a>

Input Generation

The initial position and the target squares are generated according to the following procedure.

First, randomly shuffle the coordinates of all N2N^2 squares. Then, take the first MM coordinates from the shuffled list and assign them sequentially as (i0,j0),(i1,j1),,(iM1,jM1)(i_0, j_0), (i_1, j_1), \dots, (i_{M-1}, j_{M-1}).

Tools (Input generator and visualizer)

  • <a href="https://img.atcoder.jp/ahc046/EuNd3uow.html?lang=en">Web version</a>: This is more powerful than the local version providing animations and manual play.
  • <a href="https://img.atcoder.jp/ahc046/EuNd3uow.zip">Local version</a>: You need a compilation environment of <a href="https://www.rust-lang.org/">Rust language</a>.
    • <a href="https://img.atcoder.jp/ahc046/EuNd3uow_windows.zip">Pre-compiled binary for Windows</a>: If you are not familiar with the Rust language environment, please use this instead.

Please be aware that sharing visualization results or discussing solutions/ideas during the contest is prohibited.

{sample example}

Subject outcomes

  • claude-4-sonnet correct
  • claude-4.1-opus correct
  • claude-4.5-haiku correct
  • qwen3.5-plus incorrect
  • qwen3.5-35b-a3b incorrect
  • qwen3.5-397b-a17b incorrect
Item 1191% solve rate

Story

To celebrate the 10th anniversary of AtCoder Inc., we plan to hold an anniversary party with users invited. At the party, CEO Takahashi will cut a giant cake with a knife in straight lines and distribute pieces to the attendees. There are many strawberries on the cake, and he wants to distribute a piece containing dd strawberries to an attendee who has been participating in AtCoder's contests for dd years. Please find a way to cut the cake which maximizes the number of pieces to be distributed under the specified upper limit on the number of cuts. Note that Takahashi will eat all the pieces that are not distributed, so any leftovers are allowed.

<svg height="400" id="vis" viewBox="-5 -5 810 810" width="400" xmlns="http://www.w3.org/2000/svg"> <symbol viewBox="0 0 950.001 950.001" id="strawberry"> <path d="M97.96,525.152c15.452,203.891,186.558,424.849,377.056,424.849c190.543,0,361.649-220.958,377.011-424.849 c9.989-131.284-46.628-220.44-140.062-271.815c35.595-30.553,66.702-66.721,80.655-83.699c4.372-5.32,2.354-10.907-4.396-12.268 c-39.749-8.012-166.491-31.186-228.326-14.604c-31.713,8.513-48.912,20.782-57.246,35.299 c-1.297-31.134-6.179-74.02-23.199-112.543c-16.24-36.645-28.512-53.579-36.388-61.404c-4.885-4.853-15.573-4.934-22.097-2.728 l-69.683,23.568c-6.522,2.206-6.88,6.636-1.195,10.52c22.261,15.207,72.626,58.1,82.958,140.188 c-8.871-13.48-25.892-24.86-55.902-32.9c-61.836-16.582-188.578,6.592-228.327,14.604c-6.75,1.36-8.762,6.944-4.384,12.259 c14.601,17.728,47.952,56.4,85.525,87.739C141.318,309.46,88.329,397.566,97.96,525.152z M188.194,438.437 c8.82-23.672,21.091-44.972,37.081-62.975c52.137-2.688,130.693-9.903,175.845-28.983c22.75,26.819,52.97,48.349,68.731,58.656 c5.763,3.77,15.125,3.402,20.542-0.847c12.677-9.941,35.233-29.218,54.729-54.181c50.706,18.053,132.671,24.034,180.598,25.979 c15.591,17.805,27.198,38.771,35.931,62.039C745.259,443.075,733,457.697,733,475.681v39.867c0,22.011,17.963,39.863,39.956,39.863 c0.537,0,0.97-0.289,1.465-0.289c-1.972,18.677-5.266,37.468-10.19,56.145c-7.303-9.499-18.295-16.012-31.191-16.012 c-21.993,0-40.038,17.847-40.038,39.863v39.862c0,18.187,12.556,32.9,29.219,37.671c-11.241,19.686-24.111,38.119-38.128,55.566 c-7.348-8.04-18.285-13.531-30.871-13.531c-21.992,0-40.22,15.792-40.22,35.3v35.271c0,3.426,1.535,6.563,2.567,9.696 c-42.557,31.198-90.434,50.214-140.599,50.214c-37.538,0-73.772-10.641-107.59-29.047c4.256-6.316,7.621-13.531,7.621-21.704 v-39.863c0-22.016-17.964-39.867-40.002-39.867c-22.035,0-39.998,17.852-39.998,39.867v6.674 C230,736.995,184.79,644.588,175.43,555.386c21.991-0.062,39.57-17.868,39.57-39.838v-39.867 C215,458.28,203.733,443.881,188.194,438.437z"></path> <path d="M284.021,714.824c22.038,0,39.979-17.828,39.979-39.845v-39.862c0-22.017-17.94-39.863-39.979-39.863 c-21.994,0-40.021,17.847-40.021,39.863v39.862C244,696.996,262.026,714.824,284.021,714.824z"></path> <path d="M341.998,555.41c22.039,0,40.002-17.852,40.002-39.863v-39.866c0-22.015-17.964-39.862-40.002-39.862 c-22.034,0-39.998,17.847-39.998,39.862v39.867C302,537.559,319.962,555.41,341.998,555.41z"></path> <path d="M435,714.824c21.993,0,40-17.828,40-39.845v-39.862c0-22.017-18.007-39.863-40-39.863c-22.039,0-40,17.847-40,39.863 v39.862C395,696.996,412.96,714.824,435,714.824z"></path> <path d="M502.002,555.41c21.993,0,39.998-17.852,39.998-39.863v-39.866c0-22.015-18.005-39.862-39.998-39.862 c-22.039,0-40.002,17.847-40.002,39.862v39.867C462,537.559,479.963,555.41,502.002,555.41z"></path> <path d="M542,674.979c0,22.017,17.986,39.845,39.979,39.845c21.993,0,40.021-17.828,40.021-39.845v-39.862 c0-22.017-18.027-39.863-40.021-39.863c-21.993,0-39.979,17.848-39.979,39.864V674.979z"></path> <path d="M653.525,555.41c21.992,0,39.475-17.852,39.475-39.863v-39.866c0-22.015-17.481-39.862-39.475-39.862 c-21.994,0-39.525,17.847-39.525,39.862v39.867C614,537.559,631.532,555.41,653.525,555.41z"></path> <path d="M487.002,744.335c-22.04,0-40.002,17.851-40.002,39.867v39.863c0,21.991,17.963,39.844,40.002,39.844 c21.993,0,39.998-17.853,39.998-39.844v-39.863C527,762.187,508.995,744.335,487.002,744.335z"></path> </symbol> <rect fill="white" height="810" width="810" x="-5" y="-5"></rect> <circle cx="400" cy="400" fill="none" r="400" stroke="black" stroke-width="2"></circle> <g> <title> (-5000, 5000) d = 1 </title> <use xlink:href="#strawberry" x="150" ,="" y="150" width="100" height="100" fill="red"></use> </g> <g> <title> (2000, 6000) d = 3 </title> <use xlink:href="#strawberry" x="430" ,="" y="110" width="100" height="100" fill="red"></use> </g> <g> <title> (5000, 7000) d = 3 </title> <use xlink:href="#strawberry" x="550" ,="" y="70" width="100" height="100" fill="red"></use> </g> <g> <title> (7000, -1000) d = 3 </title> <use xlink:href="#strawberry" x="630" ,="" y="390" width="100" height="100" fill="red"></use> </g> <g> <title> (0, 0) d = 1 </title> <use xlink:href="#strawberry" x="350" ,="" y="350" width="100" height="100" fill="red"></use> </g> <g> <title> (-4000, -5000) d = 2 </title> <use xlink:href="#strawberry" x="190" ,="" y="550" width="100" height="100" fill="red"></use> </g> <g> <title> (1000, -8000) d = 2 </title> <use xlink:href="#strawberry" x="390" ,="" y="670" width="100" height="100" fill="red"></use> </g> <g> <title> (0, -2500) - (1, -2500) </title> <line stroke="black" stroke-width="1" x1="12.701665379258339" x2="787.2983346207417" y1="500" y2="500"></line> </g> <g> <title> (-3000, 0) - (-2999, 2) </title> <line stroke="black" stroke-width="1" x1="131.67472617169588" x2="476.3252738283041" y1="696.6505476566083" y2="7.349452343391749"></line> </g> <g> <title> (0, 5000) - (1, 4998) </title> <line stroke="black" stroke-width="1" x1="305.644042258373" x2="654.3559577416269" y1="11.288084516746094" y2="708.7119154832538"></line> </g> </svg>

In the above example, by cutting the cake with seven strawberries in three straight lines, we obtain two pieces with one strawberry, one piece with two strawberries, and one piece with three strawberries.

Problem Statement

There is a circular cake with a radius of 10410^4 centered at the origin and NN strawberries on top of it. The center of the ii-th strawberry is at the coordinates (xi,yi)(x_i, y_i) and satisfies xi2+yi2<108x_i^2+y_i^2<10^8. Takahashi can cut the cake in at most KK straight lines (not segments), which may intersect each other. You should specify the line to be cut as a straight line passing through two different integer coordinates (px,py)(p_x,p_y) and (qx,qy)(q_x,q_y) satisfying 109px,py,qx,qy109-10^9\leq p_x,p_y,q_x,q_y\leq 10^9. The two specified points can be outside of the cake. Because he is clumsy, he cannot stop or curve a single cut in the middle of the cut.

For each d=1,2,,10d=1,2,\cdots,10, you are given the number ada_d of attendees who have been participating in AtCoder's contests for dd years. Let bdb_d be the number of pieces with dd strawberries on them. Then we can distribute d=110min(ad,bd)\sum_{d=1}^{10} \min(a_d,b_d) pieces to attendees. Here, the ii-th strawberry belongs to a piece if and only if its center (xi,yi)(x_i, y_i) is contained inside (excluding the circumference) of the piece. If a strawberry is cut in a straight line that passes through its center, it belongs to no pieces.

Scoring

Let bdb_d be the number of pieces with dd strawberries on them. Then, you will get the following score.

round(106d=110min(ad,bd)d=110ad)\mathrm{round}\left(10^6 \frac{\sum_{d=1}^{10}\min(a_d,b_d)}{\sum_{d=1}^{10} a_d}\right)

If the number of cuts exceeds KK or you specify an invalid line, it will be judged as <span class='label label-warning' data-toggle='tooltip' data-placement='top' title="Wrong Answer">WA</span> .

There are 100 test cases, and the score of a submission is the total score for each test case. If you get a result other than <span class='label label-success' data-toggle='tooltip' data-placement='top' title="Accepted">AC</span> for one or more test cases, the score of the submission will be zero. The highest score obtained during the contest time will determine the final ranking, and there will be no system test after the contest. If more than one participant gets the same score, the ranking will be determined by the submission time of the submission that received that score.

Input

Input is given from Standard Input in the following format:

$N$ $K$
$a_1$ $a_2$ $\cdots$ $a_{10}$
$x_1$ $y_1$
$\vdots$
$x_N$ $y_N$
  • The number of strawberries NN is equal to the sum of the attendees' AtCoder years. That is, N=d=110d×adN=\sum_{d=1}^{10} d\times a_d.
  • For all test cases, the upper limit on the number of cuts is fixed to K=100K=100.
  • The number ada_d of attendees who have been participating in AtCoder's contests for dd years satisfies 1ad1001\leq a_d\leq 100.

Output

Let k(K)k (\leq K) be the number of cuts and let (pxi,pyi),(qxi,qyi)(p_x^i, p_y^i), (q_x^i, q_y^i) be the two points specifying the ii-th line, then output to Standard Output in the following format.

$k$
$p_x^1$ $p_y^1$ $q_x^1$ $q_y^1$
$\vdots$
$p_x^k$ $p_y^k$ $q_x^k$ $q_y^k$

<a href="https://img.atcoder.jp/ahc012/f756367b32.html?lang=en&seed=0&output=30%0A-1812+-1984+-9663+5131%0A-2586+7859+7423+-4798%0A193+8457+-300+2680%0A-149+-9041+6425+84%0A3329+-5601+-2055+-5156%0A4701+3753+-2852+-2578%0A-1417+-9909+-5593+-5639%0A-7013+2309+-7622+6652%0A-5296+-5647+-9646+-1031%0A-1275+8332+6134+1727%0A-6996+2724+933+4067%0A1134+3022+-9377+2501%0A6487+-7016+-6730+4775%0A9141+-7928+7794+-4177%0A-5164+-3440+-2341+-6820%0A-5940+2165+-1255+6089%0A1691+-1616+347+-8205%0A-7966+-6024+-2883+5136%0A6899+3888+1191+6179%0A-762+7446+2182+2919%0A-6843+1720+-8636+-9995%0A-2997+-6378+4359+-2044%0A-7094+2392+2381+558%0A-3241+7718+-2179+-1519%0A-358+247+-547+-5282%0A-376+-1900+7187+3663%0A7470+1828+4310+-103%0A-2289+7865+8712+-1962%0A-6942+-5180+-1909+326%0A3266+3617+3585+1090%0A">Show example</a>

You may output multiple solutions. If you output more than one solution, only the last one is used for scoring. You can compare solutions by using the web visualizer.

Input Generation

<details>

Let rand(L,U)\mathrm{rand}(L,U) be a function that generates a uniform random integer between LL and UU, inclusive.

Generation of a1,,a10a_1,\cdots,a_{10}

For each ii, we independently generate ai=rand(1,100)a_i=\mathrm{rand}(1, 100).

Generation of xi,yix_i, y_i

We generate the coordinates (xi,yi)(x_i, y_i) of the ii-th strawberry uniformly at random from the integer points satisfying xi2+yi2<108x_i^2+y_i^2<10^8. If the Euclidean distance between the new point and an existing point is less than or equal to 1010, we re-generate the point.

</details>

Tools (Input generator and visualizer)

  • <a href="https://img.atcoder.jp/ahc012/f756367b32.html?lang=en">Web version</a>: This is more powerful than the local version and can display animations.
  • <a href="https://img.atcoder.jp/ahc012/f756367b32.zip">Local version</a>: You need a compilation environment of <a href="https://www.rust-lang.org/">Rust language</a>.
    • <a href="https://img.atcoder.jp/ahc012/f756367b32_windows.zip">Pre-compiled binary for Windows</a>: If you are not familiar with the Rust language environment, please use this instead.

{sample example}

Subject outcomes

  • claude-4-sonnet correct
  • claude-4.5-haiku correct
  • claude-4.5-sonnet correct
  • qwen3.5-397b-a17b incorrect
  • qwen3.5-35b-a3b incorrect
  • qwen3.6-flash incorrect
Item 1294% solve rate

Story

At the AtCoder office, preparations are underway for a slightly belated Christmas party. CEO Takahashi has decided to go cut down rooted trees to use as the Christmas trees.

Each vertex in a rooted tree has a beauty value, and the party venue looks more attractive if beautiful vertices are located high. However, if the rooted tree is too tall, it will hit the ceiling of the AtCoder office. Therefore, there is a limit to the height of rooted trees that can be brought into the venue.

Your task is to cut out several rooted trees from a given graph to maximize the attractiveness of the party venue.

Problem Statement

You are given a connected, undirected planar graph GG with NN vertices and MM edges. The vertices are numbered from 00 to N1N-1, and the edges are numbered from 00 to M1M-1. The coordinates of vertex vv are (xv,yv)(x_v, y_v), and edge ii connects vertices uiu_i and viv_i. Each vertex has a beauty value, which is a positive integer. The beauty value of vertex vv is AvA_v.

The attractiveness of a rooted tree TT is defined as follows: Let the height hvh_v of vertex vv in TT be the number of edges in the path from the root to vv. The attractiveness a(T)a(T) of the rooted tree TT is defined as a(T):=vT(hv+1)Ava(T):=\sum_{v \in T} (h_v + 1) A_v.

Your task is to construct a set of rooted trees from the given graph GG that satisfies the following conditions, and make the sum of attractiveness as large as possible:

  • All edges in each rooted tree TT must belong to GG.
  • Each vertex in GG belongs to exactly one rooted tree.
  • The height of all vertices in each rooted tree must be less than or equal to HH.

Scoring

Let FF be the set of rooted trees you construct. Then, you will obtain a score of 1+TFa(T)1+\sum_{T\in F}a(T).

There are 150150 test cases, and the score of a submission is the total score for each test case. If your submission produces an illegal output or exceeds the time limit for some test cases, the submission itself will be judged as <span class='label label-warning' data-toggle='tooltip' data-placement='top' title="Wrong Answer">WA</span> or <span class='label label-warning' data-toggle='tooltip' data-placement='top' title="Time Limit Exceeded">TLE</span> , and the score of the submission will be zero. The highest score obtained during the contest will determine the final ranking, and there will be no system test after the contest. If more than one participant gets the same score, they will be ranked in the same place regardless of the submission time.

Input

Input is given from Standard Input in the following format:

$N$ $M$ $H$
$A_0$ $\cdots$ $A_{N-1}$
$u_0$ $v_0$
$\vdots$
$u_{M-1}$ $v_{M-1}$
$x_0$ $y_0$
$\vdots$
$x_{N-1}$ $y_{N-1}$

The input satisfies the following constraints:

  • N=1000N = 1000
  • 1000M30001000 \leq M \leq 3000
  • H=10H = 10
  • 1Av1001 \leq A_v \leq 100
  • 0ui<viN10 \leq u_i < v_i \leq N-1
  • 0xv,yv10000 \leq x_v, y_v \leq 1000
  • (xv,yv)(x_v, y_v) are all distinct.
  • All inputs are integers.
  • The given graph is a connected planar graph. If vertex vv is placed at coordinate (xv,yv)(x_v, y_v), and each edge is drawn as a line segment connecting its endpoints, no two edges share points other than their endpoints.

Output

Let pvp_v be the parent of vertex vv in the constructed set of rooted trees. If vv is a root, let pv=1p_v=-1. Then, output to Standard Output in the following format:

$p_0$ $p_1$ $\cdots$ $p_{N-1}$

<a href="https://img.atcoder.jp/ahc041/m0Bwp9WL.html?lang=en&seed=0&output=sample">Show example</a>

Your program may output multiple solutions. If multiple solutions are output, only the last one is used for scoring. You can compare multiple solutions using the web version of the visualizer.

Input Generation

Let rand(L,U)\mathrm{rand}(L,U) be a function that generates a uniform random integer between LL and UU, inclusive.

Generation of the graph GG

Randomly select NN points (x0,y0),,(xN1,yN1)(x_0,y_0),\cdots,(x_{N-1},y_{N-1}) from the lattice points contained in a circle with center (500,500)(500,500) and radius 500500. If the Euclidean distance between (xi,yi)(x_i,y_i) and an already selected point (xj,yj)(x_j,y_j) (j<ij<i) is less than or equal to 1515, we select (xi,yi)(x_i,y_i) again.

For the vertex set VV obtained as described above, compute the Delaunay triangulation, define the edge set of the triangulation as EE, and let G=(V,E)G = (V, E).

Generation of the beauty values AA

For each vertex vv, the beauty value AvA_v is generated using rand(1,100)\mathrm{rand}(1, 100).

Tools (Input generator, local tester and visualizer)

  • <a href="https://img.atcoder.jp/ahc041/m0Bwp9WL.html?lang=en">Web version</a>: This is more powerful than the local version and can display animations.
  • <a href="https://img.atcoder.jp/ahc041/m0Bwp9WL.zip">Local version</a>: You need a compilation environment of <a href="https://www.rust-lang.org">Rust language</a>.
    • <a href="https://img.atcoder.jp/ahc041/m0Bwp9WL_windows.zip">Pre-compiled binary for Windows</a>: If you are not familiar with the Rust language environment, please use this instead.

Please be aware that sharing visualization results or discussing solutions/ideas during the contest is prohibited.

Subject outcomes

  • claude-4-sonnet correct
  • claude-4.1-opus correct
  • claude-4.5-haiku correct
  • qwen3.5-35b-a3b incorrect
  • qwen3.5-flash incorrect
  • qwen3.6-flash incorrect

Subjects

The models, agents, and reward models evaluated.

102 subjects, ranked by mean response (accuracy) across this benchmark's items.

  1. 1gpt-5.1-codex-high1
  2. 2gpt-5.1-thinking1
  3. 3gpt-5.1-codex-max-xhigh0.995
  4. 4gpt-5.2-high0.995
  5. 5gpt-5.2-medium0.99
  6. 6gpt-5-thinking0.99
  7. 7gpt-5.1-codex-max-high0.985
  8. 8gpt-5.4-mini-high0.98
  9. 9gpt-5.2-codex-xhigh0.98
  10. 10gpt-5.3-codex-xhigh0.98
  11. 11o4-mini-high0.98
  12. 12gpt-5.4-nano-high0.975
  13. 13gpt-5.5-xhigh0.975
  14. 14claude-4.8-opus-high0.97
  15. 15claude-4.5-opus0.97
  16. 16grok-4.20-beta0.965
  17. 17gpt-5.4-high0.96
  18. 18mercury-20.96
  19. 19claude-fable-5-high0.96
  20. 20claude-4.7-opus-no-thinking0.96
  21. 21gpt-5.5-medium0.955
  22. 22claude-4.8-opus-no-thinking0.955
  23. 23gpt-5.5-none0.95
  24. 24gpt-5.4-none0.95
  25. 25gpt-oss-120b0.945
  26. 26o3-high0.945
  27. 27gemini-3.1-pro-preview-low0.94
  28. 28glm-5.10.935
  29. 29gemini-3-flash-preview-high0.935
  30. 30claude-4.6-opus-no-thinking0.93
  31. 31claude-4.6-sonnet-medium0.93
  32. 32gpt-oss-20b0.92
  33. 33mistral-medium-3.50.92
  34. 34glm-5.2-max0.915
  35. 35deepseek-v3.1-terminus0.915
  36. 36mimo-v2.5-pro0.915