実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 100 点
問題文
2^n \gt n^2 ですか?
制約
- n は 1 以上 10^9 以下の整数
入力
入力は以下の形式で標準入力から与えられる。
n
出力
2^n \gt n^2 なら Yes を、そうでないなら No を出力せよ。
入力例 1
5
出力例 1
Yes
2^5=32,\ 5^2=25 より 2^n \gt n^2 であるため、Yes を出力します。
入力例 2
2
出力例 2
No
n=2 の場合 2^n=n^2=2^2 となり、故に 2^n \gt n^2 ではありません。よって No を出力します。
入力例 3
623947744
出力例 3
Yes
Score : 100 points
Problem Statement
Does 2^n \gt n^2 hold?
Constraints
- n is an integer between 1 and 10^9 (inclusive).
Input
Input is given from Standard Input in the following format:
n
Output
If 2^n \gt n^2, print Yes; otherwise, print No.
Sample Input 1
5
Sample Output 1
Yes
Since 2^5=32,\ 5^2=25, we have 2^n \gt n^2, so Yes should be printed.
Sample Input 2
2
Sample Output 2
No
For n=2, we have 2^n=n^2=2^2, so 2^n \gt n^2 does not hold. Thus, No should be printed.
Sample Input 3
623947744
Sample Output 3
Yes
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 100 点
問題文
与えられる 5 つの整数 A, B, C, D, E の中に何種類の整数があるかを出力してください。
制約
- 0 \leq A, B, C, D, E \leq 100
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
A B C D E
出力
答えを出力せよ。
入力例 1
31 9 24 31 24
出力例 1
3
与えられる 5 つの整数 31, 9, 24, 31, 24 の中には、9, 24, 31 という 3 種類の整数があります。 よって、3 を出力します。
入力例 2
0 0 0 0 0
出力例 2
1
Score : 100 points
Problem Statement
Print how many distinct integers there are in given five integers A, B, C, D, and E.
Constraints
- 0 \leq A, B, C, D, E \leq 100
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
A B C D E
Output
Print the answer.
Sample Input 1
31 9 24 31 24
Sample Output 1
3
In the given five integers 31, 9, 24, 31, and 24, there are three distinct integers 9, 24, and 31. Thus, 3 should be printed.
Sample Input 2
0 0 0 0 0
Sample Output 2
1
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 200 点
問題文
二次元平面上に N 個の点があります。i 個目の点の座標は (x_i,y_i) です。
この中から 2 個の点を選ぶとき、それらを結ぶ線分の長さの最大値を求めてください。
制約
- 2 \leq N \leq 100
- -1000 \leq x_i,y_i \leq 1000
- (x_i,y_i) \neq (x_j,y_j)\ (i \neq j)
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N
x_1 y_1
x_2 y_2
\hspace{0.4cm} \vdots
x_N y_N
出力
2 点を結ぶ線分の長さの最大値を出力せよ。
想定解との絶対誤差または相対誤差が 10^{-6} 以下であれば正解とみなされる。
入力例 1
3 0 0 0 1 1 1
出力例 1
1.4142135624
1 個目の点と 3 個目の点を選んだときそれらを結ぶ線分の長さは \sqrt 2 = 1.41421356237\dots となり、これが最大です。
入力例 2
5 315 271 -2 -621 -205 -511 -952 482 165 463
出力例 2
1455.7159750446
Score : 200 points
Problem Statement
There are N points in a two-dimensional plane. The coordinates of the i-th point are (x_i,y_i).
Find the maximum length of a segment connecting two of these points.
Constraints
- 2 \leq N \leq 100
- -1000 \leq x_i,y_i \leq 1000
- (x_i,y_i) \neq (x_j,y_j)\ (i \neq j)
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
x_1 y_1
x_2 y_2
\hspace{0.4cm} \vdots
x_N y_N
Output
Print the maximum length of a segment connecting two of the points.
Your answer will be considered correct when the absolute or relative error from the judge's answer is at most 10^{-6}.
Sample Input 1
3 0 0 0 1 1 1
Sample Output 1
1.4142135624
For the 1-st and 3-rd points, the length of the segment connecting them is \sqrt 2 = 1.41421356237\dots, which is the maximum length.
Sample Input 2
5 315 271 -2 -621 -205 -511 -952 482 165 463
Sample Output 2
1455.7159750446
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 200 点
問題文
空に M 種類の鳥が合わせて N 羽飛んでいます。
鳥の種類には 1,2,\dots,M の番号が付けられています。
N 羽の鳥には 1,2,\dots,N の番号が付けられており、鳥 i の種類は A_i で、大きさは B_i です。
全ての k=1,2,\dots,M について、飛んでいる種類 k の鳥の大きさの平均値を求めてください。
ただし、全ての k=1,2,\dots,M について、種類 k の鳥が 1 羽以上飛んでいることが保証されます。
制約
- 1 \le M \le N \le 100
- 1 \le A_i \le M
- 1 \le B_i \le 100
- 種類 k の鳥が少なくとも 1 羽存在する ( 1 \le k \le M )
- 入力される値は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N M A_1 B_1 A_2 B_2 \vdots A_N B_N
出力
M 行出力せよ。
k ( 1 \le k \le M ) 行目には、種類 k の鳥の大きさの平均値を出力せよ。
真の解との絶対誤差または相対誤差が 10^{-5} 以下であるとき、正解とみなされる。
入力例 1
10 5 4 92 1 16 3 77 4 99 2 89 3 8 1 40 5 56 1 40 4 77
出力例 1
32.00000000000000000000 89.00000000000000000000 42.50000000000000000000 89.33333333333333333333 56.00000000000000000000
- 種類 1 の鳥の大きさの平均値は (16+40+40)/3 = 32 です。
- 種類 2 の鳥の大きさの平均値は 89 です。
- 種類 3 の鳥の大きさの平均値は (77+8)/2 = 42.5 です。
- 種類 4 の鳥の大きさの平均値は (92+99+77)/3 \approx 89.3333 です。
- 種類 5 の鳥の大きさの平均値は 56 です。
Score : 200 points
Problem Statement
There are N birds of M types flying in the sky.
The bird types are numbered 1,2,\dots,M.
The N birds are numbered 1,2,\dots,N, and bird i is of type A_i and has size B_i.
For every k=1,2,\dots,M, find the average size of the flying birds of type k.
It is guaranteed that for every k=1,2,\dots,M, there is at least one bird of type k flying.
Constraints
- 1 \le M \le N \le 100
- 1 \le A_i \le M
- 1 \le B_i \le 100
- There exists at least one bird of type k ( 1 \le k \le M ).
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N M A_1 B_1 A_2 B_2 \vdots A_N B_N
Output
Output M lines.
The k-th line ( 1 \le k \le M ) should contain the average size of birds of type k.
Your answer will be considered correct if the absolute or relative error from the true value is at most 10^{-5}.
Sample Input 1
10 5 4 92 1 16 3 77 4 99 2 89 3 8 1 40 5 56 1 40 4 77
Sample Output 1
32.00000000000000000000 89.00000000000000000000 42.50000000000000000000 89.33333333333333333333 56.00000000000000000000
- The average size of birds of type 1 is (16+40+40)/3 = 32.
- The average size of birds of type 2 is 89.
- The average size of birds of type 3 is (77+8)/2 = 42.5.
- The average size of birds of type 4 is (92+99+77)/3 \approx 89.3333.
- The average size of birds of type 5 is 56.
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 300 点
問題文
ピザ屋で働く高橋くんは、まかないとして美味しいチーズピザを作ることにしました。
今、高橋くんの目の前に N 種類のチーズがあります。
i 種類目のチーズは 1 [g] あたりのおいしさが A_i で、 B_i [g] あります。
ピザのおいしさは、ピザに乗せたチーズのおいしさの総和で決まります。
但し、チーズを使いすぎると怒られてしまうため、乗せたチーズの重さは合計で W [g] 以下である必要があります。
この条件のもとで、可能なピザのおいしさの最大値を求めてください。
制約
- 入力は全て整数
- 1 \le N \le 3 \times 10^5
- 1 \le W \le 3 \times 10^8
- 1 \le A_i \le 10^9
- 1 \le B_i \le 1000
入力
入力は以下の形式で標準入力から与えられる。
N W A_1 B_1 A_2 B_2 \vdots A_N B_N
出力
答えを整数として出力せよ。
入力例 1
3 5 3 1 4 2 2 3
出力例 1
15
1 種類目のチーズを 1 [g] 、 2 種類目のチーズを 2 [g] 、 3 種類目のチーズを 2 [g] 乗せるのが最適です。
このとき、ピザのおいしさは 15 となります。
入力例 2
4 100 6 2 1 5 3 9 8 7
出力例 2
100
チーズの重量の総和が W [g] に満たないケースもあります。
入力例 3
10 3141 314944731 649 140276783 228 578012421 809 878510647 519 925326537 943 337666726 611 879137070 306 87808915 39 756059990 244 228622672 291
出力例 3
2357689932073
Score : 300 points
Problem Statement
Takahashi, who works for a pizza restaurant, is making a delicious cheese pizza for staff meals.
There are N kinds of cheese in front of him.
The deliciousness of the i-th kind of cheese is A_i per gram, and B_i grams of this cheese are available.
The deliciousness of the pizza will be the total deliciousness of cheese he puts on top of the pizza.
However, using too much cheese would make his boss angry, so the pizza can have at most W grams of cheese on top of it.
Under this condition, find the maximum possible deliciousness of the pizza.
Constraints
- All values in input are integers.
- 1 \le N \le 3 \times 10^5
- 1 \le W \le 3 \times 10^8
- 1 \le A_i \le 10^9
- 1 \le B_i \le 1000
Input
Input is given from Standard Input in the following format:
N W A_1 B_1 A_2 B_2 \vdots A_N B_N
Output
Print the answer as an integer.
Sample Input 1
3 5 3 1 4 2 2 3
Sample Output 1
15
The optimal choice is to use 1 gram of cheese of the first kind, 2 grams of the second kind, and 2 grams of the third kind.
The pizza will have a deliciousness of 15.
Sample Input 2
4 100 6 2 1 5 3 9 8 7
Sample Output 2
100
There may be less than W grams of cheese in total.
Sample Input 3
10 3141 314944731 649 140276783 228 578012421 809 878510647 519 925326537 943 337666726 611 879137070 306 87808915 39 756059990 244 228622672 291
Sample Output 3
2357689932073
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 350 点
問題文
N 種類の薬品 1,2,\dots,N があります。あなたの目標はこれらが全て混ざった状態にすることです。
0, 1 からなる長さ 2^N-1 の文字列 S が与えられます。この文字列は次の情報を表します。
- まず、 1 種類以上の薬品が混ざった状態 i ( 1 \le i \le 2^N-1 ) を次のように定義する。
- i を 2 進法で表記した際に下から k ( 1 \le k \le N ) 桁目が 1 である、またその時に限り、薬品 k が含まれている。
- 例えば、 13 を 2 進法で表記すると 1101_{(2)} となるため、状態 13 は薬品 1,3,4 が混ざった状態を表現します。
- S の i 文字目が
0であるとき、状態 i は 安全 である。 - S の i 文字目が
1であるとき、状態 i は 危険 である。
あなたは次の操作を使って薬品を混ぜ合わせます。
- まず、空の瓶を用意する。
- 次に、以下を繰り返す。
- まだ瓶に注いでいない薬品を 1 種類選択し、瓶に注ぐ。
- この時、瓶の中で混ざった薬品が危険な状態であってはならない。
この操作によって全ての薬品が混ざった状態を作れるか判定してください。
T 個のテストケースが与えられるので、それぞれについて答えを求めてください。
制約
- T は 1 以上 40000 以下の整数
- N は 1 以上 18 以下の整数
- S は
0,1からなる長さ 2^N-1 の文字列 - ひとつの入力に含まれる |S| = 2^N-1 の総和は 5 \times 10^5 を超えない
入力
入力は以下の形式で標準入力から与えられる。
T
\mathrm{case}_1
\mathrm{case}_2
\vdots
\mathrm{case}_T
\mathrm{case}_i は i 番目のテストケースを表す。 各テストケースは以下の形式で与えられる。
N S
出力
T 行出力せよ。i 行目 には i 番目のテストケースに対する答えを出力せよ。
各テストケースについて、全ての薬品が混ざった状態を作れるなら Yes 、作れないなら No と出力せよ。
入力例 1
5 3 0010000 3 0010110 1 1 2 100 4 001110010101110
出力例 1
Yes No No Yes Yes
この入力には 5 個のテストケースが含まれます。
1 番目のケースは次の通りです。
- 3 種類の薬品が存在する。
- 薬品 1,2 が混ざった状態 3 のみが危険で、他の状態は安全である。
- 例えば、以下の手順で全ての薬品が混ざった状態を作ることができます。
- はじめに、瓶に薬品 2 を注ぐ。瓶の中で薬品 2 のみが混ざっており、これは状態 2 なので安全である。
- 次に、瓶に薬品 3 を注ぐ。瓶の中で薬品 2,3 が混ざっており、これは状態 6 なので安全である。
- 最後に、瓶に薬品 1 を注ぐ。瓶の中で薬品 1,2,3 が混ざっており、これは状態 7 なので安全である。
2 番目のケースは次の通りです。
- 3 種類の薬品が存在する。
- 薬品 1,2 が混ざった状態 3 、薬品 1,3 が混ざった状態 5 、薬品 2,3 が混ざった状態 6 が危険で、他の状態は安全である。
- このケースについて、全ての薬品が混ざった状態を作ることはできません。
3 番目のケースは次の通りです。
- 1 種類の薬品が存在する。
- 薬品 1 のみが混ざった状態 1 が危険であるため、全ての薬品が混ざった状態を作ることはできません。
Score : 350 points
Problem Statement
There are N types of chemicals 1,2,\dots,N. Your goal is to create a state where all of them are mixed.
You are given a string S of length 2^N-1 consisting of 0 and 1, which represents the following information:
- First, define state i (1 \le i \le 2^N-1) where one or more types of chemicals are mixed as follows:
- When the k-th digit (1 \le k \le N) from the bottom in the binary representation of i is 1, and only then, chemical k is included.
- For example, 13 in binary is 1101_{(2)}, so state 13 represents a state where chemicals 1,3,4 are mixed.
- When the i-th character of S is
0, state i is safe. - When the i-th character of S is
1, state i is dangerous.
You mix chemicals using the following operation:
- First, prepare an empty bottle.
- Next, repeat the following:
- Choose one type of chemical that has not yet been poured into the bottle and pour it into the bottle.
- At this time, the chemicals mixed in the bottle must not be in a dangerous state.
Determine whether this operation can create a state where all chemicals are mixed.
You are given T test cases; solve each of them.
Constraints
- T is an integer between 1 and 40000, inclusive.
- N is an integer between 1 and 18, inclusive.
- S is a string of length 2^N-1 consisting of
0and1. - The sum of |S| = 2^N-1 in each input does not exceed 5 \times 10^5.
Input
The input is given from Standard Input in the following format:
T
\mathrm{case}_1
\mathrm{case}_2
\vdots
\mathrm{case}_T
\mathrm{case}_i represents the i-th test case. Each test case is given in the following format:
N S
Output
Output T lines. The i-th line should contain the answer for the i-th test case.
For each test case, if it is possible to create a state where all chemicals are mixed, print Yes; otherwise, print No.
Sample Input 1
5 3 0010000 3 0010110 1 1 2 100 4 001110010101110
Sample Output 1
Yes No No Yes Yes
This input contains five test cases.
The 1st case is as follows:
- There are three types of chemicals.
- Only state 3 where chemicals 1,2 are mixed is dangerous, and the other states are safe.
- For example, you can create a state where all chemicals are mixed with the following procedure:
- First, pour chemical 2 into the bottle. Only chemical 2 is mixed in the bottle, which is state 2, so it is safe.
- Next, pour chemical 3 into the bottle. Chemicals 2,3 are mixed in the bottle, which is state 6, so it is safe.
- Finally, pour chemical 1 into the bottle. Chemicals 1,2,3 are mixed in the bottle, which is state 7, so it is safe.
The 2nd case is as follows:
- There are three types of chemicals.
- State 3 where chemicals 1,2 are mixed, state 5 where chemicals 1,3 are mixed, and state 6 where chemicals 2,3 are mixed are dangerous, and the other states are safe.
- For this case, it is impossible to create a state where all chemicals are mixed.
The 3rd case is as follows:
- There is one type of chemical.
- Since state 1 where only chemical 1 is mixed is dangerous, it is impossible to create a state where all chemicals are mixed.
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 400 点
問題文
N 人のスポーツ選手がいます。
N 人の選手たちには互いに相性の悪い選手のペアが M 組あり、相性の悪い組のうち i\ (1\leq i\leq M) 組目は A _ i 番目の選手と B _ i 番目の選手です。
あなたは、選手を T チームに分けます。 どの選手もちょうど一つのチームに属さなければならず、どのチームにも少なくとも一人の選手が属さなければなりません。 さらに、どの i=1,2,\ldots,M についても、 A _ i 番目の選手と B _ i 番目の選手が同じチームに属していてはいけません。
この条件を満たすチーム分けの方法は何通りあるか求めてください。 ただし、チーム分けの方法が異なるとは、ある二人が存在して、彼らが一方のチーム分けでは同じチームに所属し、もう一方では異なるチームに所属することをいいます。
制約
- 1\leq T\leq N\leq10
- 0\leq M\leq\dfrac{N(N-1)}2
- 1\leq A _ i\lt B _ i\leq N\ (1\leq i\leq M)
- (A _ i,B _ i)\neq (A _ j,B _ j)\ (1\leq i\lt j\leq M)
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N T M A _ 1 B _ 1 A _ 2 B _ 2 \vdots A _ M B _ M
出力
答えを 1 行で出力せよ。
入力例 1
5 2 2 1 3 3 4
出力例 1
4
次の 4 通りのチーム分けが条件を満たします。

