Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 100 点
問題文
4 個のボールがあり、i 個目のボールの色は A_i です。
同じ色のボールを 2 つ選び両方捨てるという操作を最大何回行えるか求めてください。
制約
- A_1,A_2,A_3,A_4 はそれぞれ 1 以上 4 以下の整数
入力
入力は以下の形式で標準入力から与えられる。
A_1 A_2 A_3 A_4
出力
操作回数の最大値を整数として出力せよ。
入力例 1
2 1 2 1
出力例 1
2
1 個目のボールと 3 個目のボールはどちらも色が 2 なので、1 個目のボールと 3 個目のボールを共に捨てる操作を行えます。
次に、2 個目のボールと 4 個目のボールはどちらも色が 1 なので、2 個目のボールと 4 個目のボールを共に捨てる操作を行えます。
合計で 2 回操作を行えます。
入力例 2
4 4 4 1
出力例 2
1
入力例 3
1 2 3 4
出力例 3
0
操作を一度も行えない場合もあります。
Score : 100 points
Problem Statement
There are four balls, and the color of the i-th ball is A_i.
Find the maximum number of times you can perform this operation: choose two balls of the same color and discard both.
Constraints
- Each of A_1, A_2, A_3, A_4 is an integer between 1 and 4, inclusive.
Input
The input is given from Standard Input in the following format:
A_1 A_2 A_3 A_4
Output
Print the maximum number of times the operation can be performed as an integer.
Sample Input 1
2 1 2 1
Sample Output 1
2
The first and third balls both have color 2, so you can perform the operation to discard the first and third balls together.
Next, the second and fourth balls both have color 1, so you can perform the operation to discard the second and fourth balls together.
Hence, you can perform a total of two operations.
Sample Input 2
4 4 4 1
Sample Output 2
1
Sample Input 3
1 2 3 4
Sample Output 3
0
There are cases where you cannot perform the operation even once.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 100 点
問題文
0 以上 9999 以下の整数 N が与えられます。
N の先頭に必要なだけ 0 をつけ、4 桁の文字列にしたものを出力してください。
制約
- 0 \leq N \leq 9999
- N は整数
入力
入力は以下の形式で標準入力から与えられる。
N
出力
答えを出力せよ。
入力例 1
321
出力例 1
0321
321 は 3 桁なので、先頭に 1 つ 0 をつけると 4 桁になります。
入力例 2
7777
出力例 2
7777
入力例 3
1
出力例 3
0001
Score : 100 points
Problem Statement
You are given an integer N between 0 and 9999 (inclusive).
Print it as a four-digit string after appending to it the necessary number of leading zeros.
Constraints
- 0 \leq N \leq 9999
- N is an integer.
Input
Input is given from Standard Input in the following format:
N
Output
Print the answer.
Sample Input 1
321
Sample Output 1
0321
321 has three digits, so we need to add one leading zero to it to make it have four digits.
Sample Input 2
7777
Sample Output 2
7777
Sample Input 3
1
Sample Output 3
0001
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
長さ N の整数列 A=(A_1,\ldots,A_N) が与えられます。ここで A_1,A_2,\ldots,A_N は相異なります。
A の中で二番目に大きい要素は A の何番目の要素でしょうか。
制約
- 2\leq N\leq 100
- 1\leq A_i \leq 10^9
- A_1,A_2,\ldots,A_N は相異なる
- 入力される数値は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N
A_1 A_2 \ldots A_{N}
出力
A の中で二番目に大きい要素が A の X 番目であるとき、X を整数として出力せよ。
入力例 1
4 8 2 5 1
出力例 1
3
A の中で二番目に大きい要素は A_3 なので 3 を出力してください。
入力例 2
8 1 2 3 4 5 10 9 11
出力例 2
6
Score : 200 points
Problem Statement
You are given an integer sequence A=(A_1,\ldots,A_N) of length N. Here, A_1, A_2, \ldots, A_N are all distinct.
Which element in A is the second largest?
Constraints
- 2 \leq N \leq 100
- 1 \leq A_i \leq 10^9
- A_1, A_2, \ldots, A_N are all distinct.
- 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 integer X such that the X-th element in A is the second largest.
Sample Input 1
4 8 2 5 1
Sample Output 1
3
The second largest element in A is A_3, so print 3.
Sample Input 2
8 1 2 3 4 5 10 9 11
Sample Output 2
6
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 250 点
問題文
東西に無限に伸びる道路があり、この道路上のある基準となる地点から東に x\mathrm{\,m} のところにある地点の座標は x と定められています。 特に、基準となる地点から西に x\mathrm{\,m} のところにある地点の座標は -x です。
すぬけ君は今から、座標が A である地点を基点にして M\mathrm{\,m} おきにクリスマスツリーを立てます。 すなわち、座標がある整数 k を用いて A+kM と表されるような地点それぞれにクリスマスツリーを立てます。
高橋君と青木君はそれぞれ座標が L,R\ (L\leq R) である地点に立っています。 高橋君と青木君の間(高橋君と青木君が立っている地点を含む)に立てられるクリスマスツリーの本数を求めてください。
制約
- -10^{18}\leq A \leq 10^{18}
- 1\leq M \leq 10^9
- -10^{18}\leq L\leq R \leq 10^{18}
- 入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。
A M L R
出力
高橋君と青木君の間(高橋君と青木君が立っている地点を含む)に立てられるクリスマスツリーの本数を出力せよ。
入力例 1
5 3 -1 6
出力例 1
3
すぬけ君は、座標が \dots,-4,-1,2,5,8,11,14\dots である地点にクリスマスツリーを立てます。 これらのうち高橋君と青木君の間にあるのは、座標が -1,2,5 である地点に立てられる 3 本です。
入力例 2
-2 2 1 1
出力例 2
0
高橋君と青木君が同じ地点に立っていることもあります。
入力例 3
-177018739841739480 2436426 -80154573737296504 585335723211047198
出力例 3
273142010859
Score : 250 points
Problem Statement
There is a road that stretches infinitely to the east and west, and the coordinate of a point located x meters to the east from a certain reference point on this road is defined as x. In particular, the coordinate of a point located x meters to the west from the reference point is -x.
Snuke will set up Christmas trees at points on the road at intervals of M meters, starting from a point with coordinate A. In other words, he will set up a Christmas tree at each point that can be expressed as A+kM using some integer k.
Takahashi and Aoki are standing at points with coordinates L and R (L\leq R), respectively. Find the number of Christmas trees that will be set up between Takahashi and Aoki (including the points where they are standing).
Constraints
- -10^{18}\leq A \leq 10^{18}
- 1\leq M \leq 10^9
- -10^{18}\leq L\leq R \leq 10^{18}
- All input values are integers.
Input
Input is given from Standard Input in the following format:
A M L R
Output
Print the number of Christmas trees that will be set up between Takahashi and Aoki (including the points where they are standing).
Sample Input 1
5 3 -1 6
Sample Output 1
3
Snuke will set up Christmas trees at points with coordinates \dots,-4,-1,2,5,8,11,14\dots. Three of them at coordinates -1, 2, and 5 are between Takahashi and Aoki.
Sample Input 2
-2 2 1 1
Sample Output 2
0
Sometimes, Takahashi and Aoki are standing at the same point.
Sample Input 3
-177018739841739480 2436426 -80154573737296504 585335723211047198
Sample Output 3
273142010859
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 250 点
問題文
1,2,\dots,N がちょうど 3 回ずつ現れる長さ 3N の数列 A=(A_1,A_2,\dots,A_{3N}) が与えられます。
i=1,2,\dots,N について、A の中にある i のうち真ん中にあるものの添字を f(i) と定めます。 1,2,\dots,N を f(i) の昇順に並べ替えてください。
f(i) の定義は厳密には以下の通りです。
- A_j = i を満たす j が j=\alpha,\beta,\gamma\ (\alpha < \beta < \gamma) であるとする。このとき、f(i) = \beta である。
制約
- 1\leq N \leq 10^5
- 1 \leq A_j \leq N
- i=1,2,\dots,N それぞれについて、A の中に i はちょうど 3 回現れる
- 入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N
A_1 A_2 \dots A_{3N}
出力
1,2,\dots,N を f(i) の昇順に並べ替えてできる長さ N の数列を空白区切りで出力せよ。
入力例 1
3 1 1 3 2 3 2 2 3 1
出力例 1
1 3 2
- A の中にある 1 は A_1,A_2,A_9 なので、f(1) = 2 です。
- A の中にある 2 は A_4,A_6,A_7 なので、f(2) = 6 です。
- A の中にある 3 は A_3,A_5,A_8 なので、f(3) = 5 です。
よって、f(1) < f(3) < f(2) であるため 1,3,2 の順に出力します。
入力例 2
1 1 1 1
出力例 2
1
入力例 3
4 2 3 4 3 4 1 3 1 1 4 2 2
出力例 3
3 4 1 2
Score : 250 points
Problem Statement
You are given a sequence A=(A_1,A_2,\dots,A_{3N}) of length 3N where each of 1,2,\dots, and N occurs exactly three times.
For i=1,2,\dots,N, let f(i) be the index of the middle occurrence of i in A. Sort 1,2,\dots,N in ascending order of f(i).
Formally, f(i) is defined as follows.
- Suppose that those j such that A_j = i are j=\alpha,\beta,\gamma\ (\alpha < \beta < \gamma). Then, f(i) = \beta.
Constraints
- 1\leq N \leq 10^5
- 1 \leq A_j \leq N
- i occurs in A exactly three times, for each i=1,2,\dots,N.
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N
A_1 A_2 \dots A_{3N}
Output
Print the sequence of length N obtained by sorting 1,2,\dots,N in ascending order of f(i), separated by spaces.
Sample Input 1
3 1 1 3 2 3 2 2 3 1
Sample Output 1
1 3 2
- 1 occurs in A at A_1,A_2,A_9, so f(1) = 2.
- 2 occurs in A at A_4,A_6,A_7, so f(2) = 6.
- 3 occurs in A at A_3,A_5,A_8, so f(3) = 5.
Thus, f(1) < f(3) < f(2), so 1,3, and 2 should be printed in this order.
Sample Input 2
1 1 1 1
Sample Output 2
1
Sample Input 3
4 2 3 4 3 4 1 3 1 1 4 2 2
Sample Output 3
3 4 1 2