実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 100 点
問題文
高橋君は、AtCoder 語を勉強しています。
高橋君は英単語に対して AtCoder 語の単語を対応させて覚えています。
高橋君は英語における red, blue, green は AtCoder 語ではそれぞれ SSS, FFF, MMM に対応していることを覚えており、他の単語は覚えていません。
英小文字からなる文字列 S が与えられます。S が高橋君が AtCoder 語との対応を覚えている英単語の表記と一致しているならば S に対応している AtCoder 語の単語を、そうでないならば文字列 Unknown を出力してください。
制約
- S は長さ 1 以上 10 以下の英小文字からなる文字列
入力
入力は以下の形式で標準入力から与えられる。
S
出力
問題文中の指示に従い、文字列を出力せよ。
入力例 1
red
出力例 1
SSS
英語における red は AtCoder 語における SSS に対応します。
入力例 2
atcoder
出力例 2
Unknown
Score : 100 points
Problem Statement
Takahashi is learning AtCoderish Language.
He memorizes AtCoderish words corresponding to English words.
He knows that red, blue, and green in English respectively correspond to SSS, FFF, and MMM in AtCoderish, and he knows no other words.
You are given a string S consisting of lowercase English letters. If S equals an English word that Takahashi knows corresponds to an AtCoderish word, output the AtCoderish word corresponding to S; otherwise, output the string Unknown.
Constraints
- S is a string of length between 1 and 10, inclusive, consisting of English letters.
Input
The input is given from Standard Input in the following format:
S
Output
Output a string according to the instructions in the problem statement.
Sample Input 1
red
Sample Output 1
SSS
red in English corresponds to SSS in AtCoderish.
Sample Input 2
atcoder
Sample Output 2
Unknown
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 100 点
問題文
xy 平面上に長方形があります。この長方形の各辺は x 軸または y 軸に平行であり、面積は 0 ではありません。
この長方形の 4 つの頂点のうち異なる 3 つの頂点の座標 (x_1, y_1), (x_2, y_2), (x_3, y_3) が与えられるので、残る 1 つの頂点の座標を求めてください。
制約
- -100 \leq x_i, y_i \leq 100
- (x_1, y_1), (x_2, y_2), (x_3, y_3) のすべてを頂点に持つ長方形がただ一つ存在し、その各辺は x 軸または y 軸に平行であり、面積は 0 ではない。
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
x_1 y_1 x_2 y_2 x_3 y_3
出力
答えとなる頂点の座標 (x, y) を下記の形式にしたがい空白区切りで出力せよ。
x y
入力例 1
-1 -1 -1 2 3 2
出力例 1
3 -1
(-1, -1), (-1, 2), (3, 2) を頂点とする長方形の残る 1 つの頂点は (3, -1) です。
入力例 2
-60 -40 -60 -80 -20 -80
出力例 2
-20 -40
Score : 100 points
Problem Statement
There is a rectangle in the xy-plane. Each edge of this rectangle is parallel to the x- or y-axis, and its area is not zero.
Given the coordinates of three of the four vertices of this rectangle, (x_1, y_1), (x_2, y_2), and (x_3, y_3), find the coordinates of the other vertex.
Constraints
- -100 \leq x_i, y_i \leq 100
- There uniquely exists a rectangle with all of (x_1, y_1), (x_2, y_2), (x_3, y_3) as vertices, edges parallel to the x- or y-axis, and a non-zero area.
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
x_1 y_1 x_2 y_2 x_3 y_3
Output
Print the sought coordinates (x, y) separated by a space in the following format:
x y
Sample Input 1
-1 -1 -1 2 3 2
Sample Output 1
3 -1
The other vertex of the rectangle with vertices (-1, -1), (-1, 2), (3, 2) is (3, -1).
Sample Input 2
-60 -40 -60 -80 -20 -80
Sample Output 2
-20 -40
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 150 点
問題文
2 次元座標平面の原点に高橋くんがいます。
高橋くんが座標平面上の点 (a,b) から点 (c,d) に移動するには \sqrt{(a-c)^2+(b-d)^2} のコストがかかります。
高橋くんが原点からスタートし N 個の点 (X_1,Y_1),\ldots,(X_N,Y_N) へこの順に移動したのち原点に戻るときの、コストの総和を求めてください。
制約
- 1 \leq N \leq 2\times 10^5
- -10^9 \leq X_i,Y_i \leq 10^9
- 入力は全て整数である
入力
入力は以下の形式で標準入力から与えられる。
N X_1 Y_1 \vdots X_N Y_N
出力
答えを出力せよ。
真の値との相対誤差または絶対誤差が 10^{-6} 以下であれば正解とみなされる。
入力例 1
2 1 2 -1 0
出力例 1
6.06449510224597979401
移動は次の 3 行程からなります。
- (0,0) から (1,2) に移動する。\sqrt{(0-1)^2+(0-2)^2}=\sqrt{5}=2.236067977... のコストがかかる
- (1,2) から (-1,0) に移動する。\sqrt{(1-(-1))^2+(2-0)^2}=\sqrt{8}=2.828427124... のコストがかかる
- (-1,0) から (0,0) に移動する。\sqrt{(-1-0)^2+(0-0)^2}=\sqrt{1}=1 のコストがかかる
コストの総和は 6.064495102... となります。
入力例 2
7 -14142 13562 -17320 50807 -22360 67977 24494 89742 -26457 51311 28284 27124 31622 77660
出力例 2
384694.57587932075868509383
入力例 3
5 -100000 100000 100000 -100000 -100000 100000 100000 -100000 -100000 100000
出力例 3
1414213.56237309504880168872
Score : 150 points
Problem Statement
Takahashi is at the origin on a two-dimensional coordinate plane.
The cost for him to move from point (a, b) to point (c, d) is \sqrt{(a - c)^2 + (b - d)^2}.
Find the total cost when he starts at the origin, visits N points (X_1, Y_1), \ldots, (X_N, Y_N) in this order, and then returns to the origin.
Constraints
- 1 \leq N \leq 2 \times 10^5
- -10^9 \leq X_i, Y_i \leq 10^9
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N X_1 Y_1 \vdots X_N Y_N
Output
Print the answer.
Your output will be considered correct if its absolute or relative error from the true value is at most 10^{-6}.
Sample Input 1
2 1 2 -1 0
Sample Output 1
6.06449510224597979401
The journey consists of the following three steps:
- Move from (0, 0) to (1, 2). The cost is \sqrt{(0 - 1)^2 + (0 - 2)^2} = \sqrt{5} = 2.236067977....
- Move from (1, 2) to (-1, 0). The cost is \sqrt{(1 - (-1))^2 + (2 - 0)^2} = \sqrt{8} = 2.828427124....
- Move from (-1, 0) to (0, 0). The cost is \sqrt{(-1 - 0)^2 + (0 - 0)^2} = \sqrt{1} = 1.
The total cost is 6.064495102....
Sample Input 2
7 -14142 13562 -17320 50807 -22360 67977 24494 89742 -26457 51311 28284 27124 31622 77660
Sample Output 2
384694.57587932075868509383
Sample Input 3
5 -100000 100000 100000 -100000 -100000 100000 100000 -100000 -100000 100000
Sample Output 3
1414213.56237309504880168872
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 250 点
問題文
注:この問題は F 問題とほぼ同じ設定です。本文中で太字で示されている部分および制約のみが異なります。
あなたはあるリングを両手で握っています。 このリングは N\ (N\geq 3) 個のパーツ 1,2,\dots,N によって構成されており、パーツ i とパーツ i+1 (1\leq i\leq N-1)、およびパーツ 1 とパーツ N がそれぞれ隣接しています。
最初、左手はパーツ 1 を、右手はパーツ 2 を握っています。 あなたは、1 回の 操作 で以下のことを行えます。
- 片方の手を、今握っているパーツに隣接するいずれかのパーツに移動する。ただし、移動先にもう一方の手がない場合に限る。
以下の図は、初期状態およびそこから行える操作と行えない操作の例を示したもので、リングの各パーツに書き込まれた数はそのパーツの番号を、L と書かれた丸は左手を、R と書かれた丸は右手を示しています。