他に条件を満たすチーム分けは存在しないので、4 を出力してください。
入力例 2
5 1 2 1 3 3 4
出力例 2
0
条件を満たすチーム分けがひとつも存在しないこともあります。
入力例 3
6 4 0
出力例 3
65
相性の悪いペアがひとつも存在しないこともあります。
入力例 4
10 6 8 5 9 1 4 3 8 1 6 4 10 5 7 5 6 3 7
出力例 4
8001
Score : 400 points
Problem Statement
There are N sports players.
Among them, there are M incompatible pairs. The i-th incompatible pair (1\leq i\leq M) is the A_i-th and B_i-th players.
You will divide the players into T teams. Every player must belong to exactly one team, and every team must have one or more players. Additionally, for each i=1,2,\ldots,M, the A_i-th and B_i-th players must not belong to the same team.
Find the number of ways to satisfy these conditions. Here, two divisions are considered different when there are two players who belong to the same team in one division and different teams in the other.
Constraints
- 1\leq T\leq N\leq10
- 0\leq M\leq\dfrac{N(N-1)}2
- 1\leq A _ i\lt B _ i\leq N\ (1\leq i\leq M)
- (A _ i,B _ i)\neq (A _ j,B _ j)\ (1\leq i\lt j\leq M)
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N T M A _ 1 B _ 1 A _ 2 B _ 2 \vdots A _ M B _ M
Output
Print the answer in a single line.
Sample Input 1
5 2 2 1 3 3 4
Sample Output 1
4
The following four divisions satisfy the conditions.

