Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 100 点
問題文
整数 A,B が与えられるので、 A+B の値を答えてください。
但し、この問題は N 択問題であり、 i 番の選択肢は C_i です。
正解となる 選択肢の番号 を出力してください。
制約
- 入力は全て整数
- 1 \le N \le 300
- 1 \le A,B \le 1000
- 1 \le C_i \le 2000
- C_i は相異なる。すなわち、同じ選択肢が複数存在することはない。
- A+B=C_i なる i が丁度 1 つ存在する。すなわち、正解となる選択肢が必ずただ 1 つ存在する。
入力
入力は以下の形式で標準入力から与えられる。
N A B C_1 C_2 \dots C_N
出力
答えを整数として出力せよ。
入力例 1
3 125 175 200 300 400
出力例 1
2
125+175 = 300 です。
1 番の選択肢は 200 、 2 番の選択肢は 300 、 3 番の選択肢は 400 です。
よって正解となる選択肢の番号は 2 番であり、これを出力します。
入力例 2
1 1 1 2
出力例 2
1
1 択問題である場合もあります。
入力例 3
5 123 456 135 246 357 468 579
出力例 3
5
Score : 100 points
Problem Statement
Given integers A and B, find A+B.
This is a N-choice problem; the i-th choice is C_i.
Print the index of the correct choice.
Constraints
- All values in the input are integers.
- 1 \le N \le 300
- 1 \le A,B \le 1000
- 1 \le C_i \le 2000
- C_i are pairwise distinct. In other words, no two choices have the same value.
- There is exactly one i such that A+B=C_i. In other words, there is always a unique correct choice.
Input
The input is given from Standard Input in the following format:
N A B C_1 C_2 \dots C_N
Output
Print the answer as an integer.
Sample Input 1
3 125 175 200 300 400
Sample Output 1
2
We have 125+175 = 300.
The first, second, and third choices are 200, 300, and 400, respectively.
Thus, the 2-nd choice is correct, so 2 should be printed.
Sample Input 2
1 1 1 2
Sample Output 2
1
The problem may be a one-choice problem.
Sample Input 3
5 123 456 135 246 357 468 579
Sample Output 3
5
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 100 点
問題文
正整数 A,B が与えられます。
A^B+B^A の値を出力してください。
制約
- 2 \leq A \leq B \leq 9
- 入力される数値はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
A B
出力
答えを整数として出力せよ。
入力例 1
2 8
出力例 1
320
A = 2, B = 8 のとき、A^B = 256, B^A = 64 なので A^B + B^A = 320 です。
入力例 2
9 9
出力例 2
774840978
入力例 3
5 6
出力例 3
23401
Score : 100 points
Problem Statement
You are given positive integers A and B.
Print the value A^B+B^A.
Constraints
- 2 \leq A \leq B \leq 9
- All input values are integers.
Input
The input is given from Standard Input in the following format:
A B
Output
Print the answer as an integer.
Sample Input 1
2 8
Sample Output 1
320
For A = 2, B = 8, we have A^B = 256, B^A = 64, so A^B + B^A = 320.
Sample Input 2
9 9
Sample Output 2
774840978
Sample Input 3
5 6
Sample Output 3
23401
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
正整数からなる長さ N の数列 A=(A_1,\ldots,A_N) があります。どの隣接する 2 項の値も相異なります。
この数列に対し、次の操作によりいくつか数を挿入します。
- 数列 A のどの隣接する 2 項の差の絶対値も 1 であるとき、操作を終了する。
- 数列 A の先頭から見て、隣接する 2 項の差の絶対値が 1 でない最初の箇所を A_i,A_{i+1} とする。
- A_i < A_{i+1} ならば、A_i と A_{i+1} の間に、A_i+1,A_i+2,\ldots,A_{i+1}-1 を挿入する。
- A_i > A_{i+1} ならば、A_i と A_{i+1} の間に、A_i-1,A_i-2,\ldots,A_{i+1}+1 を挿入する。
- 手順 1 に戻る。
操作が終了したときの数列を出力してください。
制約
- 2 \leq N \leq 100
- 1 \leq A_i \leq 100
- A_i \neq A_{i+1}
- 入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N A_1 A_2 \ldots A_N
出力
操作が終了したときの数列の各要素を空白区切りで出力せよ。
入力例 1
4 2 5 1 2
出力例 1
2 3 4 5 4 3 2 1 2
最初、数列は (2,5,1,2) です。操作は以下のように行われます。
- 1 項目の 2 と 2 項目の 5 の間に 3,4 を挿入する。数列は (2,3,4,5,1,2) となる。
- 4 項目の 5 と 5 項目の 1 の間に 4,3,2 を挿入する。数列は (2,3,4,5,4,3,2,1,2) となる。
入力例 2
6 3 4 5 6 5 4
出力例 2
3 4 5 6 5 4
一度も挿入が行われないこともあります。
Score : 200 points
Problem Statement
We have a sequence of length N consisting of positive integers: A=(A_1,\ldots,A_N). Any two adjacent terms have different values.
Let us insert some numbers into this sequence by the following procedure.
- If every pair of adjacent terms in A has an absolute difference of 1, terminate the procedure.
- Let A_i, A_{i+1} be the pair of adjacent terms nearest to the beginning of A whose absolute difference is not 1.
- If A_i < A_{i+1}, insert A_i+1,A_i+2,\ldots,A_{i+1}-1 between A_i and A_{i+1}.
- If A_i > A_{i+1}, insert A_i-1,A_i-2,\ldots,A_{i+1}+1 between A_i and A_{i+1}.
- Return to step 1.
Print the sequence when the procedure ends.
Constraints
- 2 \leq N \leq 100
- 1 \leq A_i \leq 100
- A_i \neq A_{i+1}
- 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
Print the terms in the sequence when the procedure ends, separated by spaces.
Sample Input 1
4 2 5 1 2
Sample Output 1
2 3 4 5 4 3 2 1 2
The initial sequence is (2,5,1,2). The procedure goes as follows.
- Insert 3,4 between the first term 2 and the second term 5, making the sequence (2,3,4,5,1,2).
- Insert 4,3,2 between the fourth term 5 and the fifth term 1, making the sequence (2,3,4,5,4,3,2,1,2).
Sample Input 2
6 3 4 5 6 5 4
Sample Output 2
3 4 5 6 5 4
No insertions may be performed.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
N 個のボールがあります。
i 番目のボールの色は C_i、大きさは S_i です。ここで、色は 1, 2, \ldots, M の整数で表されます。
k = 1, 2, \ldots, M について、色 k のボールの大きさの最大値を出力してください。ただし、色 k のボールが存在しない場合は -1 と出力してください。
制約
- 1 \leq N, M \leq 100
- 1 \leq C_i \leq M
- 1 \leq S_i \leq 100
- 入力される値はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N M C_1 S_1 C_2 S_2 \vdots C_N S_N
出力
k = 1, 2, \ldots, M の順に、色 k のボールが存在するならば色 k のボールの大きさの最大値を、存在しないならば -1 を空白区切りで出力せよ。
入力例 1
4 5 1 3 2 10 1 7 4 9
出力例 1
7 10 -1 9 -1
色 1 のボールの大きさの最大値は 7、色 2 のボールの大きさの最大値は 10、色 4 のボールの大きさの最大値は 9 です。
色 3 のボール、色 5 のボールは存在しません。
入力例 2
5 5 2 6 5 12 5 2 5 9 2 7
出力例 2
-1 7 -1 -1 12
Score : 200 points
Problem Statement
There are N balls.
The color of the i-th ball is C_i, and its size is S_i. Here, the colors are represented by integers 1, 2, \ldots, M.
For k = 1, 2, \ldots, M, output the maximum size of a ball of color k, or -1 if there is no ball of color k.
Constraints
- 1 \leq N, M \leq 100
- 1 \leq C_i \leq M
- 1 \leq S_i \leq 100
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N M C_1 S_1 C_2 S_2 \vdots C_N S_N
Output
In the order k = 1, 2, \ldots, M, output the maximum size of a ball of color k if such a ball exists, or -1 otherwise, separated by spaces.
Sample Input 1
4 5 1 3 2 10 1 7 4 9
Sample Output 1
7 10 -1 9 -1
The maximum size of a ball of color 1 is 7, that of a ball of color 2 is 10, and that of a ball of color 4 is 9.
There is no ball of color 3 or color 5.
Sample Input 2
5 5 2 6 5 12 5 2 5 9 2 7
Sample Output 2
-1 7 -1 -1 12
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
長さ N の整数列 A=(A_1,A_2,\ldots,A_N) が与えられます。
1\leq i<j<k\leq N をみたす整数の組 (i,j,k) であって、
次の条件をみたすものの個数を求めてください。
A_i,A_j,A_k の中にちょうど 2 種類の値が含まれる。すなわち、A_i,A_j,A_k の中のいずれか 2 つは等しく、残りの 1 つは異なる。
制約
- 3 \leq N \leq 2\times 10^5
- 1 \leq A_i \leq N
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N A_1 A_2 \ldots A_N
出力
条件をみたす整数の組の個数を出力せよ。
入力例 1
5 3 2 5 2 2
出力例 1
6
例えば、(i,j,k)=(1,2,4) は、A_1=3, A_2=2, A_4=2 の中に 2,3 のちょうど 2 種類の値が含まれるため、条件をみたします。
これを含めて、(i,j,k)=(1,2,4),(1,2,5),(1,4,5),(2,3,4),(2,3,5),(3,4,5) の 6 組が条件をみたします。
よって、6 を出力します。
入力例 2
3 1 1 1
出力例 2
0
条件をみたす組が存在しない可能性もあります。
Score : 300 points
Problem Statement
You are given an integer sequence of length N, A=(A_1,A_2,\ldots,A_N).
Find the number of triples of integers (i,j,k) satisfying 1\leq i<j<k\leq N that satisfy the following condition:
Exactly two distinct values are contained in A_i,A_j,A_k. That is, two of A_i,A_j,A_k are equal, and the remaining one is different.
Constraints
- 3 \leq N \leq 2\times 10^5
- 1 \leq A_i \leq N
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N A_1 A_2 \ldots A_N
Output
Print the number of triples of integers that satisfy the condition.
Sample Input 1
5 3 2 5 2 2
Sample Output 1
6
For example, (i,j,k)=(1,2,4) satisfies the condition because exactly two distinct values, 2 and 3, are contained in A_1=3, A_2=2, and A_4=2.
Including this, the six triples (i,j,k)=(1,2,4),(1,2,5),(1,4,5),(2,3,4),(2,3,5),(3,4,5) satisfy the condition.
Therefore, print 6.
Sample Input 2
3 1 1 1
Sample Output 2
0
There may be no triples that satisfy the condition.