Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 100 点
問題文
地震のマグニチュードは、その地震のエネルギーの大きさを対数で表した値です。マグニチュードが 1 増える度にエネルギーは約 32 倍になることが知られています。
ここではマグニチュードが 1 増える度に地震のエネルギーがちょうど 32 倍になるとします。このとき、マグニチュード A の地震のエネルギーの大きさはマグニチュード B の地震のエネルギーの大きさの何倍ですか?
制約
- 3\leq B\leq A\leq 9
- A , B は整数
入力
入力は以下の形式で標準入力から与えられる。
A B
出力
答えを整数で出力せよ。
入力例 1
6 4
出力例 1
1024
6 は 4 より 2 だけ大きいので、 マグニチュード 6 の地震はマグニチュード 4 の地震と比べて 32\times 32=1024 倍のエネルギーを持っています。
入力例 2
5 5
出力例 2
1
マグニチュードが同じなのでエネルギーの大きさも同じです。
Score : 100 points
Problem Statement
The magnitude of an earthquake is a logarithmic scale of the energy released by the earthquake. It is known that each time the magnitude increases by 1, the amount of energy gets multiplied by approximately 32.
Here, we assume that the amount of energy gets multiplied by exactly 32 each time the magnitude increases by 1. In this case, how many times is the amount of energy of a magnitude A earthquake as much as that of a magnitude B earthquake?
Constraints
- 3\leq B\leq A\leq 9
- A and B are integers.
Input
Input is given from Standard Input in the following format:
A B
Output
Print the answer as an integer.
Sample Input 1
6 4
Sample Output 1
1024
6 is 2 greater than 4, so a magnitude 6 earthquake has 32\times 32=1024 times as much energy as a magnitude 4 earthquake has.
Sample Input 2
5 5
Sample Output 2
1
Earthquakes with the same magnitude have the same amount of energy.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 100 点
問題文
英小文字からなる N 文字の文字列 S が与えられます。
S の先頭から A 文字、末尾から B 文字取り除いた N-A-B 文字の文字列を出力してください。
制約
- 1\le N\le20
- 0\le A
- 0\le B
- A+B\lt N
- S は英小文字からなる N 文字の文字列
- N,A,B はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N A B S
出力
S の先頭から A 文字、末尾から B 文字取り除いた文字列を出力せよ。
入力例 1
7 1 3 atcoder
出力例 1
tco
atcoder の先頭から 1 文字、末尾から 3 文字取り除くと tco になります。
入力例 2
1 0 0 a
出力例 2
a
出力すべき文字列が S と等しい場合もあります。
入力例 3
20 4 8 abcdefghijklmnopqrst
出力例 3
efghijkl
Score : 100 points
Problem Statement
You are given an N-character string S consisting of lowercase English letters.
Output the string of N-A-B characters obtained by removing the first A characters and the last B characters from S.
Constraints
- 1\le N\le20
- 0\le A
- 0\le B
- A+B\lt N
- S is a string of N characters consisting of lowercase English letters.
- N, A, and B are all integers.
Input
The input is given from Standard Input in the following format:
N A B S
Output
Output the string obtained by removing the first A characters and the last B characters from S.
Sample Input 1
7 1 3 atcoder
Sample Output 1
tco
Removing the first one character and the last three characters from atcoder gives tco.
Sample Input 2
1 0 0 a
Sample Output 2
a
The string to be output may be equal to S.
Sample Input 3
20 4 8 abcdefghijklmnopqrst
Sample Output 3
efghijkl
Time Limit: 2 sec / Memory Limit: 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
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
英小文字からなる文字列 S が与えられます。 S の中で出現回数が最も多い文字をすべて取り除き、残った文字を元の順序を保ったまま連結して出力してください。
なお、出現回数が最大の文字が複数種類ある場合は、そのすべてを取り除いてください。
制約
- 1 \le |S| \le 100
- S は英小文字からなる文字列である
入力
入力は以下の形式で標準入力から与えられる。
S
出力
答えを出力せよ。
入力例 1
mississippi
出力例 1
mpp
mississippi に最も多く出現する文字は s と i でともに 4 回出現します。s と i をすべて取り除いた文字列は mpp となります。
入力例 2
atcoder
出力例 2
入力例 3
beginner
出力例 3
bgir
Score : 200 points
Problem Statement
You are given a string S consisting of lowercase English letters. Remove all occurrences of the most frequent character(s) in S, then output the remaining characters concatenated in their original order.
If there are multiple characters with the maximum frequency, remove all of them.
Constraints
- 1 \le |S| \le 100
- S is a string consisting of lowercase English letters.
Input
The input is given from Standard Input in the following format:
S
Output
Output the answer.
Sample Input 1
mississippi
Sample Output 1
mpp
The most frequent characters in mississippi are s and i, each appearing four times. Removing all occurrences of s and i yields the string mpp.
Sample Input 2
atcoder
Sample Output 2
Sample Input 3
beginner
Sample Output 3
bgir
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
以下の条件を満たす正整数 x を 321-like Number と呼びます。 この定義は A 問題と同様です。
- 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 ではありません。
K 番目に小さい 321-like Number を求めてください。
制約
- 入力は全て整数
- 1 \le K
- 321-like Number は K 個以上存在する
入力
入力は以下の形式で標準入力から与えられる。
K
出力
K 番目に小さい 321-like Number を整数として出力せよ。
入力例 1
15
出力例 1
32
321-like Number は小さいものから順に (1,2,3,4,5,6,7,8,9,10,20,21,30,31,32,40,\dots) です。
このうち 15 番目に小さいものは 32 です。
入力例 2
321
出力例 2
9610
入力例 3
777
出力例 3
983210
Score : 300 points
Problem Statement
A positive integer x is called a 321-like Number when it satisfies the following condition. This definition is the same as the one in Problem A.
- 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.
Find the K-th smallest 321-like Number.
Constraints
- All input values are integers.
- 1 \le K
- At least K 321-like Numbers exist.
Input
The input is given from Standard Input in the following format:
K
Output
Print the K-th smallest 321-like Number as an integer.
Sample Input 1
15
Sample Output 1
32
The 321-like Numbers are (1,2,3,4,5,6,7,8,9,10,20,21,30,31,32,40,\dots) from smallest to largest.
The 15-th smallest of them is 32.
Sample Input 2
321
Sample Output 2
9610
Sample Input 3
777
Sample Output 3
983210
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
長さ N の数列 A=(a_1,\ldots,a_N) があります。また、整数 K が与えられます。
あなたは次の操作を 0 回以上何度でも行えます。
- 1 \leq i \leq N-K を満たす整数 i を選び、a_i と a_{i+K} の値を入れ替える。
A を昇順に並べ替えることが出来るかどうかを判定してください。
制約
- 2 \leq N \leq 2 \times 10^5
- 1 \leq K \leq N-1
- 1 \leq a_i \leq 10^9
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N K a_1 \ldots a_N
出力
A を昇順に並び替えることが出来るならば Yes と、出来ないならば No と出力せよ。
入力例 1
5 2 3 4 1 3 4
出力例 1
Yes
次のように操作をすることで A を昇順に並び替えることが出来ます。
- i=1 とし、a_1 と a_3 の値を入れ替える。数列は (1,4,3,3,4) となる。
- i=2 とし、a_2 と a_4 の値を入れ替える。数列は (1,3,3,4,4) となる。
入力例 2
5 3 3 4 1 3 4
出力例 2
No
入力例 3
7 5 1 2 3 4 5 5 10
出力例 3
Yes
操作を行う必要が無い場合もあります。
Score : 300 points
Problem Statement
We have a sequence of length N: A=(a_1,\ldots,a_N). Additionally, you are given an integer K.
You can perform the following operation zero or more times.
- Choose an integer i such that 1 \leq i \leq N-K, then swap the values of a_i and a_{i+K}.
Determine whether it is possible to sort A in ascending order.
Constraints
- 2 \leq N \leq 2 \times 10^5
- 1 \leq K \leq N-1
- 1 \leq a_i \leq 10^9
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N K a_1 \ldots a_N
Output
If it is possible to sort A in ascending order, print Yes; otherwise, print No.
Sample Input 1
5 2 3 4 1 3 4
Sample Output 1
Yes
The following sequence of operations sorts A in ascending order.
- Choose i=1 to swap the values of a_1 and a_3. A is now (1,4,3,3,4).
- Choose i=2 to swap the values of a_2 and a_4. A is now (1,3,3,4,4).
Sample Input 2
5 3 3 4 1 3 4
Sample Output 2
No
Sample Input 3
7 5 1 2 3 4 5 5 10
Sample Output 3
Yes
No operations may be needed.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 400 点
問題文
H \times W 枚のクッキーが H 行 W 列に並んでいます。
上から i 行目・左から j 列目のクッキーの色は英小文字 c_{i,j} で表されます。
これから、以下の手続きを行います。
1. 各行に対して次の操作を行う : その行に 2 枚以上のクッキーが残っており、それらの色がすべて同じならば、それらに印をつける。
2. 各列に対して次の操作を行う : その列に 2 枚以上のクッキーが残っており、それらの色がすべて同じならば、それらに印をつける。
3. 印のついたクッキーがあればそれらをすべて取り除いて 1. に戻り、なければ手続きを終了する。
手続きを終了した時点で残っているクッキーの枚数を求めてください。
制約
- 2 \leq H, W \leq 2000
- c_{i,j} は英小文字である
入力
入力は以下の形式で標準入力から与えられる。
H W
c_{1,1}c_{1,2} \ldots c_{1,W}
c_{2,1}c_{2,2} \ldots c_{2,W}
\vdots
c_{H,1}c_{H,2} \ldots c_{H,W}
出力
答えを出力せよ。
入力例 1
4 3 aaa aaa abc abd
出力例 1
2
以下で示す順で手続きを行います。
- 1. により、1, 2 行目のクッキーに印をつける。
- 2. により、1 列目のクッキーに印をつける。
- 3. により、印を付けたクッキーを取り除く。
この時点でクッキーは以下のようになっています。ただし、クッキーを取り除いた箇所は . で表しています。
... ... .bc .bd
- 1. により、何もしない。
- 2. により、2 列目のクッキーに印をつける。
- 3. により、印を付けたクッキーを取り除く。
この時点でクッキーは以下のようになっています。ただし、クッキーを取り除いた箇所は . で表しています。
... ... ..c ..d
- 1. により、何もしない。
- 2. により、何もしない。
- 3. により、印がついているクッキーが存在しないので手続きを終了する。
最終的に残っているクッキーの枚数は 2 枚です。
入力例 2
2 5 aaaaa abcde
出力例 2
4
入力例 3
3 3 ooo ooo ooo
出力例 3
0
Score : 400 points
Problem Statement
There are H \times W cookies in H rows and W columns.
The color of the cookie at the i-row from the top and j-th column from the left is represented by a lowercase English letter c_{i,j}.
We will perform the following procedure.
1. For each row, perform the following operation: if there are two or more cookies remaining in the row and they all have the same color, mark them.
2. For each column, perform the following operation: if there are two or more cookies remaining in the column and they all have the same color, mark them.
3. If there are any marked cookies, remove them all and return to 1; otherwise, terminate the procedure.
Find the number of cookies remaining at the end of the procedure.
Constraints
- 2 \leq H, W \leq 2000
- c_{i,j} is a lowercase English letter.
Input
The input is given from Standard Input in the following format:
H W
c_{1,1}c_{1,2} \ldots c_{1,W}
c_{2,1}c_{2,2} \ldots c_{2,W}
\vdots
c_{H,1}c_{H,2} \ldots c_{H,W}
Output
Print the answer.
Sample Input 1
4 3 aaa aaa abc abd
Sample Output 1
2
The procedure is performed as follows.
- 1. Mark the cookies in the first and second rows.
- 2. Mark the cookies in the first column.
- 3. Remove the marked cookies.
At this point, the cookies look like the following, where . indicates a position where the cookie has been removed.
... ... .bc .bd
- 1. Do nothing.
- 2. Mark the cookies in the second column.
- 3. Remove the marked cookies.
At this point, the cookies look like the following, where . indicates a position where the cookie has been removed.
... ... ..c ..d
- 1. Do nothing.
- 2. Do nothing.
- 3. No cookies are marked, so terminate the procedure.
The final number of cookies remaining is 2.
Sample Input 2
2 5 aaaaa abcde
Sample Output 2
4
Sample Input 3
3 3 ooo ooo ooo
Sample Output 3
0
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 500 点
問題文
長さ N の数列 A = (A_1, A_2, \dots, A_N) および整数 X, Y があります。 次の条件をすべて満たす整数の組 (L, R) の個数を求めてください。
- 1 \leq L \leq R \leq N
- A_L, A_{L+1}, \dots, A_R の最大値は X であり、最小値は Y である。
制約
- 1 \leq N \leq 2 \times 10^5
- 1 \leq A_i \leq 2 \times 10^5
- 1 \leq Y \leq X \leq 2 \times 10^5
- 入力される値はすべて整数である。
入力
入力は以下の形式で標準入力から与えられる。
N X Y A_1 A_2 \dots A_N
出力
答えを出力せよ。
入力例 1
4 3 1 1 2 3 1
出力例 1
4
条件を満たすのは (L,R)=(1,3),(1,4),(2,4),(3,4) の 4 通りです。
入力例 2
5 2 1 1 3 2 4 1
出力例 2
0
条件を満たす (L,R) は存在しません。
入力例 3
5 1 1 1 1 1 1 1
出力例 3
15
X=Y である場合もあります。
入力例 4
10 8 1 2 7 1 8 2 8 1 8 2 8
出力例 4
36
Score : 500 points
Problem Statement
We have a number sequence A = (A_1, A_2, \dots, A_N) of length N and integers X and Y. Find the number of pairs of integers (L, R) satisfying all the conditions below.
- 1 \leq L \leq R \leq N
- The maximum value of A_L, A_{L+1}, \dots, A_R is X, and the minimum is Y.
Constraints
- 1 \leq N \leq 2 \times 10^5
- 1 \leq A_i \leq 2 \times 10^5
- 1 \leq Y \leq X \leq 2 \times 10^5
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N X Y A_1 A_2 \dots A_N
Output
Print the answer.
Sample Input 1
4 3 1 1 2 3 1
Sample Output 1
4
4 pairs satisfy the conditions: (L,R)=(1,3),(1,4),(2,4),(3,4).
Sample Input 2
5 2 1 1 3 2 4 1
Sample Output 2
0
No pair (L,R) satisfies the condition.
Sample Input 3
5 1 1 1 1 1 1 1
Sample Output 3
15
It may hold that X=Y.
Sample Input 4
10 8 1 2 7 1 8 2 8 1 8 2 8
Sample Output 4
36
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 500 点
問題文
長さ L のパンが 1 つあり、これを N 人の子供たちに切り分けます。 i 番目 (1\leq i\leq N) の子供は長さ A_i のパンを欲しがっています。
そこで、高橋君は次の操作を繰り返して、長さ A_1,A_2,\ldots,A_N のパンを切り出して配ることにしました。
長さ k のパン 1 つと 1 以上 k-1 以下の整数 x を選ぶ。選んだパンを長さ x のパンと 長さ k-x のパンに切り分ける。
このとき、x の値によらずコストが k かかる。
それぞれの子供に配るパンは長さがちょうど A_i のパン 1 つである必要がありますが、誰にも配られずに余るパンがいくつあっても構いません。
このとき、全ての子供たちにパンを配るために必要な最小のコストを求めてください。
制約
- 2 \leq N \leq 2\times 10^5
- 1\leq A_i\leq 10^9
- A_1+A_2+\cdots+A_N\leq L\leq 10^{15}
- 入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N L A_1 A_2 \ldots A_N
出力
全ての子供たちにパンを配るために必要な最小のコストを出力せよ。
入力例 1
5 7 1 2 1 2 1
出力例 1
16
高橋君は次のようにしてパンを切り分けて配ることができます。
- 長さ 7 のパンと整数 x=3 を選ぶ。パンは長さ 3 のパンと長さ 4 のパンに切り分けられる。 (コスト 7 )
- 長さ 3 のパンと整数 x=1 を選ぶ。パンは長さ 1 のパンと長さ 2 のパンに切り分けられる。前者を 1 番目の子供に配る。 (コスト 3 )
- 長さ 2 のパンと整数 x=1 を選ぶ。パンは長さ 1 のパン 2 つに切り分けられる。これを 3,5 番目の子供に配る。 (コスト 2 )
- 長さ 4 のパンと整数 x=2 を選ぶ。パンは長さ 2 のパン 2 つに切り分けられる。これを 2,4 番目の子供に配る。 (コスト 4 )
このとき、コストは 7+3+2+4=16 かかり、これが最小です。 また、余るパンはありません。
入力例 2
3 1000000000000000 1000000000 1000000000 1000000000
出力例 2
1000005000000000
それぞれの子供に配るパンの長さはちょうど A_i でなければならない事に注意してください。
Score : 500 points
Problem Statement
We have a loaf of bread of length L, which we will cut and distribute to N children.
The i-th child (1\leq i\leq N) wants a loaf of length A_i.
Now, Takahashi will repeat the operation below to cut the loaf into lengths A_1, A_2, \ldots, A_N for the children.
Choose a loaf of length k and an integer x between 1 and k-1 (inclusive). Cut the loaf into two loaves of length x and k-x.
This operation incurs a cost of k regardless of the value of x.
Each child i must receive a loaf of length exactly A_i, but it is allowed to leave some loaves undistributed.
Find the minimum cost needed to distribute loaves to all children.
Constraints
- 2 \leq N \leq 2\times 10^5
- 1\leq A_i\leq 10^9
- A_1+A_2+\cdots+A_N\leq L\leq 10^{15}
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N L A_1 A_2 \ldots A_N
Output
Print the minimum cost needed to distribute loaves to all children.
Sample Input 1
5 7 1 2 1 2 1
Sample Output 1
16
Takahashi can cut the loaf for the children as follows.
- Choose the loaf of length 7 and x=3, cutting it into loaves of length 3 and 4 for a cost of 7.
- Choose the loaf of length 3 and x=1, cutting it into loaves of length 1 and 2 for a cost of 3. Give the former to the 1-st child.
- Choose the loaf of length 2 and x=1, cutting it into two loaves of length 1 for a cost of 2. Give them to the 3-rd and 5-th children.
- Choose the loaf of length 4 and x=2, cutting it into two loaves of length 2 for a cost of 4. Give them to the 2-nd and 4-th children.
This incurs a cost of 7+3+2+4=16, which is the minimum possible. There will be no leftover loaves.
Sample Input 2
3 1000000000000000 1000000000 1000000000 1000000000
Sample Output 2
1000005000000000
Note that each child i must receive a loaf of length exactly A_i.