No other division satisfies them, so print 4.
Sample Input 2
5 1 2 1 3 3 4
Sample Output 2
0
There may be no division that satisfies the conditions.
Sample Input 3
6 4 0
Sample Output 3
65
There may be no incompatible pair.
Sample Input 4
10 6 8 5 9 1 4 3 8 1 6 4 10 5 7 5 6 3 7
Sample Output 4
8001
実行時間制限: 3 sec / メモリ制限: 1024 MiB
配点 : 450 点
問題文
高橋君と青木君が二次元平面上を歩きます。
高橋君のスタート地点は (TS_X, TS_Y)、ゴール地点は (TG_X, TG_Y) です。 青木君のスタート地点は (AS_X, AS_Y)、ゴール地点は (AG_X, AG_Y) です。
二人は同時に各々のスタート地点を出発し、各々のゴール地点に向かって真っ直ぐ速さ 1 で歩き続け、各々のゴール地点に到達すると停止します。 (出発は同時ですが、停止するタイミングは同時とは限らないことに注意してください。)
二人の間の距離が最も短いタイミング(二人が出発する瞬間および停止した後を含む)における、二人の間の距離を求めてください。
ここで、距離はユークリッド距離を指すものとします。すなわち、2 点 (x_1,y_1),(x_2,y_2) の間の距離は \sqrt{(x_1-x_2)^2+(y_1-y_2)^2} として定められます。
T 個のテストケースが与えられるので、それぞれについて答えを求めてください。
制約
- 1\leq T\leq 2\times 10^5
- -100\leq TS_X,TS_Y,TG_X,TG_Y,AS_X,AS_Y,AG_X,AG_Y \leq 100
- (TS_X,TS_Y)\neq (TG_X,TG_Y)
- (AS_X,AS_Y)\neq (AG_X,AG_Y)
- 入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。
T
\text{case}_1
\text{case}_2
\vdots
\text{case}_T
\text{case}_i は i 番目のテストケースを表す。各テストケースは以下の形式で与えられる。
TS_X TS_Y TG_X TG_Y AS_X AS_Y AG_X AG_Y
出力
T 行出力せよ。i 行目 (1\leq i\leq T) には i 番目のテストケースに対する答えを出力せよ。
出力は、真の値との絶対誤差または相対誤差が 10^{-6} 以下のとき、正解と判定される。
入力例 1
4 0 0 -2 2 -1 -1 4 4 4 0 2 0 6 0 8 0 1 0 1 1 -1 0 1 1 -8 9 2 6 -10 -10 17 20
出力例 1
1.000000000000000 2.000000000000000 0.000000000000000 1.783905950993199
1 番目のテストケースについて、二人が出発する時刻を 0 とおくと、二人の行動は以下のようになります。
- 時刻 0:高橋君が (0,0) を出発し、(-2,2) に向かって速さ 1 で歩き始める。同時に、青木君が (-1,-1) を出発し、(4,4) に向かって速さ 1 で歩き始める。
- 時刻 2\sqrt{2}:高橋君がゴール地点の (-2,2) に到達し、停止する。このとき、青木君は (1,1) におり、まだ歩き続けている。
- 時刻 5\sqrt{2}:青木君がゴール地点の (4,4) に到達し、停止する。
二人の間の距離が最も短いのは時刻 \frac{1}{\sqrt{2}} であり、このとき高橋君と青木君はそれぞれ (-\frac{1}{2},\frac{1}{2}), (-\frac{1}{2},-\frac{1}{2}) にいて、その距離は 1 です。
2 番目のテストケースについて、二人の間の距離が最も短いのは二人が出発する瞬間であり、そのときの距離は 2 です。
3 番目のテストケースについて、二人の間の距離が最も短いのは二人が共に停止した後であり、そのときの距離は 0 です。
Score : 450 points
Problem Statement
Takahashi and Aoki walk on a two-dimensional plane.
Takahashi's start point is (TS_X, TS_Y) and goal point is (TG_X, TG_Y). Aoki's start point is (AS_X, AS_Y) and goal point is (AG_X, AG_Y).
They simultaneously depart from their respective start points and walk straight toward their respective goal points at speed 1, and stop when they reach their respective goal points. (Note that they depart simultaneously, but they do not necessarily stop at the same time.)
Find the distance between them at the moment when the distance between them is shortest (including the moment they depart and after they stop).
Here, distance refers to Euclidean distance. That is, the distance between two points (x_1,y_1),(x_2,y_2) is defined as \sqrt{(x_1-x_2)^2+(y_1-y_2)^2}.
You are given T test cases, so solve each of them.
Constraints
- 1\leq T\leq 2\times 10^5
- -100\leq TS_X,TS_Y,TG_X,TG_Y,AS_X,AS_Y,AG_X,AG_Y \leq 100
- (TS_X,TS_Y)\neq (TG_X,TG_Y)
- (AS_X,AS_Y)\neq (AG_X,AG_Y)
- All input values are integers.
Input
The input is given from Standard Input in the following format:
T
\text{case}_1
\text{case}_2
\vdots
\text{case}_T
\text{case}_i represents the i-th test case. Each test case is given in the following format:
TS_X TS_Y TG_X TG_Y AS_X AS_Y AG_X AG_Y
Output
Output T lines. The i-th line (1\leq i\leq T) should contain the answer for the i-th test case.
Your answer will be considered correct if the absolute or relative error from the true value is at most 10^{-6}.
Sample Input 1
4 0 0 -2 2 -1 -1 4 4 4 0 2 0 6 0 8 0 1 0 1 1 -1 0 1 1 -8 9 2 6 -10 -10 17 20
Sample Output 1
1.000000000000000 2.000000000000000 0.000000000000000 1.783905950993199
For the first test case, let time 0 be the moment they depart. Their behavior is as follows:
- Time 0: Takahashi departs from (0,0) and starts walking toward (-2,2) at speed 1. At the same time, Aoki departs from (-1,-1) and starts walking toward (4,4) at speed 1.
- Time 2\sqrt{2}: Takahashi reaches his goal point (-2,2) and stops. At this time, Aoki is at (1,1) and is still walking.
- Time 5\sqrt{2}: Aoki reaches his goal point (4,4) and stops.
The distance between them is shortest at time \frac{1}{\sqrt{2}}, when Takahashi and Aoki are at (-\frac{1}{2},\frac{1}{2}) and (-\frac{1}{2},-\frac{1}{2}) respectively, and the distance is 1.
For the second test case, the distance between them is shortest at the moment they depart, and the distance at that time is 2.
For the third test case, the distance between them is shortest after they both stop, and the distance at that time is 0.
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 500 点
問題文
空の配列 A があります。 i=1,2,\ldots,N の順に以下の操作を行います。
- 数 i を、A の前から P_i 番目の位置になるように挿入する。
- より正確には、「A の P_i-1 項目まで」「 i 」「A の P_i 項目以降」をこの順に連結したもので A を置き換える。
全ての操作を終えた後の A を出力してください。
制約
- 1 \leq N \leq 5\times 10^5
- 1 \leq P_i \leq i
- 入力は全て整数である
入力
入力は以下の形式で標準入力から与えられる。
N P_1 P_2 \ldots P_N
出力
全ての操作を終えた後の A を (A_1,\ldots,A_N) とするとき、A_1,\ldots,A_N をこの順に空白区切りで出力せよ。
入力例 1
4 1 1 2 1
出力例 1
4 2 3 1
操作は以下のように行われます。
- 数 1 を、A の前から 1 番目の位置になるように挿入する。 A=(1) となる。
- 数 2 を、A の前から 1 番目の位置になるように挿入する。 A=(2,1) となる。
- 数 3 を、A の前から 2 番目の位置になるように挿入する。 A=(2,3,1) となる。
- 数 4 を、A の前から 1 番目の位置になるように挿入する。 A=(4,2,3,1) となる。
入力例 2
5 1 2 3 4 5
出力例 2
1 2 3 4 5
Score : 500 points
Problem Statement
There is an empty array A. For i = 1,2,\ldots,N, perform the following operation in order:
- Insert the number i into A so that it becomes the P_i-th element from the beginning.
- More precisely, replace A with the concatenation of the first P_i-1 elements of A, then i, then the remaining elements of A starting from the P_i-th element, in this order.
Output the final array A after all operations have been completed.
Constraints
- 1 \leq N \leq 5\times 10^5
- 1 \leq P_i \leq i
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N P_1 P_2 \ldots P_N
Output
Let the final array be A = (A_1, A_2, \ldots, A_N). Print A_1, A_2, \ldots, A_N in this order, separated by spaces.
Sample Input 1
4 1 1 2 1
Sample Output 1
4 2 3 1
The operations are performed as follows:
- Insert the number 1 so that it becomes the 1st element of A. Now, A = (1).
- Insert the number 2 so that it becomes the 1st element of A. Now, A = (2, 1).
- Insert the number 3 so that it becomes the 2nd element of A. Now, A = (2, 3, 1).
- Insert the number 4 so that it becomes the 1st element of A. Now, A = (4, 2, 3, 1).
Sample Input 2
5 1 2 3 4 5
Sample Output 2
1 2 3 4 5