Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 100 点
問題文
整数 R,C と 2 行 2 列からなる行列 A が与えられるので、 A_{R,C} を出力してください。
制約
- 入力は全て整数
- 1 \le R,C \le 2
- 0 \le A_{i,j} \le 100
入力
入力は以下の形式で標準入力から与えられる。
R C
A_{1,1} A_{1,2}
A_{2,1} A_{2,2}
出力
答えを整数として出力せよ。
入力例 1
1 2 1 0 0 1
出力例 1
0
A_{1,2}=0 です。
入力例 2
2 2 1 2 3 4
出力例 2
4
A_{2,2}=4 です。
入力例 3
2 1 90 80 70 60
出力例 3
70
A_{2,1}=70 です。
Score : 100 points
Problem Statement
Given integers R, C, and a 2 \times 2 matrix A, print A_{R,C}.
Constraints
- All values in input are integers.
- 1 \le R,C \le 2
- 0 \le A_{i,j} \le 100
Input
Input is given from Standard Input in the following format:
R C
A_{1,1} A_{1,2}
A_{2,1} A_{2,2}
Output
Print the answer as an integer.
Sample Input 1
1 2 1 0 0 1
Sample Output 1
0
We have A_{1,2}=0.
Sample Input 2
2 2 1 2 3 4
Sample Output 2
4
We have A_{2,2}=4.
Sample Input 3
2 1 90 80 70 60
Sample Output 3
70
We have A_{2,1}=70.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 100 点
問題文
小数第三位までで表すことのできる実数 X が、小数第三位まで入力されます。
X を小数第一位で四捨五入した結果として得られる整数を出力してください。
制約
- 0 \leq X < 100
- X は小数第三位までで表現可能である。
- X は小数第三位まで与えられる。
入力
入力は以下の形式で標準入力から与えられる。
X
出力
X を小数第一位で四捨五入して得られる整数を出力せよ。
入力例 1
3.456
出力例 1
3
3.456 の小数第一位は 4 であるので、3.456 を小数第一位で四捨五入した値は 3 となります。
入力例 2
99.500
出力例 2
100
入力例 3
0.000
出力例 3
0
Score : 100 points
Problem Statement
You are given a real number X, which is representable using at most three decimal digits, with three decimal digits.
Round X to the nearest integer and print the result.
Constraints
- 0 \leq X < 100
- X is representable using at most three decimal digits.
- X has three decimal digits in input.
Input
Input is given from Standard Input in the following format:
X
Output
Print the integer resulting from rounding X to the nearest integer.
Sample Input 1
3.456
Sample Output 1
3
The digit in the first decimal place of 3.456 is 4, so we should round it down to 3.
Sample Input 2
99.500
Sample Output 2
100
Sample Input 3
0.000
Sample Output 3
0
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
以下の手順で行われる試験があります。
- 試験は 1 ラウンド目から N ラウンド目までの N ラウンドからなる。
- 各ラウンドに対し、 0 以上 100 以下の整数でスコアが与えられる。
- N ラウンドのスコアのうち、最高スコアと最低スコアを除いた N-2 ラウンドのスコアの合計が最終結果となる。
- 厳密には、各ラウンドのスコアを昇順に並べた列を S=(S_1,S_2,\dots,S_N) としたとき、最終結果は S_2+S_3+\dots+S_{N-1} となる。
現在、試験のうち N-1 ラウンドが終了し、 i ラウンド目のスコアは A_i でした。
最終結果を X 以上とするために N ラウンド目に取るべきスコアの最小値を出力してください。
但し、 N ラウンド目にどのようなスコアを取っても最終結果が X 以上にならない場合、代わりに -1 と出力してください。
なお、 N ラウンド目に取りうるスコアは 0 以上 100 以下の整数であることに注意してください。
制約
- 入力は全て整数
- 3 \le N \le 100
- 0 \le X \le 100 \times (N-2)
- 0 \le A_i \le 100
入力
入力は以下の形式で標準入力から与えられる。
N X
A_1 A_2 \dots A_{N-1}
出力
答えを出力せよ。
入力例 1
5 180 40 60 80 50
出力例 1
70
4 ラウンド目までのスコアは 40,60,80,50 でした。
5 ラウンド目にスコア 70 を取ると、スコアを昇順に並べた列は S=(40,50,60,70,80) となり、最終結果は 50+60+70=180 となります。
なお、最終結果を 180 以上にするために取るべきスコアの最小値が 70 であることが示せます。
入力例 2
3 100 100 100
出力例 2
0
2 ラウンド目までのスコアは 100,100 でした。
3 ラウンド目にスコア 0 を取ると、スコアを昇順に並べた列は S=(0,100,100) となり、最終結果は 100 となります。
最大スコアである 100 が複数ありますが、そのうち 1 つしか除かれないことに注意してください。(最小スコアについても同様です)
なお、最終結果を 100 以上にするために取るべきスコアの最小値が 0 であることが示せます。
入力例 3
5 200 0 0 99 99
出力例 3
-1
4 ラウンド目までのスコアは 0,0,99,99 でした。
5 ラウンド目にどのようなスコアを取っても、最終結果を 200 以上にすることができないことが示せます。
入力例 4
10 480 59 98 88 54 70 24 8 94 46
出力例 4
45
Score : 200 points
Problem Statement
There is an exam structured as follows.
- The exam consists of N rounds called round 1 to N.
- In each round, you are given an integer score between 0 and 100, inclusive.
- Your final grade is the sum of the N-2 of the scores earned in the rounds excluding the highest and lowest.
- Formally, let S=(S_1,S_2,\dots,S_N) be the sequence of the scores earned in the rounds sorted in ascending order, then the final grade is S_2+S_3+\dots+S_{N-1}.
Now, N-1 rounds of the exam have ended, and your score in round i was A_i.
Print the minimum score you must earn in round N for a final grade of X or higher.
If your final grade will never be X or higher no matter what score you earn in round N, print -1 instead.
Note that your score in round N can only be an integer between 0 and 100.
Constraints
- All input values are integers.
- 3 \le N \le 100
- 0 \le X \le 100 \times (N-2)
- 0 \le A_i \le 100
Input
The input is given from Standard Input in the following format:
N X
A_1 A_2 \dots A_{N-1}
Output
Print the answer.
Sample Input 1
5 180 40 60 80 50
Sample Output 1
70
Your scores in the first four rounds were 40, 60, 80, and 50.
If you earn a score of 70 in round 5, the sequence of the scores sorted in ascending order will be S=(40,50,60,70,80), for a final grade of 50+60+70=180.
It can be shown that 70 is the minimum score you must earn for a final grade of 180 or higher.
Sample Input 2
3 100 100 100
Sample Output 2
0
Your scores in the first two rounds were 100 and 100.
If you earn a score of 0 in round 3, the sequence of the scores sorted in ascending order will be S=(0,100,100), for a final grade of 100.
Note that the highest score, 100, is earned multiple times, and only one of them is excluded. (The same goes for the lowest score.)
It can be shown that 0 is the minimum score you must earn for a final grade of 100 or higher.
Sample Input 3
5 200 0 0 99 99
Sample Output 3
-1
Your scores in the first four rounds were 0, 0, 99, and 99.
It can be shown that your final grade will never be 200 or higher no matter what score you earn in round 5.
Sample Input 4
10 480 59 98 88 54 70 24 8 94 46
Sample Output 4
45
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
人 1 、人 2 、\ldots 、人 N と番号をつけられた N 人の人がいます。
N 人は、人 1 、人 2 、\ldots 、人 N の順番に下記の行動をちょうど 1 回ずつ行います。
- 人 i 自身がまだ一度も番号を呼ばれていないなら、人 A_i の番号を呼ぶ。
最後まで番号を一度も呼ばれない人全員の番号を昇順に列挙してください。
制約
- 2 \leq N \leq 2 \times 10^5
- 1 \leq A_i \leq N
- A_i \neq i
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N A_1 A_2 \ldots A_N
出力
下記の形式にしたがって、最後まで番号を一度も呼ばれない人全員の番号を昇順に列挙せよ。
K X_1 X_2 \ldots X_K
すなわち、まず 1 行目に、最後まで番号を一度も呼ばれない人の人数 K を出力し、 2 行目に、最後まで番号を一度も呼ばれない人全員の番号を昇順に並べた列 (X_1, X_2, \ldots, X_K) を空白区切りで出力せよ。
入力例 1
5 3 1 4 5 4
出力例 1
2 2 4
5 人の行動は下記の通りです。
- 人 1 はまだ番号を一度も呼ばれていないので、人 1 は人 3 の番号を呼びます。
- 人 2 はまだ番号を一度も呼ばれていないので、人 2 は人 1 の番号を呼びます。
- 人 3 はすでに人 1 によって番号を呼ばれているので、何もしません。
- 人 4 はまだ番号を一度も呼ばれていないので、人 4 は人 5 の番号を呼びます。
- 人 5 はすでに人 4 によって番号を呼ばれているので、何もしません。
よって、最後まで番号を一度も呼ばれないのは人 2 と人 4 です。
入力例 2
20 9 7 19 7 10 4 13 9 4 8 10 15 16 3 18 19 12 13 2 12
出力例 2
10 1 2 5 6 8 11 14 17 18 20
Score : 200 points
Problem Statement
There are N people whose IDs are 1, 2, \ldots, and N.
Each of person 1, person 2, \ldots, and person N performs the following action once in this order:
- If person i's ID has not been called out yet, call out person A_i's ID.
Enumerate the IDs of all the people whose IDs are never called out until the end in ascending order.
Constraints
- 2 \leq N \leq 2 \times 10^5
- 1 \leq A_i \leq N
- A_i \neq i
- All values in the input are integers.
Input
The input is given from Standard Input in the following format:
N A_1 A_2 \ldots A_N
Output
Enumerate the IDs of all the people whose IDs are not called out until the end in ascending order in the following format:
K X_1 X_2 \ldots X_K
In other words, the first line should contain the number of people, K, whose IDs are never called out until the end; the second line should contain the sequence (X_1, X_2, \ldots, X_K) of IDs of such people in ascending order, with spaces in between.
Sample Input 1
5 3 1 4 5 4
Sample Output 1
2 2 4
The five people's actions are as follows.
- Person 1's ID has not been called out yet, so person 1 calls out person 3's ID.
- Person 2's ID has not been called out yet, so person 2 calls out person 1's ID.
- Person 3's ID has already been called out by person 1, so nothing happens.
- Person 4's ID has not been called out yet, so person 4 calls out person 5's ID.
- Person 5's ID has already been called out by person 4, so nothing happens.
Therefore, person 2 and 4's IDs are not called out until the end.
Sample Input 2
20 9 7 19 7 10 4 13 9 4 8 10 15 16 3 18 19 12 13 2 12
Sample Output 2
10 1 2 5 6 8 11 14 17 18 20
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
ボールがいくつか刺さった棒が N 本あり、各ボールには英小文字が 1 個書かれています。
i = 1, 2, \ldots, N について、i 番目の棒に刺さった各ボールの英小文字は、文字列 S_i によって表されます。 具体的には、i 番目の棒には文字列 S_i の長さ |S_i| に等しい個数のボールが刺さっており、 刺さっているボールの英小文字を、棒のある端から順に並べたものは文字列 S_i と等しいです。
2 つの棒は、一方の棒に刺さっているボールの英小文字をどちらかの端から並べた列と、もう一方の棒に刺さっているボールの英小文字をどちらかの端から並べた列が一致するとき、同じ棒とみなされます。 より形式的には、1 以上 N 以下の整数 i, j について、i 本目の棒と j 本目の棒は、S_i が S_j と一致するか、S_i が S_j を前後反転したものと一致するとき、かつそのときに限り、同じとみなされます。
N 本の棒の中に、何種類の異なる棒があるかを出力してください。
制約
- N は整数
- 2 \leq N \leq 2 \times 10^5
- S_i は英小文字のみからなる文字列
- |S_i| \geq 1
- \sum_{i = 1}^N |S_i| \leq 2 \times 10^5
入力
入力は以下の形式で標準入力から与えられる。
N S_1 S_2 \vdots S_N
出力
答えを出力せよ。
入力例 1
6 a abc de cba de abc
出力例 1
3
- S_2 =
abcが S_4 =cbaを前後反転したものと一致するため、2 番目の棒と 4 番目の棒は同じとみなされます。 - S_2 =
abcが S_6 =abcと一致するため、2 番目の棒と 6 番目の棒は同じとみなされます。 - S_3 =
deが S_5 =deと一致するため、3 番目の棒と 5 番目の棒は同じとみなされます。
よって、6 本の棒の中に、1 本目の棒、2 本目の棒( 4, 6 本目の棒と同じ)、3 本目の棒( 5 本目の棒と同じ)の 3 種類の異なる棒があります。
Score : 300 points
Problem Statement
There are N sticks with several balls stuck onto them. Each ball has a lowercase English letter written on it.
For each i = 1, 2, \ldots, N, the letters written on the balls stuck onto the i-th stick are represented by a string S_i. Specifically, the number of balls stuck onto the i-th stick is the length |S_i| of the string S_i, and S_i is the sequence of letters on the balls starting from one end of the stick.
Two sticks are considered the same when the sequence of letters on the balls starting from one end of one stick is equal to the sequence of letters starting from one end of the other stick. More formally, for integers i and j between 1 and N, inclusive, the i-th and j-th sticks are considered the same if and only if S_i equals S_j or its reversal.
Print the number of different sticks among the N sticks.
Constraints
- N is an integer.
- 2 \leq N \leq 2 \times 10^5
- S_i is a string consisting of lowercase English letters.
- |S_i| \geq 1
- \sum_{i = 1}^N |S_i| \leq 2 \times 10^5
Input
The input is given from Standard Input in the following format:
N S_1 S_2 \vdots S_N
Output
Print the answer.
Sample Input 1
6 a abc de cba de abc
Sample Output 1
3
- S_2 =
abcequals the reversal of S_4 =cba, so the second and fourth sticks are considered the same. - S_2 =
abcequals S_6 =abc, so the second and sixth sticks are considered the same. - S_3 =
deequals S_5 =de, so the third and fifth sticks are considered the same.
Therefore, there are three different sticks among the six: the first, second (same as the fourth and sixth), and third (same as the fifth).