あなたは今から与えられる Q 個の指示に順番に従う必要があります。 i\ (1\leq i\leq Q) 個目の指示は文字 H_i および整数 T_i によって表され、その意味は以下の通りです:
- 操作を何回か(0 回でもよい)行うことで、H_i が
Lならば左手、Rならば右手が、パーツ T_i を握っている状態にする。 このとき、H_i によって指定された手ではない方の手を 動かしてはならない。
なお、達成可能な指示しか与えられないことが保証されます。
詳細
この問題の設定の下では、各 i について、i 個目の指示に従う直前でのそれぞれの手の位置が一意に定まることが証明できます。 このとき、左手の位置をパーツ l_i、右手の位置をパーツ r_i とおくと、H_i=L ならば T_i\neq r_i が、H_i= R ならば T_i\neq l_i がそれぞれ保証されます。
すべての指示に従うために必要な操作回数の合計の最小値を求めてください。
制約
- 3\leq N \leq 100
- 1\leq Q \leq 100
- H_i は
LまたはR - 1\leq T_i\leq N
- N,Q,T_i は整数
- 達成可能な指示しか与えられない(詳細は問題文を参照してください)
入力
入力は以下の形式で標準入力から与えられる。
N Q H_1 T_1 H_2 T_2 \vdots H_Q T_Q
出力
すべての指示に従うために必要な操作回数の合計の最小値を出力せよ。
入力例 1
6 3 R 4 L 5 R 6
出力例 1
8

