問題一覧 > スコア問題

No.5004 Room Assignment

レベル : / 実行時間制限 : 1ケース 5.000秒 / メモリ制限 : 512 MB / リアクティブ問題 (詳しくはこちら)
タグ : (解説公開後に AC するまで非表示) / 解いたユーザー数 43
作問者 : butsurizuki
お気に入りにしたユーザー ProblemId : 7297 / 自分の提出
問題文最終更新日: 2021-12-01 09:33:17
Room Assignment
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Show the original
Advent Calendar Contest 2021 (順位表) の他の問題:

Notes

For the rankings by score, see here: https://yukicoder.me/problems/no/5004/score

This problem is the Day 1 problem of Advent Calendar Contest 2021.
The difficulty level is one assigned for the Advent Calendar Contest. You can earn points in the contest as long as you produce a valid output.

Since this is a score-based problem, you cannot make another submission for 5 minutes after your last submission.

The rules (as intended by the writer) on discussing this problem during the contest are as follows.

  • Discussion and consultation are allowed on matters not directly related to solutions (such as how to run local tests).
  • Volunteers may create and publish visualizers, among other things.
  • Furthermore, you are allowed to directly discuss your own solution and to share your code.
    • However, if someone else improves their solution as a result, the resulting score belongs to the person who submitted the improved code.
No rejudging, system tests, or the like are planned after the end of the contest period.
The contest period ends at 2021-12-25 23:30:00, and the seeds used to generate the test cases will be published on the editorial page.

Problem Statement

This is an interactive problem.

You are a server engineer for an online game.
Your task is to write a program that assigns appearing players to rooms so that players of as similar skill as possible share a room, and so that this is done as quickly as possible.

First, $2$ integers $T,R$ are given in the following format.

$T$ $R$
Players will now appear over $T$ ticks. Your program must perform the interaction described below $T$ times.
$R$ represents the upper limit on the number of people assigned to the same room.

The interaction between the judge and your program at tick $t$ ($0 \le t < T$) is as follows.
First, at the beginning of tick $t$, information on the players appearing at tick $t$ is given in the following format.
$N$ $S_1$ $S_2$ $\dots$ $S_N$
$N$ represents the number of players who appeared at tick $t$.
Letting $p$ be the number of players who appeared at tick $t-1$ or earlier, player $p+1,$ player $p+2,$ $\dots,$ player $p+N$ appeared at tick $t$.
$S_i$ represents the "skill value" of player $p+i$. The "skill value" is a parameter used for scoring.
A player who appears is initially assigned to a room containing only that $1$ player.

Next, you must output the operations to perform at tick $t$ in the following format.
$M$
$U_1$ $V_1$
$U_2$ $V_2$
$\dots$
$U_M$ $V_M$
$M$ must be an integer greater than or equal to $0$, and represents the number of operations performed at this tick.
There is no particular upper limit on $M$, but if your output is excessively large, unexpected errors such as OLE or RE may occur. No relief measures will be taken in such cases.
The judge supports outputs in which the sum of $M$ over the entire output is at most $10^4$; if an unexpected error occurs for an output satisfying this, please contact us through "Questions".
The $i$-th operation is represented by $2$ integers $U_i,V_i$, and merges the room containing player $U_i$ and the room containing player $V_i$. (This corresponds to the merge query of Union-Find.)
Here, when merging rooms, the total number of people must not exceed $R$. You also cannot use players who have not yet appeared in a merge.
If you attempt to merge a room with itself, the operation is ignored. (It does not result in WA.)
Be sure to read all of the judge's input through to the end. Otherwise, you may get WA.
Be sure to flush standard output after printing. Otherwise, you may get TLE.

Scoring

Among the players in a room, let $S_M$ be the skill value of the player with the largest skill value, and $S_m$ be the skill value of the player with the smallest skill value.
Also, define $E$ as follows.
$E=\sum_{i,j}$ ( $y-x$, if $i$ appeared at tick $x$ and $(i,j)$ came to be in the same room at tick $y$ )
Here, $\sum_{i,j}$ denotes the sum over all pairs $(i,j)$ $(i \neq j)$ of distinct players in the same room.
The value of each room is then defined as follows.

  • If the room has $1$ person, the value of the room is $0$
  • If the room has $2$ people, the value of the room is $\max(1 \times (200-(S_M-S_m)^2) - E,0)$
  • If the room has $3$ people, the value of the room is $\max(3 \times (200-(S_M-S_m)^2) - E,0)$
  • If the room has $4$ people, the value of the room is $\max(6 \times (200-(S_M-S_m)^2) - E,0)$

