実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 100 点
問題文
果物屋さんでりんごが売られています。
あなたは次の操作を好きな順で好きなだけ繰り返すことができます。
- X 円を払ってりんごを 1 個手に入れる。
- Y 円を払ってりんごを 3 個手に入れる。
りんごをちょうど N 個手に入れるには最低何円必要ですか?
制約
- 1 \leq X \leq Y \leq 100
- 1 \leq N \leq 100
- 入力される値はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
X Y N
出力
答えを整数として出力せよ。
入力例 1
10 25 10
出力例 1
85
25 円払って 3 個のりんごを手に入れる操作を 3 回繰り返した後、10 円払って 1 個のりんごを手に入れると丁度 10 個のりんごを手に入れられます。このときあなたは 85 円を消費します。
これより少ない金額でちょうど 10 個のりんごを手に入れることはできないので、答えは 85 円になります。
入力例 2
10 40 10
出力例 2
100
10 円払って 1 個のりんごを手に入れる操作を 10 回繰り返すのが最適です。
入力例 3
100 100 2
出力例 3
200
100 円を払って 1 個のりんごを手に入れる操作を 2 回繰り返す以外に ちょうど 2 個のりんごを手に入れる方法はありません。
入力例 4
100 100 100
出力例 4
3400
Score : 100 points
Problem Statement
A fruit store sells apples.
You may perform the following operations as many times as you want in any order:
- Buy one apple for X yen (the currency in Japan).
- Buy three apples for Y yen.
How much yen do you need to pay to obtain exactly N apples?
Constraints
- 1 \leq X \leq Y \leq 100
- 1 \leq N \leq 100
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
X Y N
Output
Print the answer as an integer.
Sample Input 1
10 25 10
Sample Output 1
85
Buy three apples for 25 yen three times and one apple for 10 yen, and you will obtain exactly 10 apples for a total of 85 yen.
You cannot obtain exactly 10 apples for a lower cost, so the answer is 85 yen.
Sample Input 2
10 40 10
Sample Output 2
100
It is optimal to buy an apple for 10 yen 10 times.
Sample Input 3
100 100 2
Sample Output 3
200
The only way to obtain exactly 2 apples is to buy an apple for 100 yen twice.
Sample Input 4
100 100 100
Sample Output 4
3400
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 100 点
問題文
1,2,\ldots,N の番号のついた N 人の人に合計 K 枚のカードを配ります。
人 A から始めて 人 A,A+1,A+2,\ldots,N,1,2,\ldots の順に 1 枚ずつカードを配るとき、最後のカードは誰に配られるでしょうか?
厳密には、人 x(1 \leq x < N) の次には人 x+1 にカードを配り、人 N の次には人 1 にカードを配ります。
制約
- 1 \leq N,K \leq 1000
- 1 \leq A \leq N
- 入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N K A
出力
最後のカードが配られた人の番号を出力せよ。
入力例 1
3 3 2
出力例 1
1
人 2、人 3、人 1 の順にカードを配ります。
入力例 2
1 100 1
出力例 2
1
入力例 3
3 14 2
出力例 3
3
Score : 100 points
Problem Statement
We will hand out a total of K cards to N people numbered 1, 2, \ldots, N.
Beginning with Person A, we will give the cards one by one to the people in this order: A, A+1, A+2, \ldots, N, 1, 2, \ldots. Who will get the last card?
Formally, after Person x(1 \leq x < N) gets a card, Person x+1 will get a card. After Person N gets a card, Person 1 gets a card.
Constraints
- 1 \leq N,K \leq 1000
- 1 \leq A \leq N
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N K A
Output
Print a number representing the person who will get the last card.
Sample Input 1
3 3 2
Sample Output 1
1
The cards are given to Person 2, 3, 1 in this order.
Sample Input 2
1 100 1
Sample Output 2
1
Sample Input 3
3 14 2
Sample Output 3
3
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 200 点
問題文
ナオヒロ君は N+1 個の連続する整数を 1 個ずつ持っていましたが、そのうち 1 個をなくしてしまいました。
残っている N 個の整数が順不同で A_1,\ldots,A_N として与えられるので、なくした整数を求めてください。
なお、なくした整数が一意に定まるような入力のみが与えられます。
制約
- 2 \leq N \leq 100
- 1 \leq A_i \leq 1000
- 入力は全て整数である
- なくした整数は一意に定まる
入力
入力は以下の形式で標準入力から与えられる。
N A_1 A_2 \ldots A_N
出力
答えを出力せよ。
入力例 1
3 2 3 5
出力例 1
4
ナオヒロ君は初め 2,3,4,5 の 4 個の整数を持っており、4 をなくし、2,3,5 が残っていました。
なくした整数である 4 を出力します。
入力例 2
8 3 1 4 5 9 2 6 8
出力例 2
7
入力例 3
16 152 153 154 147 148 149 158 159 160 155 156 157 144 145 146 150
出力例 3
151
Score : 200 points
Problem Statement
Naohiro had N+1 consecutive integers, one of each, but he lost one of them.
The remaining N integers are given in arbitrary order as A_1,\ldots,A_N. Find the lost integer.
The given input guarantees that the lost integer is uniquely determined.
Constraints
- 2 \leq N \leq 100
- 1 \leq A_i \leq 1000
- All input values are integers.
- The lost integer is uniquely determined.
Input
The input is given from Standard Input in the following format:
N A_1 A_2 \ldots A_N
Output
Print the answer.
Sample Input 1
3 2 3 5
Sample Output 1
4
Naohiro originally had four integers, 2,3,4,5, then lost 4, and now has 2,3,5.
Print the lost integer, 4.
Sample Input 2
8 3 1 4 5 9 2 6 8
Sample Output 2
7
Sample Input 3
16 152 153 154 147 148 149 158 159 160 155 156 157 144 145 146 150
Sample Output 3
151
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 200 点
問題文
文字列 S が与えられます。
S の連続する部分文字列のうち、回文であるものの長さの最大値を求めてください。
ただし、S の連続する部分文字列であって回文であるものは常に存在します。
制約
- S は長さ 2 以上 100 以下の英大文字からなる文字列
入力
入力は以下の形式で標準入力から与えられる。
S
出力
答えを出力せよ。
入力例 1
TOYOTA
出力例 1
5
TOYOTA の連続する部分文字列 TOYOT は長さ 5 の回文です。
TOYOTA の唯一の長さ 6 の連続する部分文字列 TOYOTA は回文でないので、5 を出力します。
入力例 2
ABCDEFG
出力例 2
1
すべての長さ 1 の連続する部分文字列は回文です。
入力例 3
AAAAAAAAAA
出力例 3
10
Score : 200 points
Problem Statement
You are given a string S.
Find the maximum length of a contiguous substring of S that is a palindrome.
Note that there is always a contiguous substring of S that is a palindrome.
Constraints
- S is a string of length between 2 and 100, inclusive, consisting of uppercase English letters.
Input
The input is given from Standard Input in the following format:
S
Output
Print the answer.
Sample Input 1
TOYOTA
Sample Output 1
5
TOYOT, a contiguous substring of TOYOTA, is a palindrome of length 5.
TOYOTA, the only length-6 contiguous substring of TOYOTA, is not a palindrome, so print 5.
Sample Input 2
ABCDEFG
Sample Output 2
1
Every contiguous substring of length 1 is a palindrome.
Sample Input 3
AAAAAAAAAA
Sample Output 3
10
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 300 点
問題文
xy 座標平面上の 2 つの格子点 (x_1, y_1), (x_2, y_2) からの距離がともに \sqrt{5} である格子点は存在しますか?
注記
xy 座標平面上にある点のうち、x 座標と y 座標がともに整数である点を格子点と呼びます。
また、xy 平面上の 2 点 (a, b), (c, d) の距離をユークリッド距離 \sqrt{(a - c)^2 + (b-d)^2} として定義します。
参考として、xy 平面の (0, 0) の上に黒丸を、(0, 0) からの距離が \sqrt{5} となる格子点の上に白丸を書いた図は以下のようになります。(x,y いずれかが整数となる部分に目盛り線を引いています。)