以下のように操作を行うことで、Q 個の指示すべてに順番に従うことができます。
- 右手をパーツ 2\rightarrow 3\rightarrow 4 と移動させることで、1 番目の指示に従う。
- 左手をパーツ 1\rightarrow 6\rightarrow 5 と移動させることで、2 番目の指示に従う。
- 右手をパーツ 4\rightarrow 3\rightarrow 2\rightarrow 1\rightarrow 6 と移動させることで、3 番目の指示に従う。
このとき行う操作回数の合計は 2+2+4=8 であり、これが最小です。 (3 番目の指示に従う際に右手をパーツ 4\rightarrow 5\rightarrow 6 と移動させることはできないことに注意してください。)
入力例 2
100 2 L 1 R 2
出力例 2
0
操作を 1 度も行わずに指示に従うことができる場合もあります。
入力例 3
30 8 R 23 R 26 R 29 L 20 R 29 R 19 L 7 L 16
出力例 3
92
Score : 250 points
Problem Statement
Note: This problem has almost the same setting as Problem F. Only the parts in bold in the main text and constraints differ.
You are holding a ring with both hands. This ring consists of N\ (N \geq 3) parts numbered 1,2,\dots,N, where parts i and i+1 (1 \leq i \leq N-1) are adjacent, and parts 1 and N are also adjacent.
Initially, your left hand is holding part 1, and your right hand is holding part 2. In one operation, you can do the following:
- Move one of your hands to an adjacent part of the part it is currently holding. However, you can do this only if the other hand is not on the destination part.
The following figure shows the initial state and examples of operations that can and cannot be made from there. The number written on each part of the ring represents the part number, and the circles labeled L and R represent your left and right hands, respectively.

