実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 100 点
問題文
1 以上 9 以下の数字 A,B,C が与えられます。
A,B,C を好きな順番で並べて繋げることで作れる 3 桁の整数のうち、値が最大のものを求めてください。
制約
- A,B,C は 1 以上 9 以下の数字
入力
入力は以下の形式で標準入力から与えられる。
A B C
出力
答えを出力せよ。
入力例 1
3 2 4
出力例 1
432
A,B,C を好きな順番で並べて繋げることで作れる 3 桁の整数は 324, 342, 234, 243, 432, 423 の 6 通りであり、 このうち値が最大のものは 432 です。
入力例 2
7 7 7
出力例 2
777
777 のみを作ることができます。
入力例 3
9 1 9
出力例 3
991
Score : 100 points
Problem Statement
You are given three digits A,B,C between 1 and 9, inclusive.
Find the maximum value among all 3-digit integers that can be formed by arranging A,B,C in any order and concatenating them.
Constraints
- A,B,C are digits between 1 and 9, inclusive.
Input
The input is given from Standard Input in the following format:
A B C
Output
Output the answer.
Sample Input 1
3 2 4
Sample Output 1
432
There are six 3-digit integers that can be formed by arranging A,B,C in any order and concatenating them: 324, 342, 234, 243, 432, 423; the maximum value among them is 432.
Sample Input 2
7 7 7
Sample Output 2
777
Only 777 can be formed.
Sample Input 3
9 1 9
Sample Output 3
991
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 100 点
問題文
整数 A, B, C が与えられます。A \neq B かつ B = C であるならば Yes を、そうでないならば No を出力してください。
制約
- 1 \leq A, B, C \leq 9
- 入力される値はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
A B C
出力
問題文中の指示に従って Yes, No のいずれかを出力せよ。
入力例 1
4 5 5
出力例 1
Yes
4 \neq 5 かつ 5 = 5 なので Yes を出力します。
入力例 2
1 3 7
出力例 2
No
1 \neq 3 ですが 3 = 7 ではないので No を出力します。
入力例 3
6 6 6
出力例 3
No
Score : 100 points
Problem Statement
You are given integers A, B, C. If A \neq B and B = C, output Yes; otherwise, output No.
Constraints
- 1 \leq A, B, C \leq 9
- All input values are integers.
Input
The input is given from Standard Input in the following format:
A B C
Output
Output Yes or No according to the instructions in the problem statement.
Sample Input 1
4 5 5
Sample Output 1
Yes
Since 4 \neq 5 and 5 = 5, output Yes.
Sample Input 2
1 3 7
Sample Output 2
No
Although 1 \neq 3, we don't have 3 = 7, so output No.
Sample Input 3
6 6 6
Sample Output 3
No
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 200 点
問題文
N 人の人がいます。N 人の人には人 1, 人 2,\dots, 人 N と番号がついています。
人 i(2 \le i \le N) の親は人 P_i です。ここで、P_i < i が保証されます。
人 1 が人 N の何代前か求めてください。
制約
- 2 \le N \le 50
- 1 \le P_i < i(2 \le i \le N)
- 入力は全て整数。
入力
入力は以下の形式で標準入力から与えられる。
N P_2 P_3 \dots P_N
出力
答えを整数として出力せよ。
入力例 1
3 1 2
出力例 1
2
人 2 は人 3 の親であるため、人 3 の 1 代前です。
人 1 は人 2 の親であるため、人 3 の 2 代前です。
よって解は 2 です。
入力例 2
10 1 2 3 4 5 6 7 8 9
出力例 2
9
Score : 200 points
Problem Statement
There are N people, called Person 1, Person 2, \ldots, Person N.
The parent of Person i (2 \le i \le N) is Person P_i. Here, it is guaranteed that P_i < i.
How many generations away from Person N is Person 1?
Constraints
- 2 \le N \le 50
- 1 \le P_i < i(2 \le i \le N)
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N P_2 P_3 \dots P_N
Output
Print the answer as a positive integer.
Sample Input 1
3 1 2
Sample Output 1
2
Person 2 is a parent of Person 3, and thus is one generation away from Person 3.
Person 1 is a parent of Person 2, and thus is two generations away from Person 3.
Therefore, the answer is 2.
Sample Input 2
10 1 2 3 4 5 6 7 8 9
Sample Output 2
9
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 200 点
問題文
駐車場があります。この駐車場に駐車するときの料金は以下の通りです。
- L 時ちょうどから R 時ちょうどまでのあいだは、1 時間停めるごとに X の料金がかかる
- 上に該当しない時間のあいだは、1 時間停めるごとに Y の料金がかかる
この駐車場に、日をまたぐことなく車を A 時ちょうどから B 時ちょうどまで停めたとき、料金はいくらになりますか?
制約
- 1 \leq X, Y \leq 1000
- 1 \leq L < R \leq 23
- 1 \leq A < B \leq 23
- 入力される値はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
X Y L R A B
出力
答えを出力せよ。
入力例 1
700 300 9 17 7 21
出力例 1
7400
車を 7 時から 21 時のあいだ停めたとき、かかる料金は以下のようになります。
- 7 時から 9 時までの 2 時間は 300 \times 2 = 600 の料金がかかる
- 9 時から 17 時までの 8 時間は 700 \times 8 = 5600 の料金がかかる
- 17 時から 21 時までの 4 時間は 300 \times 4 = 1200 の料金がかかる
600 + 5600 + 1200 = 7400 が求める答えです。
入力例 2
600 500 9 17 17 20
出力例 2
1500
車を 17 時から 20 時のあいだ停めたとき、かかる料金は以下のようになります。
- 17 時から 20 時までの 3 時間は 500 \times 3 = 1500 の料金がかかる
1500 が求める答えです。
入力例 3
900 200 12 14 11 13
出力例 3
1100
Score : 200 points
Problem Statement
There is a parking lot. The fee for parking in this lot is as follows:
- During the period from exactly L o'clock to exactly R o'clock, a fee of X is charged for each hour parked.
- During the period not covered above, a fee of Y is charged for each hour parked.
If a car is parked in this lot from exactly A o'clock to exactly B o'clock without crossing midnight, how much is the fee?
Constraints
- 1 \leq X, Y \leq 1000
- 1 \leq L < R \leq 23
- 1 \leq A < B \leq 23
- All input values are integers.
Input
The input is given from Standard Input in the following format:
X Y L R A B
Output
Output the answer.
Sample Input 1
700 300 9 17 7 21
Sample Output 1
7400
If a car is parked from 7 o'clock to 21 o'clock, the fee is as follows.
- For the 2 hours from 7 o'clock to 9 o'clock, a fee of 300 \times 2 = 600 is charged.
- For the 8 hours from 9 o'clock to 17 o'clock, a fee of 700 \times 8 = 5600 is charged.
- For the 4 hours from 17 o'clock to 21 o'clock, a fee of 300 \times 4 = 1200 is charged.
The answer is 600 + 5600 + 1200 = 7400.
Sample Input 2
600 500 9 17 17 20
Sample Output 2
1500
If a car is parked from 17 o'clock to 20 o'clock, the fee is as follows.
- For the 3 hours from 17 o'clock to 20 o'clock, a fee of 500 \times 3 = 1500 is charged.
The answer is 1500.
Sample Input 3
900 200 12 14 11 13
Sample Output 3
1100
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 350 点
問題文
長さ N の整数列 A=(A_1,A_2,\ldots,A_N) が与えられます。
Q 個のクエリが与えられるので順に処理してください。クエリは 2 種類あり、以下のいずれかの形式で与えられます。
1 c: A の先頭の要素を末尾に移動させる操作を c 回行う。2 l r: \displaystyle \sum_{i=l}^r A_i の値を出力する。
制約
- 1\le N\le 2\times 10^5
- 1\le Q\le 2\times 10^5
- 1\le A_i \le 10^9
- 1\le c\le N
- 1\le l\le r \le N
- 2 つ目の形式のクエリが 1 つ以上存在する
- 入力される値は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N Q
A_1 A_2 \ldots A_N
\text{query}_1
\text{query}_2
\vdots
\text{query}_Q
各クエリ \text{query}_i は以下の 2 種類のいずれかの形式で与えられる。
1 c
2 l r
出力
問題文の指示に従って 2 つ目の形式のクエリへの答えを改行区切りで出力せよ。
入力例 1
4 3 3 1 4 5 2 1 3 1 1 2 2 3
出力例 1
8 9
各クエリは以下のように処理されます。
- 1 つ目のクエリ: A_1+A_2+A_3=3+1+4=8 なので 8 を出力します。
- 2 つ目のクエリ: A=(3,1,4,5) が A=(1,4,5,3) に変化します。
- 3 つ目のクエリ: A_2+A_3=4+5=9 なので 9 を出力します。
入力例 2
5 7 1 2 4 8 16 2 1 5 1 4 1 5 2 1 5 2 2 4 1 1 2 3 3
出力例 2
31 31 7 4
Score : 350 points
Problem Statement
You are given an integer sequence A=(A_1,A_2,\ldots,A_N) of length N.
Process Q queries in order. There are two types of queries, given in the following formats:
1 c: Perform the operation of moving the first element of A to the end c times.2 l r: Output the value of \displaystyle \sum_{i=l}^r A_i.
Constraints
- 1\le N\le 2\times 10^5
- 1\le Q\le 2\times 10^5
- 1\le A_i \le 10^9
- 1\le c\le N
- 1\le l\le r \le N
- At least one query of the second type exists.
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N Q
A_1 A_2 \ldots A_N
\text{query}_1
\text{query}_2
\vdots
\text{query}_Q
Each query \text{query}_i is given in one of the following two formats:
1 c
2 l r
Output
Following the instructions in the problem statement, output the answers to the second type queries, separated by newlines.
Sample Input 1
4 3 3 1 4 5 2 1 3 1 1 2 2 3
Sample Output 1
8 9
Each query is processed as follows:
- First query: A_1+A_2+A_3=3+1+4=8, so output 8.
- Second query: A=(3,1,4,5) changes to A=(1,4,5,3).
- Third query: A_2+A_3=4+5=9, so output 9.
Sample Input 2
5 7 1 2 4 8 16 2 1 5 1 4 1 5 2 1 5 2 2 4 1 1 2 3 3
Sample Output 2
31 31 7 4