A - E869120, who Leaps through Time

Time Limit: 1 sec / Memory Limit: 976 MB

配点:200

問題文

E869120 君は、高橋王国に住んでいます。
彼は、AtCodeer 株式会社で働いています。この会社では、毎日時刻 0 に必ず出席しなければならない会議が始まります。
高橋王国には N 個の都市があり、西から順に都市 1, 2, 3, ..., N と番号付けられています。彼の家は都市 1 であり、彼の会社は都市 N です。また 高橋王国には都市 ii+1 (1 \leq i \leq N - 1) を双方向に結ぶ道路があり、この道路で移動するのに A_i 単位時間かかります。ただし、1 単位時間は時刻 0 から 1 までの時間とします。

2031 年のある日の事です… 彼は起きて時計を確認したら、なんと時刻 0 でした!
このままだと会議に遅れてしまいます。AtCodeer 株式会社は遅刻に厳しいので、会議に一回でも遅れると、叱責・減給どころでは済みません。一発で解雇になってしまいます!
しかし、彼は特殊能力を持っています。これは「タイムリープ」であり、この能力を 1 回使うと時刻が T 単位時間戻されます。「タイムリープ」はいずれかの都市にいるときに使うことができます。

会議に遅刻しないようにする、すなわち都市 N にある会社に時刻 0 またはそれ以前に到着するためには、最低何回の「タイムリープ」を使う必要があるか、求めてください。
ただし、彼は起きた時刻 0 に行動を開始することが出来るとします。

制約

  • N2 以上 100 以下の整数
  • T1 以上 100 以下の整数
  • A_i1 以上 100 以下の整数

部分点

この問題はいくつかの小課題に分けられ、その小課題のすべてのテストケースに正解した場合に「この小課題に正解した」とみなされます。
提出したソースコードの得点は、正解した小課題の点数の合計となります。

  1. (100 点):N = 2, T = 1
  2. (100 点):追加の制約はない

入力

入力は以下の形式で標準入力から与えられます。

N T
A_1 A_2 A_3 ... A_{N - 1}

出力

使わなければならない「タイムリープ」の最小回数を、1 行で出力してください。


入力例 1

2 1
3

出力例 1

3

例えば、次のような行動をとると、「タイムリープ」の回数を 3 回にでき、これが最小です。

  1. 最初、E869120 君は都市 1 におり、時刻は 0 である。

  2. 都市 1 で「タイムリープ」を 3 回使う。これが終わった時点で、時刻は -3 である。

  3. 都市 1 から都市 2 に移動する。移動し終わった時点で、時刻は 0 なので、なんと間に合っている!


入力例 2

3 4
5 6

出力例 2

3

この入力例が、小課題 1 の制約を満たさないことに注意してください。

Max Score:200 points

Problem Statement

Mr.E869120 lives in Takahashi Kingdom.
He works as a programmer in AtCodeer Inc, which there is a meeting that we must attend. The meeting is held every day at time 0.
In Takahashi kingdom, there are N cities, and they are called city 1, city 2, city 3, ..., city N from west to east. In addition, there is a road which connects between city i and city i+1 (1 \leq i \leq N - 1), and takes A_i minutes to move.

Something happened on a day of May 2031... He woke up and looked a watch - it was actually time 0, which is the meeting time!
He is going to be late for the meeting. Since AtCodeer Inc. is very strict for being late, he is very likely to be fired!

But he is able to use a magic: TIMELEAP. When he use it, the time will be back by T minutes. He can use TIMELEAP when he is in any city. For example, if T = 3 and he use TIMELEAP at time 8, then the time will be back to 5.
He want to minimize the number of use of TIMELEAP. To not be late for the meeting, how many TIMELEAP should he use?

Constraints

  • N is an integer between 2 and 100 (inclusive)
  • T is an integer between 1 and 100 (inclusive)
  • A_i is an integer between 1 and 100 (inclusive)

Subtasks

This problem is separated several two subtasks, and you will get score of the subtask if your program prints the correct answer for all testcases for the subtask prepared.
The score for a program is the sum of score of subtasks of correct answer.

  1. (100 points):N = 2, T = 1
  2. (100 points):No additional constraints.

Input

Input is given from Standard Input in the following format:

N T
A_1 A_2 A_3 ... A_{N - 1}

Output

Print the minimum number of TIMELEAP that Mr.E869120 should use.


Sample Input 1

2 1
3

Sample Output 1

3

For example, if he does following move, the number of TIMELEAP will be 3.

  1. Initially, Mr.E869120 is in city 1 and the time is 0.

  2. Use TIMELEAP 3 times when he is in city 1. Now the time is -3.

  3. Move from city 1 to city 2. Since it takes 3 minutes, now the time is 0. Note: It is allowed to arrive at city N at time 0.


Sample Input 2

3 4
5 6

Sample Output 2

3

Note this testcase is not included in Subtask 1.

B - AtCoder Market

Time Limit: 1 sec / Memory Limit: 976 MB

配点:300

問題文

AtCoder マーケットは、1 \ 000 \ 000 \ 000 個のマスが 1 列につながったマス目で表されるスーパーマーケットである。ここでは、左から i 番目のマスを「マス i」とする。

ある日、N 人の買い物客が AtCoder マーケットに来る。i 人目の買い物客は、マス A_i にある品物とマス B_i にある品物を買う。

square1001 君は、AtCoder マーケットに入口と出口を 1 つずつ設置することにした。
入口と出口はいずれかのマス目に設置する。入口と出口は同じ場所にあってもよい。

そのとき、買い物客は次のような経路で移動する。

  • まず、入口からスタートする。マス A_iB_i を経由して、出口でゴールする。

すべての買い物客について、隣り合ったマス目に進むのに 1 秒かかるとき、最適に入口と出口を設置したときの「すべての買い物客の移動時間の合計」の最小値を求めなさい。

制約

  • 1 \leq N \leq 30
  • 1 \leq A_i < B_i \leq 1 \ 000 \ 000 \ 000

小課題・得点

この問題はいくつかの小課題に分けられ、その小課題のすべてのテストケースに正解した場合に「この小課題に正解した」とみなされます。
提出したソースコードの得点は、正解した小課題の点数の合計となります。

  1. (195 点):1 \leq A_i < B_i \leq 100 を満たす。また、移動時間が最小となるような入口と出口のマスは、マス 1, 2, 3, ..., 100 のどれかである。
  2. (105 点):追加の制約はない。

入力

入力は以下の形式で標準入力から与えられます。

N
A_1 B_1
A_2 B_2
 :  :
A_N B_N

出力

「すべての買い物客の移動時間の合計」の最小値を、秒単位で出力してください。

注意

この問題の制約上、答えが 32 ビット整数型の範囲に収まらない可能性があることに注意してください。
例えば C / C++ では、long long 型を使うなどで、64 ビット整数型を使用することができます。


入力例 1

3
5 7
2 6
8 10

出力例 1

18

例えば、入口をマス 5、出口をマス 7 に設定すると、それぞれの買い物客は次のように動くことになります:

  • 買い物客 1:マス 5 -> 6 -> 7
  • 買い物客 2:マス 5 -> 4 -> 3 -> 2 -> 3 -> 4 -> 5 -> 6 -> 7
  • 買い物客 3:マス 5 -> 6 -> 7 -> 8 -> 9 -> 10 -> 9 -> 8 -> 7

(太字は「ここで品物を買った」ことを表します)

買い物客 1, 2, 3 はそれぞれ 2, 8, 8 秒間移動にかけます。合計は 18 秒です。
また、18 秒より短い合計移動時間にすることはできません。


入力例 2

5
1 71
43 64
13 35
14 54
79 85

出力例 2

334

入口をマス 14 に、出口をマス 64 に設置すると、合計移動時間を 334 秒にすることができ、これが最小です。


入力例 3

11
15004200 341668840
277786703 825590503
85505967 410375631
797368845 930277710
90107929 763195990
104844373 888031128
338351523 715240891
458782074 493862093
189601059 534714600
299073643 971113974
98291394 443377420

出力例 3

8494550716

入口をマス 189 \ 601 \ 059 に、出口をマス 715 \ 240 \ 891 に設置すると、合計移動時間を 8 \ 494 \ 550 \ 716 秒にすることができ、これが最小です。

Max Score:300 Points

Problem Statement

AtCoder Market is a supermarket consist of 1 \ 000 \ 000 \ 000 squares, connected like a straight line from left to right. Let "square i" the i-th leftmost square. In other words, square i and square i+1 is connected for all integer i \ (1 \leq i \leq 999 \ 999 \ 999).

