Time Limit: 2 sec / Memory Limit: 1024 MB
配点 : 100 点
問題文
与えられる 5 つの整数 A, B, C, D, E の中に何種類の整数があるかを出力してください。
制約
- 0 \leq A, B, C, D, E \leq 100
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
A B C D E
出力
答えを出力せよ。
入力例 1
31 9 24 31 24
出力例 1
3
与えられる 5 つの整数 31, 9, 24, 31, 24 の中には、9, 24, 31 という 3 種類の整数があります。 よって、3 を出力します。
入力例 2
0 0 0 0 0
出力例 2
1
Score : 100 points
Problem Statement
Print how many distinct integers there are in given five integers A, B, C, D, and E.
Constraints
- 0 \leq A, B, C, D, E \leq 100
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
A B C D E
Output
Print the answer.
Sample Input 1
31 9 24 31 24
Sample Output 1
3
In the given five integers 31, 9, 24, 31, and 24, there are three distinct integers 9, 24, and 31. Thus, 3 should be printed.
Sample Input 2
0 0 0 0 0
Sample Output 2
1
Time Limit: 2 sec / Memory Limit: 1024 MB
配点 : 100 点
問題文
以下の条件を満たす正整数 x を 321-like Number と呼びます。
- x の各桁を上から見ると狭義単調減少になっている。
- すなわち、x が d 桁の整数だとすると、 1 \le i < d を満たす全ての整数 i について以下の条件を満たす。
- ( x の上から i 桁目 ) > ( x の上から i+1 桁目 )
なお、 1 桁の正整数は必ず 321-like Number であることに注意してください。
例えば、 321,96410,1 は 321-like Number ですが、 123,2109,86411 は 321-like Number ではありません。
N が入力として与えられるので、 N が 321-like Number なら Yes
、そうでないなら No
と出力してください。
制約
- 入力は全て整数
- 1 \le N \le 99999
入力
入力は以下の形式で標準入力から与えられる。
N
出力
N が 321-like Number なら Yes
、そうでないなら No
と出力せよ。
入力例 1
321
出力例 1
Yes
N=321 に対して、以下が成り立ちます。
- 上から 1 桁目の 3 は上から 2 桁目の 2 より大きい。
- 上から 2 桁目の 2 は上から 3 桁目の 1 より大きい。
以上より、 321 は 321-like Number です。
入力例 2
123
出力例 2
No
N=123 について、例えば以下が成り立ちます。
- 上から 1 桁目の 1 は上から 2 桁目の 2 より大きくない。
このことから、 123 は 321-like Number ではありません。
入力例 3
1
出力例 3
Yes
入力例 4
86411
出力例 4
No
Score : 100 points
Problem Statement
A positive integer x is called a 321-like Number when it satisfies the following condition.
- The digits of x are strictly decreasing from top to bottom.
- In other words, if x has d digits, it satisfies the following for every integer i such that 1 \le i < d:
- (the i-th digit from the top of x) > (the (i+1)-th digit from the top of x).
Note that all one-digit positive integers are 321-like Numbers.
For example, 321, 96410, and 1 are 321-like Numbers, but 123, 2109, and 86411 are not.
You are given N as input. Print Yes
if N is a 321-like Number, and No
otherwise.
Constraints
- All input values are integers.
- 1 \le N \le 99999
Input
The input is given from Standard Input in the following format:
N
Output
Print Yes
if N is a 321-like Number, and No
otherwise.
Sample Input 1
321
Sample Output 1
Yes
For N=321, the following holds:
- The first digit from the top, 3, is greater than the second digit from the top, 2.
- The second digit from the top, 2, is greater than the third digit from the top, 1.
Thus, 321 is a 321-like Number.
Sample Input 2
123
Sample Output 2
No
For N=123, the following holds:
- The first digit from the top, 1, is not greater than the second digit from the top, 2.
Thus, 123 is not a 321-like Number.
Sample Input 3
1
Sample Output 3
Yes
Sample Input 4
86411
Sample Output 4
No
Time Limit: 2 sec / Memory Limit: 1024 MB
配点 : 200 点
問題文
1 から N までの番号がついた N 人の人がいます。
N 人の人の今後 D 日間の予定が与えられます。人 i の予定は長さ D の文字列 S_i で表されて、S_i の j 文字目が o
ならば j 日目は暇であることを、x
ならばそうでないことを意味します。
D 日間のうち全員が暇であるような 連続する 何日かを選ぶことを考えます。
選べる日数は最大で何日ですか?ただし、選べる日が存在しない場合は 0 日と答えてください。
制約
- 1 \leq N \leq 100
- 1 \leq D \leq 100
- N, D は整数
- S_i は
o
とx
からなる長さ D の文字列
入力
入力は以下の形式で標準入力から与えられる。
N D S_1 S_2 \vdots S_N
出力
選べる日数の最大値を出力せよ。選べる日が存在しない場合は 0
を出力せよ。
入力例 1
3 5 xooox oooxx oooxo
出力例 1
2
2 日目と 3 日目は全員が暇な日なので選ぶことができます。
この 2 日間を選ぶと、連続する日にちを選ぶ方法の中で日数を最大にすることができます。
入力例 2
3 3 oxo oxo oxo
出力例 2
1
選ぶ日にちは連続している必要があるのに注意してください。(1 日目と 3 日目は全員が暇な日なので選ぶことができますが、この 2 つを同時に選ぶことはできません)
入力例 3
3 3 oox oxo xoo
出力例 3
0
選べる日が存在しない場合は 0
を出力してください。
入力例 4
1 7 ooooooo
出力例 4
7
入力例 5
5 15 oxooooooooooooo oxooxooooooooox oxoooooooooooox oxxxooooooxooox oxooooooooxooox
出力例 5
5
Score : 200 points
Problem Statement
There are N people numbered 1 to N.
You are given their schedule for the following D days. The schedule for person i is represented by a string S_i of length D. If the j-th character of S_i is o
, person i is free on the j-th day; if it is x
, they are occupied that day.
From these D days, consider choosing some consecutive days when all the people are free.
How many days can be chosen at most? If no day can be chosen, report 0.
Constraints
- 1 \leq N \leq 100
- 1 \leq D \leq 100
- N and D are integers.
- S_i is a string of length D consisting of
o
andx
.
Input
The input is given from Standard Input in the following format:
N D S_1 S_2 \vdots S_N
Output
Print the maximum number of days that can be chosen, or 0
if no day can be chosen.
Sample Input 1
3 5 xooox oooxx oooxo
Sample Output 1
2
All the people are free on the second and third days, so we can choose them.
Choosing these two days will maximize the number of days among all possible choices.
Sample Input 2
3 3 oxo oxo oxo
Sample Output 2
1
Note that the chosen days must be consecutive. (All the people are free on the first and third days, so we can choose either of them, but not both.)
Sample Input 3
3 3 oox oxo xoo
Sample Output 3
0
Print 0
if no day can be chosen.
Sample Input 4
1 7 ooooooo
Sample Output 4
7
Sample Input 5
5 15 oxooooooooooooo oxooxooooooooox oxoooooooooooox oxxxooooooxooox oxooooooooxooox
Sample Output 5
5
Time Limit: 2 sec / Memory Limit: 1024 MB
配点 : 200 点
問題文
整数 1, 2, \dots, N が書かれたカードが 4 枚ずつ、合計 4N 枚あります。
高橋君は、これらのカードをシャッフルしたのち 1 枚のカードを選んで抜き取り、残りの 4N - 1 枚を束にしてあなたに渡しました。渡された束の i \, (1 \leq i \leq 4N - 1) 枚目のカードには、整数 A_i が書かれています。
高橋君が抜き取ったカードに書かれていた整数を求めてください。
制約
- 1 \leq N \leq 10^5
- 1 \leq A_i \leq N \, (1 \leq i \leq 4N - 1)
- 各 k \, (1 \leq k \leq N) に対し、A_i = k となる i は 4 個以下である。
- 入力は全て整数である。
入力
入力は以下の形式で標準入力から与えられる。
N A_1 A_2 \ldots A_{4N - 1}
出力
答えを出力せよ。
入力例 1
3 1 3 2 3 3 2 2 1 1 1 2
出力例 1
3
高橋君が抜き取ったカードには 3 が書かれています。
入力例 2
1 1 1 1
出力例 2
1
入力例 3
4 3 2 1 1 2 4 4 4 4 3 1 3 2 1 3
出力例 3
2
Score : 200 points
Problem Statement
We have 4 cards with an integer 1 written on it, 4 cards with 2, \ldots, 4 cards with N, for a total of 4N cards.
Takahashi shuffled these cards, removed one of them, and gave you a pile of the remaining 4N-1 cards. The i-th card (1 \leq i \leq 4N - 1) of the pile has an integer A_i written on it.
Find the integer written on the card removed by Takahashi.
Constraints
- 1 \leq N \leq 10^5
- 1 \leq A_i \leq N \, (1 \leq i \leq 4N - 1)
- For each k \, (1 \leq k \leq N), there are at most 4 indices i such that A_i = k.
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N A_1 A_2 \ldots A_{4N - 1}
Output
Print the answer.
Sample Input 1
3 1 3 2 3 3 2 2 1 1 1 2
Sample Output 1
3
Takahashi removed a card with 3 written on it.
Sample Input 2
1 1 1 1
Sample Output 2
1
Sample Input 3
4 3 2 1 1 2 4 4 4 4 3 1 3 2 1 3
Sample Output 3
2
Time Limit: 2 sec / Memory Limit: 1024 MB
配点 : 300 点
問題文
冷蔵庫に N 種類の材料があります。これらを材料 1、\dots、材料 N と呼びます。材料 i は Q_i グラムあります。
あなたは 2 種類の料理を作れます。料理 A は、1 人分を作るのに各材料 i (1 \leq i \leq N) が A_i グラム必要です。料理 B は、1 人分を作るのに各材料 i が B_i グラム必要です。どちらも整数人分しか作れません。
冷蔵庫にある材料のみを使って、最大で合計何人分の料理を作れますか。
制約
- 1 \leq N \leq 10
- 1 \leq Q_i \leq 10^6
- 0 \leq A_i \leq 10^6
- A_i \geq 1 であるような i が存在する。
- 0 \leq B_i \leq 10^6
- B_i \geq 1 であるような i が存在する。
- 入力値はすべて整数である。
入力
入力は以下の形式で標準入力から与えられる。
N Q_1 Q_2 \dots Q_N A_1 A_2 \dots A_N B_1 B_2 \dots B_N
出力
最大で合計 S 人分の料理を作れるとして、整数 S を出力せよ。
入力例 1
2 800 300 100 100 200 10
出力例 1
5
この冷蔵庫には、800 グラムの材料 1 と 300 グラムの材料 2 があります。
100 グラムの材料 1 と 100 グラムの材料 2 で料理 A を 1 人分作れ、200 グラムの材料 1 と 10 グラムの材料 2 で料理 B を 1 人分作れます。
料理 A を 2 人分、料理 B を 3 人分作るのに必要な材料 1 の量は 100 \times 2 + 200 \times 3 = 800 グラム、材料 2 の量は 100 \times 2 + 10 \times 3 = 230 グラムで、いずれも冷蔵庫にある量を超えません。このようにして合計 5 人分の料理を作ることができますが、6 人分を作る方法はなく、答えは 5 です。
入力例 2
2 800 300 100 0 0 10
出力例 2
38
800 グラムの材料 1 で料理 A を 8 人分、300 グラムの材料 2 で料理 B を 30 人分、合計 38 人分作れます。
入力例 3
2 800 300 801 300 800 301
出力例 3
0
何も作れません。
入力例 4
10 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 0 1 2 3 4 5 6 7 8 9 9 8 7 6 5 4 3 2 1 0
出力例 4
222222
Score: 300 points
Problem Statement
Your refrigerator has N kinds of ingredients. Let us call them ingredient 1, \dots, ingredient N. You have Q_i grams of ingredient i.
You can make two types of dishes. To make one serving of dish A, you need A_i grams of each ingredient i (1 \leq i \leq N). To make one serving of dish B, you need B_i grams of each ingredient i. You can only make an integer number of servings of each type of dish.
Using only the ingredients in the refrigerator, what is the maximum total number of servings of dishes you can make?
Constraints
- 1 \leq N \leq 10
- 1 \leq Q_i \leq 10^6
- 0 \leq A_i \leq 10^6
- There is an i such that A_i \geq 1.
- 0 \leq B_i \leq 10^6
- There is an i such that B_i \geq 1.
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N Q_1 Q_2 \dots Q_N A_1 A_2 \dots A_N B_1 B_2 \dots B_N
Output
Assuming that you can make a maximum total of S servings of dishes, print the integer S.
Sample Input 1
2 800 300 100 100 200 10
Sample Output 1
5
This refrigerator has 800 grams of ingredient 1 and 300 grams of ingredient 2.
You can make one serving of dish A with 100 grams of ingredient 1 and 100 grams of ingredient 2, and one serving of dish B with 200 grams of ingredient 1 and 10 grams of ingredient 2.
To make two servings of dish A and three servings of dish B, you need 100 \times 2 + 200 \times 3 = 800 grams of ingredient 1, and 100 \times 2 + 10 \times 3 = 230 grams of ingredient 2, neither of which exceeds the amount available in the refrigerator. In this way, you can make a total of five servings of dishes, but there is no way to make six, so the answer is 5.
Sample Input 2
2 800 300 100 0 0 10
Sample Output 2
38
You can make 8 servings of dish A with 800 grams of ingredient 1, and 30 servings of dish B with 300 grams of ingredient 2, for a total of 38 servings.
Sample Input 3
2 800 300 801 300 800 301
Sample Output 3
0
You cannot make any dishes.
Sample Input 4
10 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 0 1 2 3 4 5 6 7 8 9 9 8 7 6 5 4 3 2 1 0
Sample Output 4
222222