実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 100 点
問題文
5 枚のカードがあり、それぞれのカードには整数 A,B,C,D,E が書かれています。
この 5 枚組は以下の条件を満たすとき、またそのときに限って、フルハウスであると呼ばれます。
- 同じ数が書かれたカード 3 枚と、別の同じ数が書かれたカード 2 枚からなる。
5 枚組がフルハウスであるか判定してください。
制約
- 1 \leq A,B,C,D,E\leq 13
- A,B,C,D,E 全てが同じ値ではない
- 入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。
A B C D E
出力
フルハウスである場合 Yes を、そうでないとき No を出力せよ。
入力例 1
1 2 1 2 1
出力例 1
Yes
1 が書かれたカード 3 枚と、2 が書かれたカード 2 枚からなるため、これはフルハウスです。
入力例 2
12 12 11 1 2
出力例 2
No
フルハウスの条件を満たしません。
Score : 100 points
Problem Statement
We have five cards with integers A, B, C, D, and E written on them, one on each card.
This set of five cards is called a Full house if and only if the following condition is satisfied:
- the set has three cards with a same number written on them, and two cards with another same number written on them.
Determine whether the set is a Full house.
Constraints
- 1 \leq A,B,C,D,E\leq 13
- Not all of A, B, C, D, and E are the same.
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
A B C D E
Output
If the set is a Full house, print Yes; otherwise, print No.
Sample Input 1
1 2 1 2 1
Sample Output 1
Yes
The set has three cards with 1 written on them and two cards with 2 written on them, so it is a Full house.
Sample Input 2
12 12 11 1 2
Sample Output 2
No
The condition is not satisfied.
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 100 点
問題文
長さ N の整数列 A=(A_1,A_2,\dots,A_N) と整数 X が与えられます。
X が A に含まれるか判定してください。
制約
- 入力は全て整数
- 1 \le N \le 100
- 1 \le A_i \le 100
- 1 \le X \le 100
入力
入力は以下の形式で標準入力から与えられる。
N A_1 A_2 \dots A_N X
出力
X が A に含まれるなら Yes 、含まれないなら No と出力せよ。
入力例 1
5 3 1 4 1 5 4
出力例 1
Yes
A=(3,1,4,1,5), X=4 であり、 X は A に含まれます。
入力例 2
4 100 100 100 100 100
出力例 2
Yes
X が複数回 A に含まれる場合もあります。
入力例 3
6 2 3 5 7 11 13 1
出力例 3
No
Score : 100 points
Problem Statement
You are given an integer sequence A=(A_1,A_2,\dots,A_N) of length N and an integer X.
Determine whether X is contained in A.
Constraints
- All input values are integers.
- 1 \le N \le 100
- 1 \le A_i \le 100
- 1 \le X \le 100
Input
The input is given from Standard Input in the following format:
N A_1 A_2 \dots A_N X
Output
If X is contained in A, print Yes; otherwise, print No.
Sample Input 1
5 3 1 4 1 5 4
Sample Output 1
Yes
We have A=(3,1,4,1,5) and X=4; X is contained in A.
Sample Input 2
4 100 100 100 100 100
Sample Output 2
Yes
X may be contained in A multiple times.
Sample Input 3
6 2 3 5 7 11 13 1
Sample Output 3
No
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 200 点
問題文
長さ N の整数列 A = (A_1, A_2, \dots, A_N), B = (B_1, B_2, \dots, B_N) が与えられます。
A の要素はすべて異なります。B の要素もすべて異なります。
次の 2 つを出力してください。
- A にも B にも含まれ、その位置も一致している整数の個数。言い換えると、A_i = B_i を満たす整数 i の個数。
- A にも B にも含まれるが、その位置は異なる整数の個数。言い換えると、A_i = B_j, i \neq j を満たす整数の組 (i, j) の個数。
制約
- 1 \leq N \leq 1000
- 1 \leq A_i \leq 10^9
- 1 \leq B_i \leq 10^9
- A_1, A_2, \dots, A_N はすべて異なる。
- B_1, B_2, \dots, B_N はすべて異なる。
- 入力はすべて整数である。
入力
入力は以下の形式で標準入力から与えられる。
N A_1 A_2 \dots A_N B_1 B_2 \dots B_N
出力
答えを 2 行出力せよ。1 行目には 1. の個数、2 行目には 2. の個数を出力せよ。
入力例 1
4 1 3 5 2 2 3 1 4
出力例 1
1 2
A にも B にも含まれ、その位置も一致している整数は A_2 = B_2 = 3 の 1 個です。
A にも B にも含まれるが、その位置は異なる整数は A_1 = B_3 = 1 と A_4 = B_1 = 2 の 2 個です。
入力例 2
3 1 2 3 4 5 6
出力例 2
0 0
1., 2. ともに条件を満たす整数は存在しません。
入力例 3
7 4 8 1 7 9 5 6 3 5 1 7 8 2 6
出力例 3
3 2
Score : 200 points
Problem Statement
You are given integer sequences, each of length N: A = (A_1, A_2, \dots, A_N) and B = (B_1, B_2, \dots, B_N).
All elements of A are different. All elements of B are different, too.
Print the following two values.
- The number of integers contained in both A and B, appearing at the same position in the two sequences. In other words, the number of integers i such that A_i = B_i.
- The number of integers contained in both A and B, appearing at different positions in the two sequences. In other words, the number of pairs of integers (i, j) such that A_i = B_j and i \neq j.
Constraints
- 1 \leq N \leq 1000
- 1 \leq A_i \leq 10^9
- 1 \leq B_i \leq 10^9
- A_1, A_2, \dots, A_N are all different.
- B_1, B_2, \dots, B_N are all different.
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N A_1 A_2 \dots A_N B_1 B_2 \dots B_N
Output
Print the answers in two lines: the answer to1. in the first line, and the answer to2. in the second line.
Sample Input 1
4 1 3 5 2 2 3 1 4
Sample Output 1
1 2
There is one integer contained in both A and B, appearing at the same position in the two sequences: A_2 = B_2 = 3.
There are two integers contained in both A and B, appearing at different positions in the two sequences: A_1 = B_3 = 1 and A_4 = B_1 = 2.
Sample Input 2
3 1 2 3 4 5 6
Sample Output 2
0 0
In both 1. and 2., no integer satisfies the condition.
Sample Input 3
7 4 8 1 7 9 5 6 3 5 1 7 8 2 6
Sample Output 3
3 2
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 150 点
問題文
健康に気を使っている高橋君は、M 種類の栄養素について、食事によって十分な量を摂取できているか気になりました。
i 番目の栄養素は 1 日あたり A_i 以上摂取することが目標です。
高橋君は今日 N 品の食品を食べ、i 品目の食品からは栄養素 j を X_{i,j} 摂取しました。
M 種類全ての栄養素で目標を達成しているかどうかを判定してください。
制約
- 1 \leq N \leq 100
- 1 \leq M \leq 100
- 0 \leq A_i,X_{i,j} \leq 10^7
- 入力は全て整数である
入力
入力は以下の形式で標準入力から与えられる。
N M
A_1 \ldots A_M
X_{1,1} \ldots X_{1,M}
\vdots
X_{N,1} \ldots X_{N,M}
出力
M 種類全ての栄養素で目標を達成しているなら Yes、そうでないならば No を出力せよ。
入力例 1
2 3 10 20 30 20 0 10 0 100 100
出力例 1
Yes
栄養素 1 は 1 品目から 20、2 品目から 0 摂取したため、合わせて 20 摂取しており、10 以上摂取するという目標を達成しています。
栄養素 2,3 についても同様に目標を達成しています。
入力例 2
2 4 10 20 30 40 20 0 10 30 0 100 100 0
出力例 2
No
栄養素 4 について目標を達成していません。
Score : 150 points
Problem Statement
Takahashi is health-conscious and concerned about whether he is getting enough of M types of nutrients from his diet.
For the i-th nutrient, his goal is to take at least A_i units per day.
Today, he ate N foods, and from the i-th food, he took X_{i,j} units of nutrient j.
Determine whether he has met the goal for all M types of nutrients.
Constraints
- 1 \leq N \leq 100
- 1 \leq M \leq 100
- 0 \leq A_i, X_{i,j} \leq 10^7
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N M
A_1 \ldots A_M
X_{1,1} \ldots X_{1,M}
\vdots
X_{N,1} \ldots X_{N,M}
Output
Print Yes if the goal is met for all M types of nutrients, and No otherwise.
Sample Input 1
2 3 10 20 30 20 0 10 0 100 100
Sample Output 1
Yes
For nutrient 1, Takahashi took 20 units from the 1-st food and 0 units from the 2-nd food, totaling 20 units, thus meeting the goal of taking at least 10 units.
Similarly, he meets the goal for nutrients 2 and 3.
Sample Input 2
2 4 10 20 30 40 20 0 10 30 0 100 100 0
Sample Output 2
No
The goal is not met for nutrient 4.
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 350 点
問題文
N 棟のビルが等間隔に一列に並んでいます。手前から i 番目のビルの高さは H_i です。
あなたは次の条件をともに満たすようにいくつかのビルを選んで電飾で飾ろうとしています。
- 選んだビルたちは高さが等しい
- 選んだビルたちは等間隔に並んでいる
最大でいくつのビルを選ぶことができますか? なお、ちょうど 1 つのビルを選んだときは条件を満たすとみなします。
制約
- 1 \leq N \leq 3000
- 1 \leq H_i \leq 3000
- 入力は全て整数である
入力
入力は以下の形式で標準入力から与えられる。
N H_1 \ldots H_N
出力
答えを出力せよ。
入力例 1
8 5 7 5 7 7 5 7 7
出力例 1
3
手前から 2,5,8 番目のビルを選ぶと条件を満たします。
入力例 2
10 100 200 300 400 500 600 700 800 900 1000
出力例 2
1
1つのビルを選んだときは条件を満たすとみなします。
入力例 3
32 3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4 6 2 6 4 3 3 8 3 2 7 9 5
出力例 3
3
Score : 350 points
Problem Statement
There are N buildings arranged in a line at equal intervals. The height of the i-th building from the front is H_i.
You want to decorate some of these buildings with illuminations so that both of the following conditions are satisfied:
- The chosen buildings all have the same height.
- The chosen buildings are arranged at equal intervals.
What is the maximum number of buildings you can choose? If you choose exactly one building, it is considered to satisfy the conditions.
Constraints
- 1 \leq N \leq 3000
- 1 \leq H_i \leq 3000
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N H_1 \ldots H_N
Output
Print the answer.
Sample Input 1
8 5 7 5 7 7 5 7 7
Sample Output 1
3
Choosing the 2nd, 5th, and 8th buildings from the front satisfies the conditions.
Sample Input 2
10 100 200 300 400 500 600 700 800 900 1000
Sample Output 2
1
Choosing just one building is considered to satisfy the conditions.
Sample Input 3
32 3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4 6 2 6 4 3 3 8 3 2 7 9 5
Sample Output 3
3