The score for $1$ test case is the sum of the values of all rooms. The final score is the sum of the scores over all test cases.
Any case that receives a verdict other than AC is scored as $0$ points for that case.

Input Generation

  • The number of test cases used for scoring is $100$
  • $T=3600$ is fixed
  • $R=4$ is fixed
  • The sum of $N$ is fixed at $5400$
  • For all $S_i$, $0 \le S_i \le 100$
How the test cases are generated
Let $\mathrm{nd}(\mu,\sigma)$ be a function that generates a normally distributed random real number with mean $\mu$ and standard deviation $\sigma$.
Let $\mathrm{rnd}(l,r)$ be a function that generates a uniform random real number with lower bound $l$ and upper bound $r$.
Let $\mathrm{round}(x)$ be $x$ rounded to the nearest integer.

Generation of $S_i$
$S_i$ is generated by $\mathrm{round}(\mathrm{nd}(50,20))$.
However, if the generated value violates the constraints on $S_i$, generation is repeated until a value satisfying the constraints is obtained.

Generation of player appearance timings
First, a real number $\omega$ is determined by $\mathrm{rnd}(0,2 \pi)$.
Initially, the appearance rate is defined as the function $f(t)=1.5+\sin(\frac{2 \pi t}{T} + \omega)$. This represents the standard number of players appearing at tick $t$.
Next, we obtain the function $F$ representing the standard cumulative number of appeared players.
This is the integral of $f$, namely $F(t)=1.5t-\dfrac{T\cos\left(\frac{2{\pi}t}{T}+{\omega}\right)}{2{\pi}} + C$ (where $C$ is the integration constant chosen so that $F(0)=0$ holds).
Next, let $G$ be the inverse function of $F$. $G(x)$ represents (the standard number of ticks after which the number of appeared players reaches $x$).
Then, define the sequence $B$ by $B_i=\mathrm{round}(G(i-0.5) + \mathrm{rnd}(-20,20))\mod T$ ($1 \le i \le 5400$).
If the sequence $B$ contains $l$ elements equal to $k$, then $l$ players appear at tick $k$.

Distributed Materials

Get the distributed materials (zip) here.
The same content is also available from GitHub.
You may use these materials in your solutions, and you may redistribute translations of them into other languages.
Notes on local testing:
In this problem, scoring is performed by giving the contents of the input file as is to your code, step by step, through interaction.
Therefore, no interaction with a judge is needed for local testing.
Implement your code so that it receives the appropriate information at the appropriate time, run it to generate an output file, and give that file to the scoring program to get the scoring result.

Sample

Sample 1
Input
6 4
1 5
2 4 7
2 50 4
3 4 4 4
2 0 51
2 100 100
Output
0
2
1 2
2 3
0
4
8 7
7 6
6 5
5 8
0
2
4 10
9 11

Note that this input is an example that violates the test case generation method.

Tick $0$: Player $1$ with skill value $5$ appeared. The program performs no operations.

Tick $1$: Player $2$ with skill value $4$ and player $3$ with skill value $7$ appeared.
The program merged the room containing player $1$ and the room containing player $2$.
The program merged the room containing player $2$ and the room containing player $3$.

Tick $2$: Player $4$ with skill value $50$ and player $5$ with skill value $4$ appeared. The program performs no operations.

Tick $3$: Players $6,7,8$ with skill value $4$ appeared.
The program merged the room containing player $8$ and the room containing player $7$.
The program merged the room containing player $7$ and the room containing player $6$.
The program merged the room containing player $6$ and the room containing player $5$.
The program attempted to merge the room containing player $5$ and the room containing player $8$, but since these $2$ rooms are the same, this operation is ignored.

Tick $4$: Player $9$ with skill value $0$ and player $10$ with skill value $51$ appeared. The program performs no operations.

Tick $5$: Players $11,12$ with skill value $100$ appeared.
The program merged the room containing player $4$ and the room containing player $10$.
The program merged the room containing player $9$ and the room containing player $11$.

The value of the room containing players $1,2,3$ is $3 \times (200 - (7-4)^2) - 2 = 571$
The value of the room containing players $5,6,7,8$ is $6 \times (200 - (4-4)^2) - 3 = 1197$
The value of the room containing players $4,10$ is $1 \times (200 - (51-50)^2) - 4 = 195$
The value of the room containing players $9,11$ and of the room containing only player $12$ is $0$.
Finally, the program's score for this test case is $571 + 1197 + 195 + 0 + 0 = 1963$.

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。