Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
x 軸の正の向きが右、y 軸の正の向きが上であるような xy 座標平面において、点 (a,b) を原点を中心として反時計回りに d 度回転させた点を求めてください。
制約
- -1000 \leq a,b \leq 1000
- 1 \leq d \leq 360
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
a b d
出力
求めるべき点を (a',b') とするとき、 a' と b' をこの順に空白区切りで出力せよ。
なお、各出力について、解との絶対誤差または相対誤差が 10^{−6} 以下であれば正解として扱われる。
入力例 1
2 2 180
出力例 1
-2 -2
(2,2) を原点を中心として反時計回りに 180 度回転させた点は、(2,2) を原点について対称な位置に移動させた点であり、(-2,-2) となります。
入力例 2
5 0 120
出力例 2
-2.49999999999999911182 4.33012701892219364908
(5,0) を原点を中心として反時計回りに 120 度回転させた点は (-\frac {5}{2} , \frac {5\sqrt{3}}{2}) です。
この例での出力はこれらの値と厳密には一致しませんが、誤差が十分に小さいため正解として扱われます。
入力例 3
0 0 11
出力例 3
0.00000000000000000000 0.00000000000000000000
(a,b) が原点(回転の中心)なので回転させても座標が変わりません。
入力例 4
15 5 360
出力例 4
15.00000000000000177636 4.99999999999999555911
360 度回転させたので座標が変わりません。
入力例 5
-505 191 278
出力例 5
118.85878514480690171240 526.66743699786547949770
Score : 200 points
Problem Statement
In an xy-coordinate plane whose x-axis is oriented to the right and whose y-axis is oriented upwards, rotate a point (a, b) around the origin d degrees counterclockwise and find the new coordinates of the point.
Constraints
- -1000 \leq a,b \leq 1000
- 1 \leq d \leq 360
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
a b d
Output
Let the new coordinates of the point be (a', b'). Print a' and b' in this order, with a space in between.
Your output will be considered correct when, for each value printed, the absolute or relative error from the answer is at most 10^{-6}.
Sample Input 1
2 2 180
Sample Output 1
-2 -2
When (2, 2) is rotated around the origin 180 degrees counterclockwise, it becomes the symmetric point of (2, 2) with respect to the origin, which is (-2, -2).
Sample Input 2
5 0 120
Sample Output 2
-2.49999999999999911182 4.33012701892219364908
When (5, 0) is rotated around the origin 120 degrees counterclockwise, it becomes (-\frac {5}{2} , \frac {5\sqrt{3}}{2}).
This sample output does not precisely match these values, but the errors are small enough to be considered correct.
Sample Input 3
0 0 11
Sample Output 3
0.00000000000000000000 0.00000000000000000000
Since (a, b) is the origin (the center of rotation), a rotation does not change its coordinates.
Sample Input 4
15 5 360
Sample Output 4
15.00000000000000177636 4.99999999999999555911
A 360-degree rotation does not change the coordinates of a point.
Sample Input 5
-505 191 278
Sample Output 5
118.85878514480690171240 526.66743699786547949770
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
次の図に示す、各マスが黒または白に塗られた縦 15 行 \times 横 15 列のグリッドにおいて、 上から R 行目、左から C 列目のマスが何色かを出力して下さい。
制約
- 1 \leq R, C \leq 15
- R, C は整数
入力
入力は以下の形式で標準入力から与えられる。
R C
出力
図のグリッドにおいて上から R 行目、左から C 列目のマスが黒色の場合は black
と、白色の場合は white
と出力せよ。
ジャッジは英小文字と英大文字を厳密に区別することに注意せよ。
入力例 1
3 5
出力例 1
black
図のグリッドにおいて上から 3 行目、左から 5 列目のマスは黒色です。
よって、black
と出力します。
入力例 2
4 5
出力例 2
white
図のグリッドにおいて上から 4 行目、左から 5 列目のマスは白色です。
よって、white
と出力します。
Score : 200 points
Problem Statement
Print the color of the cell at the R-th row from the top and C-th column from the left in the following grid with 15 vertical rows and 15 horizontal columns.
Constraints
- 1 \leq R, C \leq 15
- R and C are integers.
Input
Input is given from Standard Input in the following format:
R C
Output
In the grid above, if the color of the cell at the R-th row from the top and C-th column from the left is black, then print black
; if the cell is white, then print white
. Note that the judge is case-sensitive.
Sample Input 1
3 5
Sample Output 1
black
In the grid above, the cell at the 3-rd row from the top and 5-th column from the left is black. Thus, black
should be printed.
Sample Input 2
4 5
Sample Output 2
white
In the grid above, the cell at the 4-th row from the top and 5-th column from the left is white. Thus, white
should be printed.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
N 人の生徒が 4 日間にわたる試験を受けています。
それぞれの日に行われる試験は 300 点満点です。すなわち、4 日間を通した試験の満点は 1200 点です。
現在 3 日目までの試験が終わり、これから 4 日目の試験が行われようとしています。i \, (1 \leq i \leq N) 番目の生徒は j \, (1 \leq j \leq 3) 日目の試験で P_{i, j} 点獲得しました。
それぞれの生徒について、4 日目の試験後に上位 K 位以内に入っていることがあり得るかどうか判定してください。
ただし、4 日目の試験後の生徒の順位は、その生徒よりも 4 日間の合計点が高い生徒の人数に 1 を加えた値として定めます。
制約
- 1 \leq K \leq N \leq 10^5
- 0 \leq P_{i, j} \leq 300 \, (1 \leq i \leq N, 1 \leq j \leq 3)
- 入力は全て整数である。
入力
入力は以下の形式で標準入力から与えられる。
N K P_{1,1} P_{1,2} P_{1,3} \vdots P_{N,1} P_{N,2} P_{N,3}
出力
N 行出力せよ。i \, (1 \leq i \leq N) 行目には、i 番目の生徒が 4 日目の試験後に上位 K 位以内に入っていることがあり得るならば Yes
と、そうでないならば No
と出力せよ。
入力例 1
3 1 178 205 132 112 220 96 36 64 20
出力例 1
Yes Yes No
4 日目に全員が 100 点を取ると、1 番目の生徒が 1 位になります。 4 日目に 2 番目の生徒が 100 点を取り、それ以外の生徒が 0 点を取ると、2 番目の生徒が 1 位になります。 3 番目の生徒が 1 位になることはあり得ません。
入力例 2
2 1 300 300 300 200 200 200
出力例 2
Yes Yes
入力例 3
4 2 127 235 78 192 134 298 28 56 42 96 120 250
出力例 3
Yes Yes No Yes
Score : 300 points
Problem Statement
N students are taking a 4-day exam.
There is a 300-point test on each day, for a total of 1200 points.
The first three days of the exam are already over, and the fourth day is now about to begin. The i-th student (1 \leq i \leq N) got P_{i, j} points on the j-th day (1 \leq j \leq 3).
For each student, determine whether it is possible that he/she is ranked in the top K after the fourth day.
Here, the rank of a student after the fourth day is defined as the number of students whose total scores over the four days are higher than that of the student, plus 1.
Constraints
- 1 \leq K \leq N \leq 10^5
- 0 \leq P_{i, j} \leq 300 \, (1 \leq i \leq N, 1 \leq j \leq 3)
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N K P_{1,1} P_{1,2} P_{1,3} \vdots P_{N,1} P_{N,2} P_{N,3}
Output
Print N lines. The i-th line (1 \leq i \leq N) should contain Yes
if it is possible that the i-th student is ranked in the top K after the fourth day, and No
otherwise.
Sample Input 1
3 1 178 205 132 112 220 96 36 64 20
Sample Output 1
Yes Yes No
If every student scores 100 on the fourth day, the 1-st student will rank 1-st.
If the 2-nd student scores 100 and the other students score 0 on the fourth day, the 2-nd student will rank 1-st.
The 3-rd student will never rank 1-st.
Sample Input 2
2 1 300 300 300 200 200 200
Sample Output 2
Yes Yes
Sample Input 3
4 2 127 235 78 192 134 298 28 56 42 96 120 250
Sample Output 3
Yes Yes No Yes
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
列 S_n を次のように定義します。
- S_1 は 1 つの 1 からなる長さ 1 の列である。
- S_n (n は 2 以上の整数) は S_{n-1}, n, S_{n-1} をこの順につなげた列である。
たとえば S_2,S_3 は次のような列です。
- S_2 は S_1, 2, S_1 をこの順につなげた列なので 1,2,1 である。
- S_3 は S_2, 3, S_2 をこの順につなげた列なので 1,2,1,3,1,2,1 である。
N が与えられるので、列 S_N をすべて出力してください。
制約
- N は整数
- 1 \leq N \leq 16
入力
入力は以下の形式で標準入力から与えられる。
N
出力
S_N を空白区切りで出力せよ。
入力例 1
2
出力例 1
1 2 1
問題文の説明にある通り、S_2 は 1,2,1 となります。
入力例 2
1
出力例 2
1
入力例 3
4
出力例 3
1 2 1 3 1 2 1 4 1 2 1 3 1 2 1
S_4 は S_3,4,S_3 をこの順につなげた列です。
Score : 300 points
Problem Statement
We define sequences S_n as follows.
- S_1 is a sequence of length 1 containing a single 1.
- S_n (n is an integer greater than or equal to 2) is a sequence obtained by concatenating S_{n-1}, n, S_{n-1} in this order.
For example, S_2 and S_3 is defined as follows.
- S_2 is a concatenation of S_1, 2, and S_1, in this order, so it is 1,2,1.
- S_3 is a concatenation of S_2, 3, and S_2, in this order, so it is 1,2,1,3,1,2,1.
Given N, print the entire sequence S_N.
Constraints
- N is an integer.
- 1 \leq N \leq 16
Input
Input is given from Standard Input in the following format:
N
Output
Print S_N, with spaces in between.
Sample Input 1
2
Sample Output 1
1 2 1
As described in the Problem Statement, S_2 is 1,2,1.
Sample Input 2
1
Sample Output 2
1
Sample Input 3
4
Sample Output 3
1 2 1 3 1 2 1 4 1 2 1 3 1 2 1
- S_4 is a concatenation of S_3, 4, and S_3, in this order.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 400 点
問題文
AtCoder 国には 1 から N の番号がついた N 個の都市と、1 から N-1 の番号がついた N-1 個の道路があります。
道路 i を通ると都市 A_i と都市 B_i の間を相互に移動することができます。全ての都市は道路を使って互いに行き来できることが保証されます。
高橋くんは都市 1 を出発し、次のルールで旅をします。
- いまいる都市と道路で直接つながっている都市のうち、まだ訪れたことがない都市が存在するとき、そのような都市のうち番号が最も小さい都市へ移動する
- そのような都市が存在しないとき
- いまいる都市が都市 1 なら旅を終了する
- そうでないなら、いまいる都市を初めて訪れたときに直前にいた都市へ移動する
高橋くんが旅の過程で訪れる都市を順に答えてください。
制約
- 2 \leq N \leq 2\times 10^5
- 1\leq A_i,B_i \leq N
- 全ての都市は道路を使って互いに行き来できる
入力
入力は以下の形式で標準入力から与えられる。
N A_1 B_1 \vdots A_{N-1} B_{N-1}
出力
高橋くんが訪れる都市を、旅の開始時及び終了時の都市 1 も含めて順に空白区切りで出力せよ。
入力例 1
4 1 2 4 2 3 1
出力例 1
1 2 4 2 1 3 1
高橋くんの旅は次のようになります。
- 最初都市 1 にいます。
- 都市 1 から道路で直接つながっている都市のうち未訪問なのは都市 2,3 です。番号が小さい都市 2 へ移動します。
- 都市 2 から道路で直接つながっている都市のうち未訪問なのは都市 4 です。都市 4 へ移動します。
- 都市 4 から道路で直接つながっている都市のうち未訪問の都市はありません。直前にいた都市 2 へ移動します。
- 都市 2 から道路で直接つながっている都市のうち未訪問の都市はありません。初めて都市 2 に来る直前にいた都市 1 へ移動します。
- 都市 1 から道路で直接つながっている都市のうち未訪問なのは都市 3 です。都市 3 へ移動します。
- 都市 3 から道路で直接つながっている都市のうち未訪問の都市はありません。直前にいた都市 1 へ移動します。
- 都市 1 から道路で直接つながっている都市のうち未訪問の都市はありません。旅を終了します。
入力例 2
5 1 2 1 3 1 4 1 5
出力例 2
1 2 1 3 1 4 1 5 1
Score : 400 points
Problem Statement
The Republic of AtCoder has N cities numbered 1 through N and N-1 roads numbered 1 through N-1. Road i connects City A_i and City B_i bidirectionally. It is guaranteed that one can travel between every pair of cities using roads.
Takahashi will depart City 1 and have a journey by repeating the following.
- If there are unvisited cities that are directly connected to the city Takahashi is in now, he goes to the city with the smallest number among those cities.
- Otherwise,
- if he is in City 1, he ends the journey;
- otherwise, he goes to the city he was in just before visiting the current city for the first time.
Find the sequence of cities visited by Takahashi in the order he visits them.
Constraints
- 2 \leq N \leq 2\times 10^5
- 1\leq A_i,B_i \leq N
- It is possible to travel between every pair of cities using roads.
Input
Input is given from Standard Input in the following format:
N A_1 B_1 \vdots A_{N-1} B_{N-1}
Output
Print the sequence of cities visited by Takahashi in the order he visits them, including City 1 at the beginning and end of the journey, with spaces in between.
Sample Input 1
4 1 2 4 2 3 1
Sample Output 1
1 2 4 2 1 3 1
His journey will be as follows.
- Start in City 1.
- The unvisited cities directly connected to City 1 are City 2 and 3. Go to the city with the smaller number, that is, City 2.
- The unvisited city directly connected to City 2 is City 4. Go there.
- There is no unvisited city directly connected to City 4. Go back to City 2.
- There is no unvisited city directly connected to City 2. Go to City 1, where he was in just before visiting City 2 for the first time.
- The unvisited city directly connected to City 1 is City 3. Go there.
- There is no unvisited city directly connected to City 3. Go back to City 1.
- There is no unvisited city directly connected to City 1. End the journey.
Sample Input 2
5 1 2 1 3 1 4 1 5
Sample Output 2
1 2 1 3 1 4 1 5 1