One day, N buyers came to AtCoder Market for shopping. i-th buyer wants to buy two goods: one in square A_i, and the other in square B_i.

The owner of AtCoder Market, square1001, is going to install one entrance and one exit.
Entrance and exit can be installed at any square, and entrance and exit can be placed at the same sqauare.

Then, the i-th buyer will do shopping in the following way:

  • Start from the entrance, then visit squares A_i, B_i, and goal at the exit. They will move in the shortest route.

For all buyers, it takes exactly 1 seconds to move to adjacent square.

What is the minimum sum of durations of shoppings, when the owner chooses the place of entrance and exit optimally?

Constraints

  • 1 \leq N \leq 30
  • 1 \leq A_i < B_i \leq 1 \ 000 \ 000 \ 000

Subtasks / Scoring

This problem is separated several two subtasks, and you will get score of the subtask if your program prints the correct answer for all testcases for the subtask prepared.
The score for a program is the sum of score of subtasks of correct answer.

  1. (195 points):1 \leq A_i < B_i \leq 100. Also, both entrance and exit will be square either 1, 2, 3, ..., 100, in the optimal solution.
  2. (105 points):No additional constraints.

Input

The input will be given from standard input, in the following format.

N
A_1 B_1
A_2 B_2
 :  :
A_N B_N

Output

Print the minimal sum of duration of shopping (in second), in one line.

Note

In this constraints, the answer may not be included in the range of 32-bit integer.
To use 64-bit integers, for example in C / C++, we can use long long type, instead of int.


Sample Input 1

3
5 7
2 6
8 10

Sample Output 1

18

Think about installing entrance in square 5, and exit in square 7. Each buyers will move as follows:

  • Buyer No.1:Square 5 -> 6 -> 7
  • Buyer No.2:Square 5 -> 4 -> 3 -> 2 -> 3 -> 4 -> 5 -> 6 -> 7
  • Buyer No.3:Square 5 -> 6 -> 7 -> 8 -> 9 -> 10 -> 9 -> 8 -> 7

(Bold character means that the buyer took the goods)

The buyers 1, 2, 3 will use 2, 8, 8 seconds, respectively, so the total shopping time will be 18 seconds.
There's no method for total shopping time to be shorter than 18 seconds.


Sample Input 2

5
1 71
43 64
13 35
14 54
79 85

Sample Output 2

334

When square1001 installs entrance in square 14 and exit in square 64, the total shopping time will be 334 seconds, and it is minimum.


Sample Input 3

11
15004200 341668840
277786703 825590503
85505967 410375631
797368845 930277710
90107929 763195990
104844373 888031128
338351523 715240891
458782074 493862093
189601059 534714600
299073643 971113974
98291394 443377420

Sample Output 3

8494550716

When square1001 installs entrance in square 189 \ 601 \ 059 and exit in square 715 \ 240 \ 891, the total shopping time will be 8 \ 494 \ 550 \ 716 seconds, and it is minimum.

C - Infinite Grid

Time Limit: 1 sec / Memory Limit: 976 MB

配点:400

問題文

H * W のマス目があります。上から i 行目 (1 \leq i \leq H)、左から j 列目 (1 \leq j \leq W) にあるマスを、マス (i, j) と呼ぶことにします。
マス (i, j) は、c_{i, j} = # のとき黒で塗られており、c_{i, j} = . のとき白で塗られています。

下の図は、H = 5, W = 5 の場合のマス目の例です。

さて、このマス目を 1 \ 000 \ 000 \ 000 = 10^{9} 個横に繋げることを考えます。例えば、上の例のマス目を横に 10^{9} 個繋げると、以下のようになります。

square1001 君は、この広いマス目の中を、左上のマス (1, 1) から右下のマス (H, 10^9 \times W) まで移動します。ただし、以下の条件で移動する必要があります。

  • 黒いマスを通らずに移動しなければならない。
  • マス (i, j) からは、マス (i + 1, j) あるいはマス (i, j + 1) にしか移動することができない。
  • マス目の外に出るような移動は許されない。

彼が条件に従って移動できるかどうかを判定してください。

制約

  • H, W1 以上 100 以下の整数
  • c_{i, j}#. のどちらかである
  • c_{1, 1}. である
  • c_{H, W}. である

部分点

この問題はいくつかの小課題に分けられ、その小課題のすべてのテストケースに正解した場合に「この小課題に正解した」とみなされます。
提出したソースコードの得点は、正解した小課題の点数の合計となります。

  1. (60 点) : H = 1
  2. (130 点) : H = 2
  3. (210 点) : 追加の制約はない。

入力

入力は以下の形式で標準入力から与えられます。

H W
c_{1, 1}c_{1, 2}c_{1, 3}...c_{1, W}
c_{2, 1}c_{2, 2}c_{2, 3}...c_{2, W}
c_{3, 1}c_{3, 2}c_{3, 3}...c_{3, W}
...
c_{H, 1}c_{H, 2}c_{H, 3}...c_{H, W}

出力

