

Time Limit: 2 sec / Memory Limit: 1024 MB
ストーリー
ある会社では、現在働きやすい環境づくりを目指している。そこで新入社員が入社する 4 月から、社内の掃除を毎週行うことにした。 しかしながら、掃除当番は簡単に決められるものではない。 たとえば 1 人に負担をかけすぎてはならないことや、まだ仕事に慣れていない新入社員の負担は特に少なくしなければならないことなど、様々な制約がある。 また、掃除当番の決め方は「X さんの次は Y さんか Z さん」のように覚えやすいものでなければならない。 できるだけ制約通りになるように、掃除当番の決め方を最適化せよ。
問題文
ある会社には 人の社員がおり、それぞれ から までの番号が付けられている。 あなたは、各社員 について整数 と を決め ( でも構わない)、以下の規則で各週の掃除当番を割り当てることにした。
- 最初の週は、社員 が掃除当番となる。
- それ以降の週については、前週の掃除当番を社員 とし、前週が終わった時点で社員 が掃除当番に 回割り当てられたとして、今週の掃除当番は次のように決まる。
- が奇数の場合: 社員
- が偶数の場合: 社員
各 について、今後 週間に社員 に掃除当番を割り当てる回数の目標値 が与えられる。 実際に社員 に割り当てられる掃除当番の回数を とするとき、誤差 をできるだけ小さくせよ。
得点
出力した掃除当番の決め方における誤差を とするとき、 点が得られる。 ここで、得点が負の値にならないことが保証される。
合計で 150 個のテストケースがあり、各テストケースの得点の合計が提出の得点となる。 一つ以上のケースで不正な出力や制限時間超過をした場合、提出全体の判定が WA や TLE となる。 コンテスト時間中に得た最高得点で最終順位が決定され、コンテスト終了後のシステムテストは行われない。 同じ得点を複数の参加者が得た場合、提出時刻に関わらず同じ順位となる。
入力
入力は以下の形式で標準入力から与えられる。
- 全てのテストケースで、社員の数 は で固定である。
- 全てのテストケースで、週数 は で固定である。
- を満たす。
- を満たす。
- 入力はすべて整数である。
出力
以下の形式で標準出力に出力せよ。
ここで および を満たさない が存在する場合、WA と判定される。
入力生成方法
以上 以下の整数値を一様ランダムに生成する関数を と表すとき、入力生成方法は次のようになる。
- 各 について、 の値を により生成する。
- 総和 が を満たすならば として入力を確定させる。そうでなければ、1. に戻って生成をやり直す。
ツール(入力ジェネレータ・ビジュアライザ)
- Web版: ローカル版より高性能でアニメーション表示が可能です。
- ローカル版: 使用するにはRust言語のコンパイル環境をご用意下さい。
- Windows用のコンパイル済みバイナリ: Rust言語の環境構築が面倒な方は代わりにこちらをご利用下さい。
コンテスト期間中に、ビジュアライズ結果の共有や、解法・考察に関する言及は禁止されています。ご注意下さい。
Story
A company is currently aiming to create a comfortable working environment. It has decided to clean the office every week starting this April, when new employees join the company. However, assigning cleaning duties is not easy. There are various constraints, for example, the duty should not be concentrated on one person, and the burden on new employees, who are not yet accustomed to the work, should be especially low. Also, the assignment should be easy to remember, like "after employee X, the next must be employee Y or Z." Create a cleaning plan that follows the constraints as closely as possible.
Problem Statement
There are employees in a company, numbered from to . For each employee , you must determine two integers and ( and may be equal). Then, the cleaning plan for each week is created in the following way:
- In the first week, employee will do the cleaning.
- From the second week onward, let employee be the one who did the cleaning last week, and let be the number of weeks in which employee had been assigned as the cleaner by the end of last week. Then, this week's cleaning duty is determined as follows:
- When is odd: employee
- When is even: employee
For each , a target number of times is given as the number of times employee should be assigned cleaning duty in the next weeks. Let be the actual number of times employee is assigned cleaning duty. Create a cleaning plan that makes the error defined by as small as possible.
Scoring
Let be the error in the output cleaning plan. You will obtain the score of , which is guaranteed to be non-negative.
There are 150 testcases, and the score of a submission is the total score for each testcase. If your submission produces an illegal output or exceeds the time limit for some testcases, the submission itself will be judged as WA or TLE, 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:
- The number of employees is fixed to across all testcases.
- The number of weeks is fixed to across all testcases.
- .
- .
- Given values are all integers.
Output
Output to Standard Output in the following format:
Here, if there exists an that does not satisfy or , the output will be judged as WA.
Input Generation
Let be the function that generates a uniform random integer between and , inclusive. The input will be generated in the following algorithm:
- For each , generate with .
- If the sum satisfies , set and finalize the input. Otherwise, retry step 1.
Tools (Input generator and visualizer)
- Web version: This is more powerful than the local version providing animations.
- Local version: You need a compilation environment of Rust language.
- Pre-compiled binary for Windows: 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.