制約
- -10^9 \leq x_1 \leq 10^9
- -10^9 \leq y_1 \leq 10^9
- -10^9 \leq x_2 \leq 10^9
- -10^9 \leq y_2 \leq 10^9
- (x_1, y_1) \neq (x_2, y_2)
- 入力はすべて整数である。
入力
入力は以下の形式で標準入力から与えられる。
x_1 y_1 x_2 y_2
出力
条件を満たす格子点が存在する場合は Yes を、存在しない場合は No を出力せよ。
入力例 1
0 0 3 3
出力例 1
Yes
- 点 (2,1) と (x_1, y_1) の距離は \sqrt{(0-2)^2 + (0-1)^2} = \sqrt{5}
- 点 (2,1) と (x_2, y_2) の距離は \sqrt{(3-2)^2 + (3-1)^2} = \sqrt{5}
- 点 (2, 1) は格子点
なので点 (2, 1) は条件を満たします。よって Yes を出力します。
なお、点 (1, 2) も条件を満たすことが同様にして確認できます。
入力例 2
0 1 2 3
出力例 2
No
条件を満たす格子点は存在しません。よって No を出力します。
入力例 3
1000000000 1000000000 999999999 999999999
出力例 3
Yes
点 (10^9 + 1, 10^9 - 2) および点 (10^9 - 2, 10^9 + 1)が条件を満たします。
Score : 300 points
Problem Statement
On an xy-coordinate plane, is there a lattice point whose distances from two lattice points (x_1, y_1) and (x_2, y_2) are both \sqrt{5}?
Notes
A point on an xy-coordinate plane whose x and y coordinates are both integers is called a lattice point.
The distance between two points (a, b) and (c, d) is defined to be the Euclidean distance between them, \sqrt{(a - c)^2 + (b-d)^2}.
The following figure illustrates an xy-plane with a black circle at (0, 0) and white circles at the lattice points whose distances from (0, 0) are \sqrt{5}. (The grid shows where either x or y is an integer.)

Constraints
- -10^9 \leq x_1 \leq 10^9
- -10^9 \leq y_1 \leq 10^9
- -10^9 \leq x_2 \leq 10^9
- -10^9 \leq y_2 \leq 10^9
- (x_1, y_1) \neq (x_2, y_2)
- 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
Output
If there is a lattice point satisfying the condition, print Yes; otherwise, print No.
Sample Input 1
0 0 3 3
Sample Output 1
Yes
- The distance between points (2,1) and (x_1, y_1) is \sqrt{(0-2)^2 + (0-1)^2} = \sqrt{5};
- the distance between points (2,1) and (x_2, y_2) is \sqrt{(3-2)^2 + (3-1)^2} = \sqrt{5};
- point (2, 1) is a lattice point,
so point (2, 1) satisfies the condition. Thus, Yes should be printed.
One can also assert in the same way that (1, 2) also satisfies the condition.
Sample Input 2
0 1 2 3
Sample Output 2
No
No lattice point satisfies the condition, so No should be printed.
Sample Input 3
1000000000 1000000000 999999999 999999999
Sample Output 3
Yes
Point (10^9 + 1, 10^9 - 2) and point (10^9 - 2, 10^9 + 1) satisfy the condition.