square1001 君が左上から右下のマスまで移動できる場合 Yay!、移動できない場合 :( と出力してください。


入力例 1

1 3
...

出力例 1

Yay!

マス目は次のようになっており、下図のように移動することで目標を達成することができます。


入力例 2

1 3
.#.

出力例 2

:(

この場合、どうやっても目標を達成できません。それどころか、(1, 3) にすらたどり着くことができません!


入力例 3

3 3
.##
...
##.

出力例 3

Yay!

下図のように移動すると目標を達成することができます。


入力例 4

7 7
..###..
...#...
#.....#
##.#.##
#.....#
...#...
..###..

出力例 4

:(

Max Score:400 points

Problem Statement

We have an H \times W grid whose squares are painted black or white.
The square at the i-th row from the top and the j-th column from the left is denoted as cell (i, j).
Cell (i, j) is painted black if c_{i,j} = #, and cell (i, j) is painted white if c_{i,j} = ..

Following picture is an example of grid which is H = 5, W = 5.

Let's think about connecting 1 \ 000 \ 000 \ 000 same H \times W grids like follows:

After connecting, the grid size will be H \times \left(10^9 \times W\right). Mr.square1001 wants to move from cell (1, 1) to cell (H, 10^9 \times W). In each moves, he can move only to cell (i + 1, j) or cell (i, j + 1) from cell (i, j). In addition, he can only pass on a white cell.
Is it possible to move from the top-left corner cell to the bottom-right corner cell?

Constraints

  • H, W is an integer between 1 and 100 (inclusive)
  • c_{i, j} is # or .
  • c_{1, 1} = .
  • c_{H, W} = .

Subtasks

This problem is separated several two subtasks, and you will get score of the subtask if your program prints the correct answer for all testcases for the subtask prepared.
The score for a program is the sum of score of subtasks of correct answer.

  1. (60 points) : H = 1
  2. (130 points) : H = 2
  3. (210 points) : No additional constraints.

Input

Input is given from Standard Input in the following format:

H W
c_{1, 1}c_{1, 2}c_{1, 3}...c_{1, W}
c_{2, 1}c_{2, 2}c_{2, 3}...c_{2, W}
c_{3, 1}c_{3, 2}c_{3, 3}...c_{3, W}
...
c_{H, 1}c_{H, 2}c_{H, 3}...c_{H, W}

Output

Print Yay! if Mr.square1001 can move from cell (1, 1) to cell (1000000000H, W). Otherwise, print :(.


Sample Input 1

1 3
...

Sample Output 1

Yay!

The state of grid and an example of movement is as follows.


Sample Input 2

1 3
.#.

Sample Output 2

:(

In this case, there is no way to move. Even he cannot move from cell (1, 1) to (1, 3).


Sample Input 3

3 3
.##
...
##.

Sample Output 3

Yay!

The state of grid and an example of movement is as follows.


Sample Input 4

7 7
..###..
...#...
#.....#
##.#.##
#.....#
...#...
..###..

Sample Output 4

:(
D - Snowballs

Time Limit: 1 sec / Memory Limit: 976 MB

配点:600

問題文

西から東に延びる十分に長い一直線の道路があります。道路には N 個の雪玉があります。
道路上で「X の位置」とは、ある道路上の地点を基準として距離 X だけ東に進んだ位置という意味です。

i 個目の雪玉は、道路の西端から X_i の位置にあり、半径は R_i です。すべての雪玉は球体であると仮定してもよいです。

E869120 君は、雪玉を合体させてできるだけ大きい雪玉を作ろうと考えました。

雪玉を距離 d 動かすと、半径は d 小さくなります。半径が 0 になると、雪玉は消滅します。
また、同じ座標にある雪玉を合体させることもできます。半径 r_1 の雪玉と半径 r_2 の雪玉を合体させると、半径 \left(r_1^3 + r_2^3\right)^{1/3} の雪玉になる。

さて、E869120 君が作れる最大の雪玉の半径はいくつでしょうか?

制約

  • 1 \leq N \leq 100 \ 000
  • 1 \leq X_i \leq 1 \ 000 \ 000 \ 000
  • 1 \leq R_i \leq 1 \ 000 \ 000 \ 000

小課題・得点

この問題はいくつかの小課題に分けられ、その小課題のすべてのテストケースに正解した場合に「この小課題に正解した」とみなされます。
提出したソースコードの得点は、正解した小課題の点数の合計となります。

  1. (70 点):N = 2
  2. (140 点):N \leq 15
  3. (250 点):N \leq 1 \ 000
  4. (140 点):追加の制約はない。

入力

入力は以下の形式で標準入力から与えられます。

N
X_1 R_1
X_2 R_2
 :  :
X_N R_N

出力

E869120 君が作れる最大の雪玉の半径を 1 行で出力してください。
ただし、相対誤差または絶対誤差が 10^{-4} 以内の場合、正答とみなされる。


入力例 1

2
4 5
7 9

出力例 1

9.03280211228081065

次のような操作をすると、半径 737^{1/3} = 9.03280... の雪玉を作ることができます。

  • 1 個目の雪玉を、距離 3 だけ東に移動させます。すると、半径が 3 減って 2 になります。
  • 1 個目の雪玉と 2 個目の雪玉を合体させます。合体後の半径は \left(9^3 + 2^3\right)^{1/3} = 9.03280... になります。

これが作れる最大の雪玉の半径になります。


入力例 2

5
3 4
1 4
1 2
9 10
5 3

出力例 2

9.99999999999999645

4 個目の雪玉は最初から半径 10 ですが、このケースではこれ以上の大きさの雪玉をどうやっても作ることができません。
また、誤差が 10^{-4} まで認められるので (「出力」セクション参照)、例えば 9.999210.000869120 などの出力をしてもよいです。


入力例 3

9
815886884 307027576
432574413 156832535
869389414 537542354
8271358 844638329
34762585 93905560
445922147 508315922
476305579 724641385
15004200 341668840
277786703 825590503

出力例 3

1000677079.68994784

半径・位置の制約が 10^9 以下であるとはいえ、答えが 10^9 を超える場合があります。

Max Score:600 points

Problem Statement

There is a very long straight road, from west to east. The road can be expressed as number line, which west is negative direction and east is positive direction.

There are N snowballs in the road. The i-th snowballs is at coordinate X_i and the radius is R_i. We can assume that shape of all snowballs are spheres.

E869120 is trying to make the largest possible snowballs by combining some of them.

When he moves a snowball by distance d, the radius of it will be decreased by d. When the radius becomes zero, the snowball disappears.
Also, he can combine two snowballs at the same coordinates. When he combines snowballs of radius r_1 and r_2, the radius of the combined snowball will be \left(r_1^3 + r_2^3\right)^{1/3}.

Calculate the maximum possible radius E869120 can make, please!

Constraints

  • 1 \leq N \leq 100 \ 000
  • 1 \leq X_i \leq 1 \ 000 \ 000 \ 000
  • 1 \leq R_i \leq 1 \ 000 \ 000 \ 000

Subtasks / Scoring

This problem is separated several two subtasks, and you will get score of the subtask if your program prints the correct answer for all testcases for the subtask prepared.
The score for a program is the sum of score of subtasks of correct answer.

  1. (70 points):N = 2
  2. (140 points):N \leq 15
  3. (250 points):N \leq 1 \ 000
  4. (140 points):No additional constraints.

Input

The input will be given from standard input, in the following format.

N
X_1 R_1
X_2 R_2
 :  :
X_N R_N

Output

Print the maximum possible radius E869120 can make.
Since it will be a real number, your solution will be correct if the absolute or relative error does not exceed 10^{-4}.


Sample Input 1

2
4 5
7 9

Sample Output 1

9.03280211228081065

If E869120 does the following operation, he can obtain a snowball of radius 737^{1/3} = 9.03280....

  • Move 1-st snowball to the east by distance 3. Then, the radius will be decreased by 3 and become 2.
  • Combine 1-st and 2-nd snowballs. The radius after combining will be \left(9^3 + 2^3\right)^{1/3} = 9.03280....

And this is the largest possible snowball he can make.


Sample Input 2

5
3 4
1 4
1 2
9 10
5 3

Sample Output 2

9.99999999999999645

4-th snowball has radius of 10 initially, but he cannot obtain the snowball larger than that, in this case.
In addition, this problem admits error less than 10^{-4} (see "Output" section for details), so printing like 9.9992 or `10.000869120' will also be correct.


Sample Input 3

9
815886884 307027576
432574413 156832535
869389414 537542354
8271358 844638329
34762585 93905560
445922147 508315922
476305579 724641385
15004200 341668840
277786703 825590503

Sample Output 3

1000677079.68994784

Although the radius and coordinate is 10^9 or less, the answer may exceed 10^9.

E - 90-degree Rotations

Time Limit: 1 sec / Memory Limit: 976 MB

配点:800

問題文

H \times W のマス目で表されるボードがあります。マス目の i \ (1 \leq i \leq H) 行目で j (1 \leq j \leq W) 列目のマスを (i, j) とします。

いくつかのマスにはコインがあります。S_{i, j} = o のとき、マス (i, j)1 つだけコインがあり、x のときコインがありません。

ロボットがコインのあるマスから上下左右のいずれかの方向を向いてスタートします。スタート位置と方向は E869120 君が自由に決めることができます。

その後、E869120 君は次の操作を繰り返します。

  • その場にあるコインを取った後、90 度左回転または 90 度右回転し、向いている方向に 1 マス以上進んだコインのある位置までジャンプする。

スタートする位置と方向、ジャンプする位置、回転する方向をうまく決めたときに、E869120 君はすべてのコインを回収することができるでしょうか?

制約

  • 2 \leq H \leq 100
  • 2 \leq W \leq 100
  • S_{i, j}o または x のいずれか
  • 最低 1 つのコインがボード上にある

部分点

この問題はいくつかの小課題に分けられ、その小課題のすべてのテストケースに正解した場合に「この小課題に正解した」とみなされます。
提出したソースコードの得点は、正解した小課題の点数の合計となります。

  1. (100 点):N \leq 8
  2. (110 点):N \leq 16
  3. (150 点):H = 2
  4. (440 点):追加の制約はない。

ただし、ここで N は「マス目上にあるコインの枚数」とします。


入力

入力は以下の形式で標準入力から与えられます。

H W
S_{1, 1}S_{1, 2}S_{1, 3}...S_{1, W}
S_{2, 1}S_{2, 2}S_{2, 3}...S_{2, W}
  :   :   :
S_{H, 1}S_{H, 2}S_{H, 3}...S_{H, W}

出力

コインをすべて回収する方法があるならば Possible、どのような行動を取ってもコインをすべて回収できないならば Impossible と出力してください。


入力例 1

5 5
xooxx
xoxxo
xxoox
ooxoo
xoxxx

出力例 1

Possible

次のような順序でロボットを動かすと、すべてのコインを回収することができます。


入力例 2

2 9
oxxxxoxxo
oxoxxoxxo

出力例 2

Possible

次のような順序でロボットを動かすと、すべてのコインを回収することができます。


入力例 3

9 25
xxxxxxxxxxxxxxxxxxxxxxxxx
xxoooxxxoooxxooooxxxoooxx
xoxxxoxoxxxoxoxxxoxoxxxox
xoxxxxxoxxxoxoxxxoxoxxxxx
xxoooxxxoooxxooooxxoxxxxx
xxxxxoxoxxxoxoxxxxxoxxxxx
xoxxxoxoxxxoxoxxxxxoxxxox
xxoooxxxoooxxoxxxxxxoooxx
xxxxxxxxxxxxxxxxxxxxxxxxx

出力例 3

Impossible

どのようなロボットの動かし方をしても、すべてのコインを回収することができません。


入力例 4

6 6
oxxxxo
xoooxx
xoooox
xoooox
xxooxx
oxxxxo

出力例 4

Impossible

この場合も、どのようなロボットの動かし方をしても、すべてのコインを回収することができません。

Max Score:800 points

Problem Statement

There is a rectangular board with H \times W cells. The cell of i-th row and j-th column is denoted by (i, j).

There are coins in some cells. If S_{i, j} = o, there is one coin in (i, j). Otherwise, if S_{i, j} = x, there is no coins in (i, j).

E869120 will place a robot in cell with coin, and he will set the initial direction, choosing from up / down / left / right. Then, the robot will repeat the following actions.

  • Collect the coins in the cell of robot. Then, rotate 90 degrees left or right. After that, jump to any cell with coin that advances at least 1 cells in the direction robot faces.

E869120's objective is to collect all coins in the board. Determine if there's a way to fulfill the objective when E869120 can decide initial cell/direction of robot, and the direction of rotation and destination of jumps for each action.

Constraints

  • 2 \leq H \leq 100
  • 2 \leq W \leq 100
  • S_{i, j} is either o or x.
  • There is at least 1 coin on the board.

Subtasks / Scoring

This problem is separated several two subtasks, and you will get score of the subtask if your program prints the correct answer for all testcases for the subtask prepared.
The score for a program is the sum of score of subtasks of correct answer.

  1. (100 points):N \leq 8
  2. (110 points):N \leq 16
  3. (150 points):H = 2
  4. (440 points):No additional constraints.

When we let N the number of coins on the board.


Input

The input will be given from standard input, in the following format.

H W
S_{1, 1}S_{1, 2}S_{1, 3}...S_{1, W}
S_{2, 1}S_{2, 2}S_{2, 3}...S_{2, W}
  :   :   :
S_{H, 1}S_{H, 2}S_{H, 3}...S_{H, W}

Output

Print Possible if there is a way to collect all coins; otherwise, print Impossible.


Sample Input 1

5 5
xooxx
xoxxo
xxoox
ooxoo
xoxxx

Sample Output 1

Possible

He can fulfill the objective by moving like the following picture.


Sample Input 2

2 9
oxxxxoxxo
oxoxxoxxo

Sample Output 2

Possible

He can fulfill the objective by moving like the following picture.


Sample Input 3

9 25
xxxxxxxxxxxxxxxxxxxxxxxxx
xxoooxxxoooxxooooxxxoooxx
xoxxxoxoxxxoxoxxxoxoxxxox
xoxxxxxoxxxoxoxxxoxoxxxxx
xxoooxxxoooxxooooxxoxxxxx
xxxxxoxoxxxoxoxxxxxoxxxxx
xoxxxoxoxxxoxoxxxxxoxxxox
xxoooxxxoooxxoxxxxxxoooxx
xxxxxxxxxxxxxxxxxxxxxxxxx

Sample Output 3

Impossible

He cannot collect all coins no matter how he commanded the robot.


Sample Input 4

6 6
oxxxxo
xoooxx
xoooox
xoooox
xxooxx
oxxxxo

Sample Output 4

Impossible

He cannot collect all coins no matter how he commanded the robot, also in this case...

F - Random Shuffles

Time Limit: 1 sec / Memory Limit: 976 MB

配点:1000

問題文

新学期も始まり、新しいクラスで交流を行いたいと思った E869120 君は、次のようなカードゲームを考えました。

  • N 枚のカードがあり、1, 2, 3,..., N と番号付けられています。
  • カードは D 種類の色のいずれかで塗られており、色は 0, 1, 2,..., D-1 のいずれかの数で表されます。
  • カード i は色 S_i \ (0 \leq S_i < D) で塗られており、i という数が書かれています。

このカードを用いて、D 人でカードゲームを行います。ルールは以下の通りです:

  1. まず、番号 1, 2, 3, ..., k のカードを重ねて山にします。番号 i のカードが上から i 番目に来るようにします。
  2. 次 (3.) の操作を L 回繰り返します。
  3. 1 以上 k 以下のランダムな整数 i を選び、上から i 枚目のカードと上から i+1 枚目のカードの位置を入れ替えます。
  4. 最後、カードの山の上から順に、プレイヤー 1, 2, 3,..., D, 1, 2, 3,..., D, 1, 2,... という順番で 1 枚ずつ配っていきます。
  5. プレイヤー i の得点は、そのプレイヤーが持っているカードのうち色 (i-1) が塗られたものに書かれた数の合計です。

ただし、3. では「上から k+1 枚目のカード」は「上から 1 枚目のカード」を指すことにします。

このゲームは N \div D ラウンドにわたって行われます。i 回目のラウンドは、k = i \times D でゲームを行います。
そのとき、それぞれのラウンドに対して各プレイヤーの得点の期待値を求めてください。

ただし、出力サイズの都合上、出力の形式が通常と違うので、「出力」の項をお読みください。

制約

  • D3 以上 10 以下の整数
  • N3 以上 3 \ 000 \ 000 以下の D の倍数
  • L1 以上 1 \ 000 \ 000 \ 000 以下の整数
  • S_i \ (1 \leq i \leq N)0, 1, 2, ..., D-1 のいずれか

部分点

この問題はいくつかの小課題に分けられ、その小課題のすべてのテストケースに正解した場合に「この小課題に正解した」とみなされます。
提出したソースコードの得点は、正解した小課題の点数の合計となります。

  1. (50 点):N \leq 10, D \leq 4, L = 1
  2. (70 点):N \leq 10, D \leq 4, L \leq 5
  3. (80 点):N \leq 50, D \leq 4, L \leq 300
  4. (100 点):N \leq 3 \ 000, D \leq 4, L \leq 300
  5. (210 点):N \leq 3 \ 000, D \leq 4
  6. (130 点):N \leq 50 \ 000, D \leq 4
  7. (40 点):N \leq 150 \ 000, D \leq 6
  8. (40 点):N \leq 300 \ 000, D \leq 8
  9. (40 点):N \leq 500 \ 000, D \leq 10
  10. (40 点):N \leq 800 \ 000, D \leq 10
  11. (200 点):N \leq 3 \ 000 \ 000, D \leq 10

入力

入力は以下の形式で標準入力から与えられます。
ただし、S_1, S_2, ..., S_N に関しては、数字をつなげた文字列として与えられます。

N D L
S_{1}S_{2}S_{3}S_{4} ... S_{N}

出力

D 行に渡って出力してください。
i 行目には、プレイヤー iN \div D 回のゲームの得点の期待値の合計を出力してください。
絶対誤差または相対誤差が 10^{-5} 未満であれば、正解と見做されます。


入力例 1

3 3 1
012

出力例 1

0.333333333333
0.666666666667
1.000000000000

カードの並びを最初 (1, 2, 3) として、L=1 回の問題文中の 3. の操作を繰り返すと、(1, 3, 2), (2, 1, 3), (3, 2, 1) の可能性が 1/3 ずつになります。

それぞれ、プレイヤーの得点は以下の通りです。

  • (1, 3, 2):プレイヤーの得点はそれぞれ 1, 0, 0
  • (2, 1, 3):プレイヤーの得点はそれぞれ 0, 0, 3
  • (3, 2, 1):プレイヤーの得点はそれぞれ 0, 2, 0

よって、プレイヤーの得点の期待値はそれぞれ 1/3, 2/3, 1 になります。


入力例 2

8 4 1
01123310

出力例 2

2.250000000000
4.500000000000
1.500000000000
0.625000000000

1 ラウンド目では、次の 4 通りが等確率で起こります。

  • (1, 2, 4, 3):プレイヤーの得点はそれぞれ 1, 2, 4, 0
  • (1, 3, 2, 4):プレイヤーの得点はそれぞれ 1, 3, 0, 0
  • (2, 1, 3, 4):プレイヤーの得点はそれぞれ 0, 0, 0, 0
  • (4, 2, 3, 1):プレイヤーの得点はそれぞれ 0, 2, 0, 0

したがって、1 ラウンド目でのそれぞれのプレイヤーの得点の期待値はそれぞれ 1/2, 7/4, 1, 0 になります。

2 ラウンド目では、次の 8 通りが等確率で起こります。

  • (1, 2, 3, 4, 5, 6, 8, 7):プレイヤーの得点はそれぞれ 1, 2, 0, 0
  • (1, 2, 3, 4, 5, 7, 6, 8):プレイヤーの得点はそれぞれ 1, 9, 0, 0
  • (1, 2, 3, 4, 6, 5, 7, 8):プレイヤーの得点はそれぞれ 1, 2, 0, 0
  • (1, 2, 3, 5, 4, 6, 7, 8):プレイヤーの得点はそれぞれ 1, 2, 0, 5
  • (1, 2, 4, 3, 5, 6, 7, 8):プレイヤーの得点はそれぞれ 1, 2, 4, 0
  • (1, 3, 2, 4, 5, 6, 7, 8):プレイヤーの得点はそれぞれ 1, 3, 0, 0
  • (2, 1, 3, 4, 5, 6, 7, 8):プレイヤーの得点はそれぞれ 0, 0, 0, 0
  • (8, 2, 3, 4, 5, 6, 7, 1):プレイヤーの得点はそれぞれ 8, 2, 0, 0

したがって、2 ラウンド目でのそれぞれのプレイヤーの得点の期待値はそれぞれ 7/4, 11/4, 1/2, 5/8 となります。


入力例 3

20 4 15
10232310010022312313

出力例 3

34.068777543023
27.854472795592
22.354635768263
28.066210471955

Max Score:1000 points

Problem Statment

In Japan, school starts from April. Since E869120 wanted to play with other classmates, he came up with the following card game.

  • There are N cards, which is numbered 1, 2, 3, ..., N.
  • There are D species of colors in cards, which is numbered 0, 1, 2, ..., D-1.
  • Card i is colored with color S_i \ (0 \leq S_i < D), and the number i is written on it.

The card game will be played by D players, with using the cards. The rule is following:

  1. First, make a pile with card 1, 2, 3, ..., k. Card i should be located at i-th from topmost.
  2. Repeat next operation (3.), K times.
  3. Choose the random integer i between 1 and k (inclusive) with equal probability, and swap the i-th topmost card and (i+1)-th topmost card currently.
  4. Distribute the cards to players. More precisely, player 1, 2, 3,..., D, 1, 2, 3, ..., D, 1, 2, 3, ..., D, 1, 2,... will get the 1, 2, 3, 4, 5, 6,..., k-th topmost card, respectively.
  5. The score of player i is the total number written on cards himself/herself have with color (i-1).

Please note that, for operation 3., "(k+1)-th topmost cards" means "1-st topmost cards$ instead.

This game consists of N \div D rounds. In the i-th round, the game will be played at k = i \times D.
For each round, calculate the expected value of score for each players.

Please note that the format of output is different, due to the size matter of output. See "Output" section for details.

Constraints

  • D is between 3 and 10 (inclusive).
  • N is between 3 and 3 \ 000 \ 000 (inclusive).
  • K is between 1 and 1 \ 000 \ 000 \ 000 (inclusive).
  • S_i \ (1 \leq i \leq N) is either of 0, 1, 2, ..., D-1.

Subtasks / Scoring

This problem is separated several two subtasks, and you will get score of the subtask if your program prints the correct answer for all testcases for the subtask prepared.
The score for a program is the sum of score of subtasks of correct answer.

  1. (50 points):N \leq 10, D \leq 4, K = 1
  2. (70 points):N \leq 10, D \leq 4, K \leq 5
  3. (80 points):N \leq 50, D \leq 4, K \leq 300
  4. (100 points):N \leq 3 \ 000, D \leq 4, K \leq 300
  5. (210 points):N \leq 3 \ 000, D \leq 4
  6. (130 points):N \leq 50 \ 000, D \leq 4
  7. (40 points):N \leq 150 \ 000, D \leq 6
  8. (40 points):N \leq 300 \ 000, D \leq 8
  9. (40 points):N \leq 500 \ 000, D \leq 10
  10. (40 points):N \leq 800 \ 000, D \leq 10
  11. (200 points):N \leq 3 \ 000 \ 000, D \leq 10

入力

The input will be given from the Standard Input, in the following format.
Note that, for S_1, S_2, ..., S_N, it will be given as a string concatenated them (all S_i are one-digit numbers).

N D L
S_{1}S_{2}S_{3}S_{4} ... S_{N}

Output

Print in D lines. In i-th line, print the sum of expected score of all N \div D rounds, for player i.
If the relative or absolute error is 10^{-5} or less, your program is regarded as correct.


Sample Input 1

3 3 1
012

Sample Output 1

0.333333333333
0.666666666667
1.000000000000

Let the initial arrangement of cards (1, 2, 3). After K=1 time "operation 3" in problem statement, the arrangement of cards, (1, 3, 2), (2, 1, 3), (3, 2, 1) will be equally probable with probability 1/3.

For each possibility, the scores of players will be following:

  • (1, 3, 2):Players' score will be 1, 0, 0
  • (2, 1, 3):Players' score will be 0, 0, 3
  • (3, 2, 1):Players' score will be 0, 2, 0

Thus, the expected value of players' score will be 1/3, 2/3, 1.


Sample Input 2

8 4 1
01123310

Sample Output 2

2.250000000000
4.500000000000
1.500000000000
0.625000000000

In 1-st round, the following 4 scenarios are equally possible.

  • (1, 2, 4, 3):Players' score will be 1, 2, 4, 0
  • (1, 3, 2, 4):Players' score will be 1, 3, 0, 0
  • (2, 1, 3, 4):Players' score will be 0, 0, 0, 0
  • (4, 2, 3, 1):Players' score will be 0, 2, 0, 0

Hence, the expected score for each players in 1-st round, will be 1/2, 7/4, 1, 0.

In 2-nd round, the following 8 scenarios are equally possible.

  • (1, 2, 3, 4, 5, 6, 8, 7):Players' score will be 1, 2, 0, 0
  • (1, 2, 3, 4, 5, 7, 6, 8):Players' score will be 1, 9, 0, 0
  • (1, 2, 3, 4, 6, 5, 7, 8):Players' score will be 1, 2, 0, 0
  • (1, 2, 3, 5, 4, 6, 7, 8):Players' score will be 1, 2, 0, 5
  • (1, 2, 4, 3, 5, 6, 7, 8):Players' score will be 1, 2, 4, 0
  • (1, 3, 2, 4, 5, 6, 7, 8):Players' score will be 1, 3, 0, 0
  • (2, 1, 3, 4, 5, 6, 7, 8):Players' score will be 0, 0, 0, 0
  • (8, 2, 3, 4, 5, 6, 7, 1):Players' score will be 8, 2, 0, 0

Hence, the expected score for each players in 2-nd round, will be 7/4, 11/4, 1/2, 5/8.


Sample Input 3

20 4 15
10232310010022312313

Sample Output 3

34.068777543023
27.854472795592
22.354635768263
28.066210471955
G - Medals

Time Limit: 1 sec / Memory Limit: 976 MB

配点:1200

問題文

時は 2212 年。競技プログラミングというスポーツの規模も広がり、国際情報オリンピックが世界で一躍有名になりました!

さて、この年の国際情報オリンピック (IOI) には N 人の参加者がいます。競技は 2 日間に渡って行われます。

  • 1 日目:筆記試験を行う。選手 iA_i 点を獲得した。筆記試験では同点はいなかった。
  • 2 日目:実技試験を行う。実技試験では、試験の結果によって 1 点から N 点までの点数が 1 人ずつに付けられる。最も良い技を見せた選手には N 点、2 番目に良い技を見せた選手には N - 1 点、… 最も悪い技を見せた選手には 1 点が付けられる。

あなたは 1 日目の競技の得点を知っています。しかし、2 日目の競技の得点は誰の得点に関しても知りません。
さて、選手の 順位 は、以下のようにして決まります。

  • 基本的に、より合計点が高い選手がより高い順位になる。(ただし一番高い順位は 1 であり、一番低い順位は N である。)
  • ただし同点が存在する場合、同点内での順位は抽選によってランダムに決まる。

1 位を取った人が金メダル、2 位を取った人が銀メダル、3 位を取った人が銅メダルを獲得します。
また、あなたはメダリストの情報について、1 つだけ知っています。これは、P (P1 または 2) によって表され:

  • P = 1 のとき、メダリストのみで 1 日目の点数を高い順に並び替えると、(金, 銀, 銅) となる。
  • P = 2 のとき、メダリストのみで 1 日目の点数を高い順に並び替えると、(金, 銅, 銀) となる。

そのとき、(金メダリスト, 銀メダリスト, 銅メダリスト) の組は何通りあるでしょうか?

制約

  • N5 以上 1 \ 000 \ 000 以下の整数
  • P1 または 2
  • A_i1 以上 1 \ 000 \ 000 \ 000 以下の整数
  • A_i は全て相異なる

小課題・得点

この問題には 2 つの小課題がある。  

  1. (600 点):P = 1
  2. (600 点):P = 2

それぞれの小課題は、次のような 12 個の部分点データセットからなる。部分点の条件を満たすテストケースにすべて正解した場合に、「この部分点データセットに正解した」とみなされる。

  1. (50 点):5 \leq N \leq 7
  2. (50 点):5 \leq N \leq 15
  3. (50 点):5 \leq N \leq 30
  4. (50 点):5 \leq N \leq 70
  5. (50 点):5 \leq N \leq 200
  6. (50 点):5 \leq N \leq 600
  7. (50 点):5 \leq N \leq 2 \ 000
  8. (50 点):5 \leq N \leq 8 \ 000
  9. (50 点):5 \leq N \leq 50 \ 000
  10. (50 点):5 \leq N \leq 200 \ 000
  11. (50 点):5 \leq N \leq 500 \ 000
  12. (50 点):5 \leq N \leq 1 \ 000 \ 000

提出したソースコードの得点は、2 つの小課題の「正解した部分点データセットの点数の合計」を足し算した値です。


入力

入力は以下の形式で標準入力から与えられる.

N P
A_1 A_2 A_3 ... A_N

出力

(金, 銀, 銅) の組としてあり得る通り数を 1 行に出力してください。


入力例 1

5 1
3 1 6 4 8

出力例 1

4

次の 4 つの可能性があります。金メダリストが選手 i、銀メダリストが選手 j、銅メダリストが選手 k のときを (i, j, k) で表します。

  • (5, 3, 1) のケース:2 日目の点数が選手 1 から順に 3, 4, 2, 1, 5 のとき、合計点は 6, 5, 8, 5, 13 となり、条件を満たす。
  • (5, 3, 2) のケース:2 日目の点数が選手 1 から順に 2, 4, 3, 1, 5 のとき、合計点は 5, 5, 9, 5, 13 となり、抽選の結果によっては条件を満たす。
  • (5, 3, 4) のケース:2 日目の点数が選手 1 から順に 1, 2, 3, 4, 5 のとき、合計点は 4, 3, 9, 8, 13 となり、条件を満たす。
  • (5, 4, 1) のケース:2 日目の点数が選手 1 から順に 4, 2, 1, 3, 5 のとき、合計点は 7, 3, 7, 7, 13 となり、抽選の結果によっては条件を満たす。

入力例 2

5 2
6 4 1 7 2

出力例 2

3

次の 3 つの可能性があります。金メダリストが選手 i、銀メダリストが選手 j、銅メダリストが選手 k のときを (i, j, k) で表します。

  • (4, 2, 1) のケース:2 日目の点数が選手 1 から順に 1, 5, 3, 4, 2 のとき、合計点は 7, 9, 4, 11, 4 となり、条件を満たす。
  • (4, 5, 1) のケース:2 日目の点数が選手 1 から順に 1, 2, 3, 4, 5 のとき、合計点は 7, 6, 4, 11, 7 となり、抽選の結果によっては条件を満たす。
  • (4, 5, 2) のケース;2 日目の点数が選手 1 から順に 1, 3, 2, 4, 5 のとき、合計点は 7, 7, 3, 11, 7 となり、抽選の結果によっては条件を満たす。

入力例 3

10 1
6 4 11 14 3 17 13 18 8 10

出力例 3

26

入力例 4

10 2
18 14 19 4 12 1 7 15 9 5

出力例 4

14

Max Score:1200 points

Problem Statement

In 2212, competitive programming is much more famous than now, and International Olympiad of Informatics (IOI) is one of the most famous contest in the world.

This year, N contestants, whose ID is numbered from 1 to N, participated in IOI.

The competition is held on 2 days as follows:

  • Day 1: There is a paper test. Contestant i got A_i points. It is guaranteed that A_i \neq A_j (1 \leq i < j \leq N).
  • Day 2: There is a practical test. In this test, score between 1 and N will be granted for each contestant. The contestant who performed the best will get N points, the contestant who performed the second best will get N - 1 points, ..., and the contestant who performed the worst will get 1 points.

Currently, you knows Day-1 score of all participants. But you don't know any of Day-2 results.
In IOI-rule, the participants' final score is (the score of paper test) + (the score of practical test).

The rank of the contestant will be determined as follows:

  • Basically, the higher the final score is, the higher the rank is. (Note: The highest rank is 1, and the lowest rank is N.)
  • If there are tie score, the rank will be determined with random-lottery among the contestant who got the same score.

In addition, contestant who got rank 1 will get a gold medal, contestant who got rank 2 will get a silver medal, and contestant who got rank 3 will get a bronze medal.

He knows one more informations about the final standings in IOI 2212. The information is represented as one integer P (either 1 or 2).

  • Let X be the participant ID who got the gold medal.
  • Let Y be the participant ID who got the silver medal.
  • Let Z be the participant ID who got the bronze medal.
  • If P = 1, A_X > A_Y > A_Z is satisfied.
  • If P = 2, A_X > A_Z > A_Y is satisfied.

How many possible combinations of (X, Y, Z) are there?

Constraints

  • N is an integer between 5 and 1 \ 000 \ 000 (inclusive)
  • P is either 1 or 2
  • A_i is an integer between 1 and 1 \ 000 \ 000 \ 000 (inclusive)
  • All A_i are different.

Subtasks and scoring

In this problem, there are 2 subtasks as follows.

  1. (600 points):P = 1
  2. (600 points):P = 2

In each subtask, there are 12 datasets as follows.

  1. (50 points):5 \leq N \leq 7
  2. (50 points):5 \leq N \leq 15
  3. (50 points):5 \leq N \leq 30
  4. (50 points):5 \leq N \leq 70
  5. (50 points):5 \leq N \leq 200
  6. (50 points):5 \leq N \leq 600
  7. (50 points):5 \leq N \leq 2 \ 000
  8. (50 points):5 \leq N \leq 8 \ 000
  9. (50 points):5 \leq N \leq 50 \ 000
  10. (50 points):5 \leq N \leq 200 \ 000
  11. (50 points):5 \leq N \leq 500 \ 000
  12. (50 points):5 \leq N \leq 1 \ 000 \ 000

Note: In each datasets, there can be two or more testcases.


Input

Input is given from Standard Input in the following format:

N P
A_1 A_2 A_3 ... A_N

Output

Print the number of possible combinations of (X, Y, Z).


Sample Input 1

5 1
3 1 6 4 8

Sample Output 1

4

Let B_i be the Day-2 score of contestant i.
There are 4 ways as follows. X is the ID of gold medalist, Y ID the id of silver medalist, and Z is the ID of bronze medalist.

  • (X, Y, Z) = (5, 3, 1). If B = (3, 4, 2, 1, 5), the final score will be 6, 5, 8, 5, 13. Therefore, it satisfies the condition.
  • (X, Y, Z) = (5, 3, 2). If B = (2, 4, 3, 1, 5), the final score will be 5, 5, 9, 5, 13. Therefore, depending on lottery, it is possible that satisfies the condition.
  • (X, Y, Z) = (5, 3, 4). If B = (1, 2, 3, 4, 5), the final score will be 4, 3, 9, 8, 13. Therefore, it satisfies the condition.
  • (X, Y, Z) = (5, 4, 1). If B = (4, 2, 1, 3, 5), the final score will be 7, 3, 7, 7, 13. Therefore, depending on lottery, it is possible that satisfies the condition.

Sample Input 2

5 2
6 4 1 7 2

Sample Output 2

3

There are 3 ways as follows.

  • (X, Y, Z) = (4, 2, 1). If B = (1, 5, 3, 4, 2), the final score will be 7, 9, 4, 11, 4. Therefore, it satisfies the condition.
  • (X, Y, Z) = (4, 5, 1). If B = (1, 2, 3, 4, 5), the final score will be 7, 6, 4, 11, 7. Therefore, depending on lottery, it is possible that satisfies the condition.
  • (X, Y, Z) = (4, 5, 2). If B = (1, 3, 2, 4, 5), the final score will be 7, 7, 3, 11, 7. Therefore, depending on lottery, it is possible that satisfies the condition.

Sample Input 3

10 1
6 4 11 14 3 17 13 18 8 10

Sample Output 3

26

Sample Input 4

10 2
18 14 19 4 12 1 7 15 9 5

Sample Output 4

14
H - Percepts of AtCoder 2

Time Limit: 3 sec / Memory Limit: 976 MB

配点:1500

問題文

E869120 は square1001 に、今年から Q 年間誕生日に数列をプレゼントすることにしました。
square1001 は、「プレゼントする数列の長さが短い方がよりコンパクトで良い」と言ったので、プレゼントする数列は出来るだけ短くしたいです。また、古から伝わる AtCoder 社の教えに基づいて、プレゼントする数列を決める必要があります。

AtCoder 社の教えとは、以下のようなものです。

  • 数列の要素は全て 異なる
  • プレゼントする数列に部分列として出現する数列のうち、単調増加列であるようなものの種類数はちょうど、聖なる数 K 個である。

ここで、数列 A = (A_1, A_2, ..., A_N) の「部分列」とは、A から 0 個以上 N 個以下の値を消して、残った値の順序を変えずにできる数列のことです。
また、数列 A = (A_1, A_2, ..., A_N) が「単調増加列」である条件は、A_1 < A_2 < ... < A_N であることです。

例えば、A = (3, 4, 1, 2) の時、部分列として出現する「単調増加列」は (), (1), (2), (3), (4), (1, 2), (3, 4)7 個です。

AtCoder 社では、毎年「聖なる数」が変わります。具体的には、i 年目の聖なる数は K_i です。
E869120 君のために、i 年目にプレゼントするべき数列を求めてください。

入力

入力は以下の形式で標準入力から与えられます。

Q
K_1
K_2
K_3
...
K_Q

出力

以下のように Q 行に渡って出力してください。

(1 年目の数列の情報)
(2 年目の数列の情報)
(3 年目の数列の情報)
...
(Q 年目の数列の情報)

ただし、数列の情報は以下のように出力してください。

N A_1 A_2 A_3 ... A_N

出力する数列は、以下の条件を満たす必要があります。

  • 0 \leq N \leq 128
  • 0 \leq A_i \leq 999
  • A_i \neq A_j (i \neq j)

制約

  • Q1 以上 1 \ 000 以下の整数
  • K_i1 以上 5 \ 000 \ 000 \ 000 \ 000 \ 000 \ 000 \ (= 5 \times 10^{18}) 以下の整数

小課題・得点

  1. (30 点):K_i \leq 100 を満たす。
  2. (70 点):K_i \leq 1 \ 500 を満たす。
  3. (1400 点) : 追加の制約はない。

ただし、小課題 3 について、以下のように得点が決定します。
ここでは、Q 年間における N の最大値を L とします。また、全てのテストケースにおける L の最大値を L' とします。

  • 120 \leq L' \leq 128 のとき、この小課題の得点は 125
  • 100 \leq L' \leq 119 のとき、この小課題の得点は 1400 \times 5^{-(L' - 99) / 20}
  • 0 \leq L' \leq 99 のとき、この小課題の得点は 1400

入力例 1

2
5
10

出力例 1

3 2 3 1
6 8 6 9 1 2 0

1 年目のプレゼントとして渡す数列は、(2, 3, 1) です。
この数列には、増加部分列が 5 個あります。(), (1), (2), (3), (2, 3) です。


入力例 2

3
20
100
869120

出力例 2

9 9 7 3 6 5 8 4 1 2
10 0 5 9 3 6 1 4 2 7 8
72 47 45 28 9 41 50 33 61 27 15 38 54 52 22 57 7 30 12 46 21 19 8 71 20 23 6 18 26 17 39 4 53 44 3 31 68 29 42 62 37 69 67 40 65 2 55 36 35 11 49 24 25 43 48 0 1 16 10 70 66 64 32 5 51 60 63 58 56 59 13 14 34

Max Score:1500 points

Problem Statement

E869120 the Coder decided to give a sequence to square1001 as a birthday gift each year, for next Q years.
Since square1001 said that "It is better if the length of sequence is shorter", the length of the sequence should be as short as possible.
Moreover, there is "AtCoder's Percepts" which has been told from ancient times, so he also decided to determine the sequence based on this percepts.

The contents of "AtCoder percepts" is as follows:

  • The elements in sequence should be distinct.
  • The sequence which is about to give, should have exactly K increasing subsequence. (K is "holy number")
  • Subsequence of A = (A_1, A_2, ..., A_N) is the sequence which can make by deleting some (possibly zero or all) elements without changing the order of remaining elements.
  • Note: Also empty sequence is included as a increasing subsequence. In addition, even if the places which has deleted is different, when the resulting subsequence is same, it is regarded as the same subsequence.
  • For example, if A = (3, 4, 1, 2), there are 7 increasing subsequences: (), (1), (2), (3), (4), (1, 2), (3, 4).

In AtCoder, "holy number" will change every year. In i-th year, holy number is K_i.
Please find a sequence which E869120 the Coder should give as a present in each year.

Input

Input is given from Standard Input in the following format:

Q
K_1
K_2
K_3
...
K_Q

Output

Print Q lines as follows:

(Information of sequence in 1-st year)
(Information of sequence in 2-nd year)
(Information of sequence in 3-rd year)
...
(Information of sequence in Q-th year)

You should output the information of sequence as follows:

N A_1 A_2 A_3 ... A_N

Note N is the length of A.
The sequence should satisfy these conditions:

  • 0 \leq N \leq 128
  • 0 \leq A_i \leq 999
  • A_i \neq A_j (i \neq j)

Constraints

  • Q is an integer between 1 and 1 \ 000 (inclusive)
  • K_i is an integer between 1 and 5 \ 000 \ 000 \ 000 \ 000 \ 000 \ 000 \ (= 5 \times 10^{18}) (inclusive)

Subtasks / Scoring

  1. (30 points):K_i \leq 100
  2. (70 points):K_i \leq 1 \ 500
  3. (1400 points) : There are no additional constraints.

In subtask 3, the score will be determined as follows.
Let L be the maximum value of N in this testcase, and let L' be the maximum value of L in all testcases in subtask 3.

  • 120 \leq L' \leq 128 : 125 points in subtask 3
  • 100 \leq L' \leq 119 : 1400 \times 5^{-(L' - 99) / 20} points in subtask 3
  • 0 \leq L' \leq 99 : 1400 points in subtask 3

Sample Input 1

2
5
10

Sample Output 1

3 2 3 1
6 8 6 9 1 2 0

The sequence that E869120 gives in 1st year is (2, 3, 1).
There are 5 increasing subsequence: (), (1), (2), (3), (2, 3).


Sample Input 2

3
20
100
869120

Sample Output 2

9 9 7 3 6 5 8 4 1 2
10 0 5 9 3 6 1 4 2 7 8
72 47 45 28 9 41 50 33 61 27 15 38 54 52 22 57 7 30 12 46 21 19 8 71 20 23 6 18 26 17 39 4 53 44 3 31 68 29 42 62 37 69 67 40 65 2 55 36 35 11 49 24 25 43 48 0 1 16 10 70 66 64 32 5 51 60 63 58 56 59 13 14 34
I - Garden 2

Time Limit: 3 sec / Memory Limit: 976 MB

配点:1500

問題文

時は 2022 年 6 月 20 日。AtCoder は創立 10 周年を記念し、会社の前に庭が作られました。
庭は HW 列のマス目で表され、上から i 行目、左から j 列目にあるマスを、マス (i, j) とします。
各マスには 1 つの花が植えられています。マス (i, j) の花の美しさは A_{i, j} です。

例えば、以下のような図が庭の例です。ただし各マスに書かれている数は花の綺麗さです。

さて、あなたはいくつかの花を伐採し、 美しい庭 を作りたいです。美しい庭とは、以下のような条件を満たすものです。

  • 伐採されていない花のマス (a, b) から、別の伐採されていない花のマス (c, d) まで、上下左右に隣り合う伐採されていない花のマスのみを辿って、同じマスを二度通らずに行く方法はちょうど 1 通り存在する。
  • 全ての伐採されていない花のマス (a, b), (c, d) ((a, b) \neq (c, d)) について上が成り立つ。

例えば、以下のような伐採の仕方をすると、美しい庭になります。

一方、以下のような伐採の仕方をすると、美しい庭にはなりません。

庭の得点 は、伐採されていない花の綺麗さの合計です。ただし、庭が美しい庭でなければ、庭の得点は 0 点となります。
例えば、上の図の庭 A の得点は 20 点、庭 B の得点は 60 点、庭 C, D, E までの得点は 0 点です。
そのとき、庭の得点が出来るだけ高くなるような伐採方法を出力してください。

入力

入力は以下の形式で標準入力から与えられます。

H W
A_{1, 1} A_{1, 2} A_{1, 3} ... A_{1, W}
A_{2, 1} A_{2, 2} A_{2, 3} ... A_{2, W}
A_{3, 1} A_{3, 2} A_{3, 3} ... A_{3, W}
...
A_{H, 1} A_{H, 2} A_{H, 3} ... A_{H, W}

出力

以下のように H 行に渡って出力してください。

c_{1, 1}c_{1, 2}c_{1, 3} ... c_{1, W}
c_{2, 1}c_{2, 2}c_{2, 3} ... c_{2, W}
c_{3, 1}c_{3, 2}c_{3, 3} ... c_{3, W}
...
c_{H, 1}c_{H, 2}c_{H, 3} ... c_{H, W}

ただし、c_{i, j} は、マス (i, j) を伐採 しない 場合 #、伐採 する 場合 . としてください。


制約

  • H, W1 以上 500 以下の整数
  • A_{i, j}1 以上 9 以下の整数

テストケースの生成について

テストケースは、以下のように作成されている。

  • 各テストケースごとに、H, W の値が決まっている。これに関しては、小課題・得点の項を参照すること。
  • A_{i, j} については、各 (i, j) (1 \leq i \leq H, 1 \leq j \leq W) について 1 以上 9 以下の整数から一様な確率で選ぶ。

小課題・得点

採点に使われるテストケースは 15 個存在する。各テストケースごとに 100 点満点で採点され、100 \times 15 = 1500 点満点でこの問題の点数が決定する。
各ケースの採点方法は以下のようである。ここでは、そのケースでの「庭の得点」を L とし、また、L' = L \div (H \times W) とする。

(☆) H = 5, W = 5 (ケース 1, 2, 3) の場合、H = 5, W = 500 (ケース 4, 5, 6) の場合の採点方法

  • 0.00 \leq L' < 2.00 のとき、0
  • 2.00 \leq L' < 3.33 のとき、0 + (L - 2.00) \times 21
  • 3.33 \leq L' < 3.93 のとき、28 + (L - 3.33) \times 40
  • 3.93 \leq L' < 4.03 のとき、52 + (L - 3.93) \times 480
  • 4.03 \leq L' のとき、100

(★) H = 500, W = 500 (ケース 7, 8, 9, 10, 11, 12, 13, 14, 15) の場合の採点方法

  • 0.00 \leq L' < 2.00 のとき、0
  • 2.00 \leq L' < 3.33 のとき、0 + (L - 2.00) \times 21
  • 3.33 \leq L' < 3.78 のとき、28 + (L - 3.33) \times 75
  • 3.78 \leq L' < 3.84 のとき、61 + (L - 3.78) \times 650
  • 3.84 \leq L' のとき、100

2.00 \leq L' \leq 4.05 の場合の、L' の値と得点の関係を表したグラフは以下のようになる。

注意

0 点と採点されたテストケースが存在する場合に限り、WA と判定されることにご注意ください。
WA でも得点がもらえている場合があること、AC でも満点ではない場合があることにご注意ください。

この問題はマラソン型課題であるため、全てのケースで満点を取れることが保証されていないことにご注意ください。作問者の解法が必ず満点とは限りません。
また、この問題に関して、満点の基準を大幅に超える提出が多数見られた場合、得点の式が変更される場合が非常に小さい確率ですがあります。ご了承ください。なお、競技開始 3 時間後以降は、得点の変更がないことが保証されております。


入力例 1

3 3
1 2 3
4 5 6
7 8 9

出力例 1

#.#
###
#.#

出力例 1 のような伐採方法を行うと、庭の得点は 1 + 3 + 4 + 5 + 6 + 7 + 9 = 35 点となります。
なお、このテストケースは採点用データに含まれないことにご注意ください。


入力例 2

4 5
4 1 8 2 6
2 2 1 2 5
3 5 1 9 2
5 1 2 3 6

出力例 2

#.###
#...#
#####
#.#.#

この入力例は、問題文中の画像に対応します。
また、この出力例は問題文中の例 B に対応し、庭の得点は 60 となります。そのとき、L' の値は 60 \div 20 = 3.00 となります。
ちなみに、庭の得点が 62 となるような出力も存在しますが、この問題では必ずしも最も庭の得点が最大となるような出力をする必要はないことにご注意ください。
なお、このテストケースも採点用データに含まれないことにご注意ください。

Max Score:1500 points

Problem Statement

June 20th, 2022 is the day of 10 year anniversary from the launch of AtCoder.
On this day, a garden was built in front of AtCoder to celebrate this anniversary.

The garden is represented as a H \times W grid. The cell that i-th row from the top and the j-th column from the left is denoted as cell (i, j).
In each cell, there is a flower. The beauty of flower in cell (i, j) is A_{i, j}.

An example of the garden is as follows: (The case of H = 4, W = 5)

You should make a beautiful garden by cutting flowers in some cells. The condition which should satisfy to be a beautiful garden is as follows:

  • For all a, b, c, d that both flowers in cell (a, b) and cell (c, d) ((a, b) \neq (c, d)) has not been cut, it satisfies following condition.
  • From (a, b) to (c, d), there is exactly 1 ways to go, by moving either of up, right, left, down by one square repeatedly, without passing the same cell twice.

For example, if you cut some flowers like A, and B, it will be a beautiful garden.

For example, if you cut some flowers like C, D, E, it will not be a beautiful garden.

The score of garden will be calculated as follows:

  • If the garden is not a beautiful garden, the score will be 0.
  • If the garden is a beautiful garden, the score will be the total beuaty of flowers which has not been cut.

For example, the score of garden A is 20, the score of garden B is 60, and the score of garden C, D, E are 0.
Print a way of cutting flowers that score of garden is as high as you can.

Input

Input is given from Standard Input in the following format:

H W
A_{1, 1} A_{1, 2} A_{1, 3} ... A_{1, W}
A_{2, 1} A_{2, 2} A_{2, 3} ... A_{2, W}
A_{3, 1} A_{3, 2} A_{3, 3} ... A_{3, W}
...
A_{H, 1} A_{H, 2} A_{H, 3} ... A_{H, W}

Output

Print H likes as follows:

c_{1, 1}c_{1, 2}c_{1, 3} ... c_{1, W}
c_{2, 1}c_{2, 2}c_{2, 3} ... c_{2, W}
c_{3, 1}c_{3, 2}c_{3, 3} ... c_{3, W}
...
c_{H, 1}c_{H, 2}c_{H, 3} ... c_{H, W}

c_{i, j} should be # if you won't cut a flower in cell (i, j), and . if you will cut flower in cell (i, j).


Constraints

  • H, W are integers between 1 and 500.
  • A_{i, j} is an integer between 1 and 9.

About Testcases

Testcases are generated as follows:

  • For each testcase, H, W is determined. You should look subtasks/scoring section to know about the exact value.
  • A_{i, j} is random integer between 1 and 9. The probability that A_{i, j} = 1 is 1 in 9. It is the same for A_{i, j} = 2, 3, 4, ..., 9.

Subtasks and Scoring

There are 15 testcases that are used for grading. Since max score per each case is 100. Max score of this problem is 100 \times 15 = 1500.
For each case, it will be graded as follows. Let L be the score of garden in your output, and let L' be L \div (H \times W).

(i) When H = 5, W = 5 (Case #1, #2, #3), or H = 5, W = 500 (Case #4, #5, #6):

  • If 0.00 \leq L' < 2.00 : 0 points
  • If 2.00 \leq L' < 3.33 : 0 + (L - 2.00) \times 21 points
  • If 3.33 \leq L' < 3.93 : 28 + (L - 3.33) \times 40 points
  • If 3.93 \leq L' < 4.03 : 52 + (L - 3.93) \times 480 points
  • If 4.03 \leq L' : 100 points

(ii) When H = 500, W = 500 (Case #7, #8, #9, #10, #11, #12, #13, #14, #15):

  • If 0.00 \leq L' < 2.00 : 0 points
  • If 2.00 \leq L' < 3.33 : 0 + (L - 2.00) \times 21 points
  • If 3.33 \leq L' < 3.78 : 28 + (L - 3.33) \times 75 points
  • If 3.78 \leq L' < 3.84 : 61 + (L - 3.78) \times 650 points
  • If 3.84 \leq L' : 100 points

This is the graph which describes the relation between L' and score when 2.00 \leq L' \leq 4.05.

Note

The verdict will be AC if there is no testcase which is graded 0 points.
It means it is not always full-score if you got AC, and it also means even if you got WA it is possible that you got some partial score.

Since this problem is marathon-match like optimization task, it is not guaranteed that there is a full-solution for all cases. Solution of problemsetter is not always full score. In addition, it is very unlikely, but if many people wrote the solution which significantly over the creterion of full score, changing scoring formula is also possible. It is guaranteed that there is no change of scoring formula after 3 hours from the beginning of this contest.


Sample Input 1

3 3
1 2 3
4 5 6
7 8 9

Sample Output 1

#.#
###
#.#

In this example, the score of garden is 1 + 3 + 4 + 5 + 6 + 7 + 9 = 35.
Note: This input is not included in datasets for grading.


Sample Input 2

4 5
4 1 8 2 6
2 2 1 2 5
3 5 1 9 2
5 1 2 3 6

Sample Output 2

#.###
#...#
#####
#.#.#

This example is as same as the example picture that written in problem statement.
Also, this sample output is as same as garden B that written in problem statement. The score of garden is 60, and value of L' is 3.0.
Actually, there is a solution which the score of garden is 62 :)
Note: This input is also not included in datasets for grading.