Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 100 点
問題文
キーエンスでは、役割や年齢、立場の違いに関係なく「さん」付けして呼ぶという文化があります。 新入社員が社長を呼ぶときも「中田さん」と呼びます。
ある人の苗字と名前がそれぞれ文字列 S,T として与えられます。
苗字、スペース( )、敬称(san)をこの順に連結した文字列を出力してください。
制約
- S,T は以下の各条件を満たす文字列
- 長さ 1 以上 10 以下
- 先頭の文字は英大文字
- 先頭以外の文字は英小文字
入力
入力は以下の形式で標準入力から与えられる。
S T
出力
苗字、スペース( )、敬称(san)をこの順に連結した文字列を出力せよ。
入力例 1
Takahashi Chokudai
出力例 1
Takahashi san
苗字(Takahashi)、スペース( )、敬称(san)をこの順に連結した文字列を出力します。
入力例 2
K Eyence
出力例 2
K san
Score : 100 points
Problem Statement
Keyence has a culture of addressing everyone with the honorific "san," regardless of their role, age, or position. Even a new employee would call the president "Nakata-san." [Translator's note: this is a bit unusual in Japan.]
You are given a person's surname and first name as strings S and T, respectively.
Print the concatenation of the surname, a space ( ), and the honorific (san) in this order.
Constraints
- Each of S and T is a string that satisfies the following conditions.
- The length is between 1 and 10, inclusive.
- The first character is an uppercase English letter.
- All characters except the first one are lowercase English letters.
Input
The input is given from Standard Input in the following format:
S T
Output
Print the concatenation of the surname, a space ( ), and the honorific (san) in this order.
Sample Input 1
Takahashi Chokudai
Sample Output 1
Takahashi san
Print the concatenation of the surname (Takahashi), a space ( ), and the honorific (san) in this order.
Sample Input 2
K Eyence
Sample Output 2
K san
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 100 点
問題文
高橋君は、レストランで「AtCoder ドリンク」というドリンクを飲もうとしています。 AtCoder ドリンクは定価である P 円を払えば飲むことができます。
また、高橋君は割引券を持っており、それを使うと AtCoder ドリンクを定価より安い価格である Q 円で飲むことができますが、 その場合には AtCoder ドリンクの他に、N 品ある料理の中から 1 つを追加で注文しなければなりません。 i = 1, 2, \ldots, N について、i 番目の料理の価格は D_i 円です。
高橋君がドリンクを飲むため支払う合計金額の最小値を出力してください。
制約
- 1 \leq N \leq 100
- 1 \leq Q \lt P \leq 10^5
- 1 \leq D_i \leq 10^5
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N P Q D_1 D_2 \ldots D_N
出力
答えを出力せよ。
入力例 1
3 100 50 60 20 40
出力例 1
70
割引券を使用して 2 番目の料理を注文することで、ドリンク代 50 円と料理代 20 円の合計 70 円の支払いで AtCoder ドリンクを飲むことができ、支払う合計金額が最小となります。
入力例 2
3 100 50 60000 20000 40000
出力例 2
100
割引券を使用せず定価の 100 円で AtCoder ドリンクを飲むことで、支払う合計金額が最小となります。
Score : 100 points
Problem Statement
Takahashi wants a beverage called AtCoder Drink in a restaurant. It can be ordered at a regular price of P yen.
He also has a discount coupon that allows him to order it at a lower price of Q yen. However, he must additionally order one of the restaurant's N dishes to use that coupon. For each i = 1, 2, \ldots, N, the price of the i-th dish is D_i yen.
Print the minimum total amount of money that he must pay to get the drink.
Constraints
- 1 \leq N \leq 100
- 1 \leq Q \lt P \leq 10^5
- 1 \leq D_i \leq 10^5
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N P Q D_1 D_2 \ldots D_N
Output
Print the answer.
Sample Input 1
3 100 50 60 20 40
Sample Output 1
70
If he uses the coupon and orders the second dish, he can get the drink by paying 50 yen for it and 20 yen for the dish, for a total of 70 yen, which is the minimum total payment needed.
Sample Input 2
3 100 50 60000 20000 40000
Sample Output 2
100
The total payment will be minimized by not using the coupon and paying the regular price of 100 yen.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
チェス盤のどこにコマが置かれているか答えてください。
縦 8 マス、横 8 マスのグリッドがあります。グリッドの各マスには、次のルールで定められる長さ 2 の文字列の名前がついています。
- 左から 1 列目にあるマスの名前の 1 文字目は
aである。同様に、左から 2,3,\ldots,8 列目にあるマスの名前の 1 文字目はb,c,d,e,f,g,hである。 - 下から 1 行目にあるマスの名前の 2 文字目は
1である。同様に、下から 2,3,\ldots,8 行目にあるマスの名前の 2 文字目は2,3,4,5,6,7,8である。
例えば、グリッドの左下のマスの名前は a1、右下のマスの名前は h1、右上のマスの名前は h8 です。
グリッドの状態を表す長さ 8 の 8 つの文字列 S_1,\ldots,S_8 が与えられます。
S_i の j 文字目は、グリッドの上から i 行目 左から j 列目のマスにコマが置かれているとき *、置かれていないとき . であり、S_1,\ldots,S_8 の中に文字 * はちょうど 1 つ存在します。
コマが置かれているマスの名前を求めてください。
制約
- S_i は
.および*のみからなる長さ 8 の文字列である - S_1,\ldots,S_8 の中に文字
*はちょうど 1 つ存在する。
入力
入力は以下の形式で標準入力から与えられる。
S_1 S_2 S_3 S_4 S_5 S_6 S_7 S_8
出力
答えを出力せよ。
入力例 1
........ ........ ........ ........ ........ ........ ........ *.......
出力例 1
a1
問題文中で説明したとおり、グリッドの左下のマスの名前は a1 です。
入力例 2
........ ........ ........ ........ ........ .*...... ........ ........
出力例 2
b3
Score : 200 points
Problem Statement
Locate a piece on a chessboard.
We have a grid with 8 rows and 8 columns of squares. Each of the squares has a 2-character name determined as follows.
- The first character of the name of a square in the 1-st column from the left is
a. Similarly, the first character of the name of a square in the 2-nd, 3-rd, \ldots, 8-th column from the left isb,c,d,e,f,g,h, respectively. - The second character of the name of a square in the 1-st row from the bottom is
1. Similarly, the second character of the name of a square in the 2-nd, 3-rd, \ldots, 8-th row from the bottom is2,3,4,5,6,7,8, respectively.
For instance, the bottom-left square is named a1, the bottom-right square is named h1, and the top-right square is named h8.
You are given 8 strings S_1,\ldots,S_8, each of length 8, representing the state of the grid.
The j-th character of S_i is * if the square at the i-th row from the top and j-th column from the left has a piece on it, and . otherwise.
The character * occurs exactly once among S_1,\ldots,S_8.
Find the name of the square that has a piece on it.
Constraints
- S_i is a string of length 8 consisting of
.and*. - The character
*occurs exactly once among S_1,\ldots,S_8.
Input
The input is given from Standard Input in the following format:
S_1 S_2 S_3 S_4 S_5 S_6 S_7 S_8
Output
Print the answer.
Sample Input 1
........ ........ ........ ........ ........ ........ ........ *.......
Sample Output 1
a1
As explained in the problem statement, the bottom-left square is named a1.
Sample Input 2
........ ........ ........ ........ ........ .*...... ........ ........
Sample Output 2
b3
Time Limit: 2 sec / Memory Limit: 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
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
1 以上 N 以下の整数からなる長さ N の数列 a = (a_1, \dots, a_N) が与えられます。
以下の条件を全て満たす整数 i, j の組の総数を求めてください。
- 1 \leq i \lt j \leq N
- \min(a_i, a_j) = i
- \max(a_i, a_j) = j
制約
- 2 \leq N \leq 5 \times 10^5
- 1 \leq a_i \leq N \, (1 \leq i \leq N)
- 入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N a_1 \ldots a_N
出力
答えを出力せよ。
入力例 1
4 1 3 2 4
出力例 1
2
(i, j) = (1, 4), (2, 3) が条件を満たします。
入力例 2
10 5 8 2 2 1 6 7 2 9 10
出力例 2
8
Score : 300 points
Problem Statement
You are given a sequence a = (a_1, \dots, a_N) of length N consisting of integers between 1 and N.
Find the number of pairs of integers i, j that satisfy all of the following conditions:
- 1 \leq i \lt j \leq N
- \min(a_i, a_j) = i
- \max(a_i, a_j) = j
Constraints
- 2 \leq N \leq 5 \times 10^5
- 1 \leq a_i \leq N \, (1 \leq i \leq N)
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N a_1 \ldots a_N
Output
Print the answer.
Sample Input 1
4 1 3 2 4
Sample Output 1
2
(i, j) = (1, 4), (2, 3) satisfy the conditions.
Sample Input 2
10 5 8 2 2 1 6 7 2 9 10
Sample Output 2
8