You need to follow Q instructions given to you in order. The i-th (1 \leq i \leq Q) instruction is represented by a character H_i and an integer T_i, meaning the following:
- Perform some number of operations (possibly zero) so that your left hand (if H_i is
L) or your right hand (if H_i isR) is holding part T_i. Here, you must not move the other hand not specified by H_i.
It is guaranteed that only achievable instructions are given.
Details
Under the settings of this problem, it can be proved that the positions of both hands are uniquely determined just before following the i-th instruction for each i. At that time, if we denote the positions of the left and right hands as parts l_i and r_i, respectively, it is guaranteed that T_i \neq r_i when H_i isL, and T_i \neq l_i when H_i is R.
Find the minimum total number of operations required to follow all the instructions.
Constraints
- 3 \leq N \leq 100
- 1 \leq Q \leq 100
- H_i is
LorR. - 1 \leq T_i \leq N
- N, Q, and T_i are integers.
- Only achievable instructions are given (see the problem statement for details).
Input
The Input is given from Standard Input in the following format:
N Q H_1 T_1 H_2 T_2 \vdots H_Q T_Q
Output
Print the minimum total number of operations required to follow all the instructions.
Sample Input 1
6 3 R 4 L 5 R 6
Sample Output 1
8

By performing the following operations, you can follow all Q instructions in order.
- Move your right hand as part 2 \rightarrow 3 \rightarrow 4 to follow the first instruction.
- Move your left hand as part 1 \rightarrow 6 \rightarrow 5 to follow the second instruction.
- Move your right hand as part 4 \rightarrow 3 \rightarrow 2 \rightarrow 1 \rightarrow 6 to follow the third instruction.
In this case, the total number of operations is 2+2+4=8, which is the minimum. (Note that when following the third instruction, you cannot move your right hand as part 4 \rightarrow 5 \rightarrow 6.)
Sample Input 2
100 2 L 1 R 2
Sample Output 2
0
There are cases where you can follow the instructions without performing any operations.
Sample Input 3
30 8 R 23 R 26 R 29 L 20 R 29 R 19 L 7 L 16
Sample Output 3
92
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 300 点
問題文
長さ N の整数列 A=(A_1,A_2,\ldots,A_N) が与えられます。
1\leq i<j<k\leq N をみたす整数の組 (i,j,k) であって、
次の条件をみたすものの個数を求めてください。
A_i,A_j,A_k の中にちょうど 2 種類の値が含まれる。すなわち、A_i,A_j,A_k の中のいずれか 2 つは等しく、残りの 1 つは異なる。
制約
- 3 \leq N \leq 2\times 10^5
- 1 \leq A_i \leq N
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N A_1 A_2 \ldots A_N
出力
条件をみたす整数の組の個数を出力せよ。
入力例 1
5 3 2 5 2 2
出力例 1
6
例えば、(i,j,k)=(1,2,4) は、A_1=3, A_2=2, A_4=2 の中に 2,3 のちょうど 2 種類の値が含まれるため、条件をみたします。
これを含めて、(i,j,k)=(1,2,4),(1,2,5),(1,4,5),(2,3,4),(2,3,5),(3,4,5) の 6 組が条件をみたします。
よって、6 を出力します。
入力例 2
3 1 1 1
出力例 2
0
条件をみたす組が存在しない可能性もあります。
Score : 300 points
Problem Statement
You are given an integer sequence of length N, A=(A_1,A_2,\ldots,A_N).
Find the number of triples of integers (i,j,k) satisfying 1\leq i<j<k\leq N that satisfy the following condition:
Exactly two distinct values are contained in A_i,A_j,A_k. That is, two of A_i,A_j,A_k are equal, and the remaining one is different.
Constraints
- 3 \leq N \leq 2\times 10^5
- 1 \leq A_i \leq N
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N A_1 A_2 \ldots A_N
Output
Print the number of triples of integers that satisfy the condition.
Sample Input 1
5 3 2 5 2 2
Sample Output 1
6
For example, (i,j,k)=(1,2,4) satisfies the condition because exactly two distinct values, 2 and 3, are contained in A_1=3, A_2=2, and A_4=2.
Including this, the six triples (i,j,k)=(1,2,4),(1,2,5),(1,4,5),(2,3,4),(2,3,5),(3,4,5) satisfy the condition.
Therefore, print 6.
Sample Input 2
3 1 1 1
Sample Output 2
0
There may be no triples that satisfy the condition.