#P10847. [EGOI 2024] Garden Decorations / 花园装饰

    ID: 19611 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 显示难度NOI/NOI+/CTS 上传者: 标签>2024交互题Special JudgeO2优化通信题EGOI(欧洲/女生)

[EGOI 2024] Garden Decorations / 花园装饰

Background

Day 1 Problem D.

The statement is translated from EGOI2024 gardendecoration. The translation comes from ChatGPT and has been manually proofread. If there are any mistakes, please contact rui_er.

7s 1GB.

This is a communication problem, and your program will be executed multiple times.

Problem Description

Every day on the way to and from school, Detje walks along a street with NN houses, numbered from 00 to N−1N - 1. Currently, resident ii lives in house ii. To change things up, the residents decide to swap houses. The person who will move into house ii is the person who currently lives in house aia_i.

In the garden of each house, there is a bird statue. These statues have two states: their wings are either open (as if flying) or closed (as if standing on the ground). The residents have strong preferences about how their bird statues should look. Currently, the bird statue in front of house ii is in the state that resident ii likes. The residents refuse to move into a house whose statue is not set to their preferred state. Detje wants to help them by adjusting the statues’ states so that they can move.

To do this, she does the following: each time she walks along the street (either to school or back home), she observes the birds one by one and may adjust some statues (by opening or closing their wings). Since she is very busy at both school and home, she does not remember the states of birds she has seen before. Luckily, she wrote down the list a0,a1,⋯ ,aN−1a_0,a_1,\cdots,a_{N-1}, so she knows which resident will move where.

Help Detje design a strategy that tells her which bird statues to adjust, so that the statues end up in the states the residents like. She may walk along the street at most 60 times, but to get a higher score, she should use as few walks as possible.


Interaction

This is a communication problem, and your program will be executed multiple times.

In each run, you should first read one line containing two integers ww and NN, which are the walk index and the number of houses. In the first run, w=0w = 0, in the second run, w=1w = 1, and so on (explained in detail below).

In the second line of the input, there are NN integers a0,a1,⋯ ,aN−1a_0,a_1,\cdots,a_{N-1}, meaning that the person who will move into house ii currently lives in house aia_i. The values aia_i form a permutation, i.e., every number from 00 to N−1N - 1 appears exactly once in the list aia_i. Note that residents may choose not to move, so ai=ia_i = i is allowed.

The residents will swap houses only once. This means that for a fixed test case, the value of NN and the list aia_i are the same in all runs of your program.

First run.

In the first execution of your program, w=0w = 0. In this run, you should output an integer WW (0≤W≤600 \le W \le 60), which is the number of times Detje wants to walk along the street. Then your program should terminate. After that, your program will be executed another WW times.

Subsequent runs.

In the next run, w=1w = 1; in the next one, w=2w = 2; and so on, until the last run where w=Ww = W.

After reading w,Nw, N and a0,a1,⋯ ,aN−1a_0,a_1,\cdots,a_{N-1}, Detje starts walking along the street.

  • If ww is odd, Detje walks from home to school, passing the houses in the order 0,1,⋯ ,N−10, 1,\cdots, N - 1.

    Your program should now read a line containing b0b_0, the current state of the statue in front of house 00, where 00 means closed and 11 means open. After reading b0b_0, you should output one line containing the new state you want to set b0b_0 to, either 00 or 11.

    Then your program should read a line containing b1b_1, the state of the statue in front of house 11, and output the new state for b1b_1. This continues for all NN houses. After Detje passes the last house (i.e., after reading and writing bN−1b_{N-1}), your program should terminate.

    Note: your program can only read the next value bi+1b_{i+1} after writing the new value for bib_i.

  • If ww is even, Detje walks from school to home, passing the houses in the order N−1,N−2,⋯ ,0N - 1, N - 2,\cdots, 0. That is, you start by reading and writing bN−1b_{N-1}, then bN−2b_{N-2}, and so on until b0b_0.

When w=1w = 1, the input values b0,b1,⋯ ,bN−1b_0,b_1,\cdots,b_{N-1} are the initial states of the bird statues (and also the residents’ preferred states). When w>1w > 1, the input values b0,b1,⋯ ,bN−1b_0,b_1,\cdots,b_{N-1} are the states that were set in the previous run of your program.

Finally, after the last run of the program, for all ii, the value bib_i must be equal to the initial value baib_{a_i}, otherwise the program will be judged as WA.

More details.

If the total running time of the W+1W + 1 separate program executions exceeds the time limit, the program will be judged as TLE.

After outputting each line, be sure to flush standard output, otherwise your program may be judged as TLE. In Python, calling input() to read a line will automatically flush. In C++, cout << endl; flushes in addition to printing a newline; if you use printf, use fflush(stdout).

Input Format

See the Interaction section.

Output Format

See the Interaction section.

0 6
1 2 0 4 3 5


2
1 6
1 2 0 4 3 5
1

1

0

0

1

0



0

1

0

1

1

1
2 6
1 2 0 4 3 5
1

1

1

0

1

0



0

0

1

1

0

1

Hint

Sample explanation

The three samples in the statement correspond to three interactive processes for the same test case.

In the sample, we are given the following permutation of people among houses:

In the first run of the sample program (w=0w = 0), it outputs W=2W = 2, meaning that Detje will walk along the street twice (and the program will run two more times). Before the first walk, the birds in the gardens look as follows:

Then the program runs with w=1w = 1, meaning Detje’s first walk. She passes the birds one by one from the left and may change their states. Before seeing bird (i+1)(i + 1), the sample program must output the state of bird ii.

After Detje reaches school, the birds look as follows:

In the last run of the program (w=2w = 2), Detje walks back home from school. Remember that in this case, she passes the birds from right to left and processes them in this order. This means she needs to decide the state of bird ii before seeing bird (i−1)(i - 1).

After she finishes the walk, the birds now look as follows:

Indeed, this is the correct configuration. For example, bird statue 33 (the fourth from the left) is open (now b3=1b_3 = 1), which is correct because person 44 will move there (a3=4a_3 = 4), and they originally had an open bird statue (originally b4=1b_4 = 1).


Constraints

For all testdata, 2≤N≤5002\le N\le 500, and you may use at most W≤60W\le 60 rounds.

  • Subtask 1 (up to 1010 points): N=2N=2.
  • Subtask 2 (up to 2424 points): N≤15N\le 15.
  • Subtask 3 (up to 99 points): ai=N−1−ia_i=N-1-i.
  • Subtask 4 (up to 1313 points): ai=(i+1) mod Na_i=(i+1)\bmod N.
  • Subtask 5 (up to 1313 points): ai=(i−1) mod Na_i=(i-1)\bmod N.
  • Subtask 6 (up to 3131 points): no special constraints.

Scoring

For each subtask that your program solves correctly, you will receive a score according to the following formula:

$$\textrm{score}=S_g\cdot\left(1-\frac{1}{2}\log_{10}(\max(W_g,3)/3)\right)$$

Here, SgS_g is the full score for that subtask, and WgW_g is the maximum number of rounds used by your program among all test cases in that subtask. Your score for each subtask will be rounded to the nearest integer.

Below is a graph of the score as a function of WgW_g. To get full score, you need to solve each test case in at most 33 rounds.

Translated by ChatGPT 5