Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 100 点
問題文
英小文字と .
のみからなる文字列 S が与えられます。
S を .
で分割したときの末尾の文字列を出力してください。
すなわち、.
を含まない S の接尾辞のうち最長のものを出力してください。
制約
- S は英小文字と
.
からなる、長さ 2 以上 100 以下の文字列 - S には
.
が 1 つ以上含まれる - S の末尾は
.
ではない
入力
入力は以下の形式で標準入力から与えられる。
S
出力
答えを出力せよ。
入力例 1
atcoder.jp
出力例 1
jp
atcoder.jp
の、 .
を含まない最長の接尾辞は jp
です。
入力例 2
translate.google.com
出力例 2
com
S に .
が複数含まれることもあります。
入力例 3
.z
出力例 3
z
S が .
から始まることもあります。
入力例 4
..........txt
出力例 4
txt
S 中で .
が連続することもあります。
Score: 100 points
Problem Statement
You are given a string S consisting of lowercase English letters and the character .
.
Print the last substring when S is split by .
s.
In other words, print the longest suffix of S that does not contain .
.
Constraints
- S is a string of length between 2 and 100, inclusive, consisting of lowercase English letters and
.
. - S contains at least one
.
. - S does not end with
.
.
Input
The input is given from Standard Input in the following format:
S
Output
Print the answer.
Sample Input 1
atcoder.jp
Sample Output 1
jp
The longest suffix of atcoder.jp
that does not contain .
is jp
.
Sample Input 2
translate.google.com
Sample Output 2
com
S may contain multiple .
s.
Sample Input 3
.z
Sample Output 3
z
S may start with .
.
Sample Input 4
..........txt
Sample Output 4
txt
S may contain consecutive .
s.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 100 点
問題文
整数 A, B が与えられます。 A^B の値を出力してください。
制約
- 1 \leq A, B \leq 9
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
A B
出力
答えを出力せよ。
入力例 1
4 3
出力例 1
64
4^3 = 64 であるので、64 を出力します。
入力例 2
5 5
出力例 2
3125
入力例 3
8 1
出力例 3
8
Score : 100 points
Problem Statement
Given integers A and B, print the value A^B.
Constraints
- 1 \leq A, B \leq 9
- All values in the input are integers.
Input
The input is given from Standard Input in the following format:
A B
Output
Print the answer.
Sample Input 1
4 3
Sample Output 1
64
4^3 = 64, so 64 should be printed.
Sample Input 2
5 5
Sample Output 2
3125
Sample Input 3
8 1
Sample Output 3
8
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
a+b+c \leq S かつ a \times b \times c \leq T を満たす非負整数の組 (a,b,c) はいくつありますか?
制約
- 0 \leq S \leq 100
- 0 \leq T \leq 10000
- S, T は整数である。
入力
入力は以下の形式で標準入力から与えられる。
S T
出力
条件を満たす非負整数の組 (a,b,c) の個数を出力せよ。
入力例 1
1 0
出力例 1
4
条件を満たす非負整数の組 (a,b,c) は (0,0,0), (0,0,1), (0,1,0), (1,0,0) の 4 つです。
入力例 2
2 5
出力例 2
10
入力例 3
10 10
出力例 3
213
入力例 4
30 100
出力例 4
2471
Score : 200 points
Problem Statement
How many triples of non-negative integers (a, b, c) satisfy a+b+c \leq S and a \times b \times c \leq T?
Constraints
- 0 \leq S \leq 100
- 0 \leq T \leq 10000
- S and T are integers.
Input
Input is given from Standard Input in the following format:
S T
Output
Print the number of triples of non-negative integers (a,b,c) satisfying the conditions.
Sample Input 1
1 0
Sample Output 1
4
The triples (a,b,c) satisfying the conditions are (0,0,0), (0,0,1), (0,1,0), and (1,0,0) ― there are four of them.
Sample Input 2
2 5
Sample Output 2
10
Sample Input 3
10 10
Sample Output 3
213
Sample Input 4
30 100
Sample Output 4
2471
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
配点 : 300 点
問題文
英大文字のみからなる文字列 S が与えられます。
S に対して、次の手順を行った後に得られる文字列を出力してください。
文字列が
WA
を(連続する)部分文字列として含む限り、次の操作を繰り返す。
- 文字列中に登場する
WA
のうち最も先頭のものをAC
に置換する。
なお、本問題の制約下で、この操作は高々有限回しか繰り返されないことが証明できます。
制約
- S は長さ 1 以上 3\times 10^5 以下の英大文字のみからなる文字列
入力
入力は以下の形式で標準入力から与えられる。
S
出力
S に対して、問題文中に記された手順を行った後に得られる文字列を出力せよ。
入力例 1
WACWA
出力例 1
ACCAC
最初、文字列は S=WACWA
です。
この文字列には 1 文字目から 2 文字目、および、4 文字目から 5 文字目の 2 ヶ所に WA
が部分文字列として含まれています。
1 回目の操作では、そのうち先頭のもの、すなわち 1 文字目から 2 文字目の部分を AC
に置換し、文字列は ACCWA
となります。
1 回目の操作後の文字列には 4 文字目から 5 文字目の 1 ヶ所にのみ WA
が部分文字列として含まれているため、2 回目の操作ではこれを AC
に置換し、文字列は ACCAC
となります。
ACCAC
は WA
を部分文字列として含まないため、手順は終了します。よって、ACCAC
を出力します。
入力例 2
WWA
出力例 2
ACC
最初、文字列は S=WWA
です。
この文字列には 2 文字目から 3 文字目の 1 ヶ所にのみ WA
が部分文字列として含まれているため、1 回目の操作ではこれを AC
に置換し、文字列は WAC
となります。
次に、1 回目の操作後の文字列は 1 文字目から 2 文字目の 1 ヶ所にのみ WA
が部分文字列として含まれているため、2 回目の操作ではこれを AC
に置換し、文字列は ACC
となります。
ACC
は WA
を部分文字列として含まないため、手順は終了します。よって、ACC
を出力します。
入力例 3
WWWWW
出力例 3
WWWWW
S には最初から WA
が部分文字列として含まれてないため、操作は 1 回も行われず手順は終了します。よって、WWWWW
を出力します。
Score : 300 points
Problem Statement
You are given a string S consisting of uppercase English letters.
Apply the following procedure to S, and then output the resulting string:
As long as the string contains
WA
as a (contiguous) substring, repeat the following operation:
- Among all occurrences of
WA
in the string, replace the leftmost one withAC
.
It can be proved under the constraints of this problem that this operation is repeated at most a finite number of times.
Constraints
- S is a string of uppercase English letters with length between 1 and 3\times 10^5, inclusive.
Input
The input is given from Standard Input in the following format:
S
Output
Print the resulting string after performing the procedure described in the problem statement on S.
Sample Input 1
WACWA
Sample Output 1
ACCAC
Initially, the string is S= WACWA
.
This string contains WA
as a substring in two places: from the 1st to the 2nd character, and from the 4th to the 5th character.
In the first operation, we replace the leftmost occurrence (the substring from the 1st to the 2nd character) with AC
, resulting in ACCWA
.
After the first operation, the string contains WA
as a substring in exactly one place: from the 4th to the 5th character.
In the second operation, we replace it with AC
, resulting in ACCAC
.
Since ACCAC
does not contain WA
as a substring, the procedure ends. Therefore, we output ACCAC
.
Sample Input 2
WWA
Sample Output 2
ACC
Initially, the string is S= WWA
.
This string contains WA
as a substring in exactly one place: from the 2nd to the 3rd character.
In the first operation, we replace it with AC
, resulting in WAC
.
Then, after the first operation, the string contains WA
in exactly one place: from the 1st to the 2nd character.
In the second operation, we replace it with AC
, resulting in ACC
.
Since ACC
does not contain WA
as a substring, the procedure ends. Therefore, we output ACC
.
Sample Input 3
WWWWW
Sample Output 3
WWWWW
Since S does not contain WA
as a substring from the start, no operations are performed and the procedure ends immediately. Therefore, we output WWWWW
.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 250 点
問題文
長さ N の整数列 A,B が与えられます。1 以上 N 以下の整数 i,j を選んで、 A_i + B_j の値を最大化してください。
制約
- 1 \leq N \leq 5 \times 10^5
- |A_i| \leq 10^9\,(i=1,2,\dots,N)
- |B_j| \leq 10^9\,(j=1,2,\dots,N)
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N A_1 A_2 \dots A_N B_1 B_2 \dots B_N
出力
A_i + B_j の最大値を出力せよ。
入力例 1
2 -1 5 3 -7
出力例 1
8
(i,j)=(1,1),(1,2),(2,1),(2,2) に対する A_i+B_j の値はそれぞれ 2,-8,8,-2 であり、(i,j)=(2,1) が最大値 8 を達成します。
入力例 2
6 15 12 3 -13 -1 -19 7 17 -13 -10 18 4
出力例 2
33
Score : 250 points
Problem Statement
You are given two integer sequences A and B, each of length N. Choose integers i, j (1 \leq i, j \leq N) to maximize the value of A_i + B_j.
Constraints
- 1 \leq N \leq 5 \times 10^5
- |A_i| \leq 10^9 (i=1,2,\dots,N)
- |B_j| \leq 10^9 (j=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_N B_1 B_2 \dots B_N
Output
Print the maximum possible value of A_i + B_j.
Sample Input 1
2 -1 5 3 -7
Sample Output 1
8
For (i,j) = (1,1), (1,2), (2,1), (2,2), the values of A_i + B_j are 2, -8, 8, -2 respectively, and (i,j) = (2,1) achieves the maximum value 8.
Sample Input 2
6 15 12 3 -13 -1 -19 7 17 -13 -10 18 4
Sample Output 2
33
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 400 点
問題文
整数 N が与えられます。以下の条件を満たす N 以下の正整数の組 (i,j) の個数を求めてください。
- i \times j は平方数である。
制約
- 1 \le N \le 2 \times 10^5
- N は整数である。
入力
入力は以下の形式で標準入力から与えられる。
N
出力
答えを出力せよ。
入力例 1
4
出力例 1
6
(1,1),(1,4),(2,2),(3,3),(4,1),(4,4) の 6 個が条件を満たします。
(2,3) は 2 \times 3 =6 が平方数でないため条件を満たしません。
入力例 2
254
出力例 2
896
Score : 400 points
Problem Statement
You are given an integer N. Find the number of pairs (i,j) of positive integers at most N that satisfy the following condition:
- i \times j is a square number.
Constraints
- 1 \le N \le 2 \times 10^5
- N is an integer.
Input
Input is given from Standard Input in the following format:
N
Output
Print the answer.
Sample Input 1
4
Sample Output 1
6
The six pairs (1,1),(1,4),(2,2),(3,3),(4,1),(4,4) satisfy the condition.
On the other hand, (2,3) does not, since 2 \times 3 =6 is not a square number.
Sample Input 2
254
Sample Output 2
896
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 450 点
問題文
H 行 W 列のグリッドがあり、はじめすべてのマスは色 0 で塗られています。
これから i = 1, 2, \ldots, M の順で以下の操作を行います。
-
T_i = 1 のとき、A_i 行目のマスをすべて色 X_i に塗り替える
-
T_i = 2 のとき、A_i 列目のマスをすべて色 X_i に塗り替える
すべての操作を終えたとき、最終的に色 i で塗られたマスが存在するような各色 i についてその色で塗られたマスの個数を求めてください。
制約
- 1 \leq H, W, M \leq 2 \times 10^5
- T_i \in \lbrace 1, 2 \rbrace
- T_i = 1 なる i に対して 1 \leq A_i \leq H
- T_i = 2 なる i に対して 1 \leq A_i \leq W
- 0 \leq X_i \leq 2 \times 10^5
- 入力される値はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
H W M T_1 A_1 X_1 T_2 A_2 X_2 \vdots T_M A_M X_M
出力
色 i で塗られたマスが存在するような整数 i の個数を K として、K + 1 行出力せよ。
1 行目には K の値を出力せよ。
2 行目以降には色 i で塗られたマスが存在するような各色 i について、色の番号およびその色で塗られたマスの個数を出力せよ。
具体的には、i + 1 (1 \leq i \leq K) 行目には色の番号 c_i と色 c_i で塗られたマスの個数 x_i をこの順に空白区切りで出力せよ。
ただし、色の番号は昇順で出力せよ。すなわち、c_1 < c_2 < \ldots < c_K を満たすように出力せよ。また、x_i > 0 が必要であることに注意せよ。
入力例 1
3 4 4 1 2 5 2 4 0 1 3 3 1 3 2
出力例 1
3 0 5 2 4 5 3
操作によってグリッドの各マスの色は以下のように変化します。
0000 0000 0000 0000 0000 0000 → 5555 → 5550 → 5550 → 5550 0000 0000 0000 3333 2222
最終的に色 0 で塗られたマスは 5 つ、色 2 で塗られたマスは 4 つ、色 5 で塗られたマスは 3 つです。
入力例 2
1 1 5 1 1 1 1 1 10 2 1 100 1 1 1000 2 1 10000
出力例 2
1 10000 1
入力例 3
5 5 10 1 1 1 1 2 2 1 3 3 1 4 4 1 5 5 2 1 6 2 2 7 2 3 8 2 4 9 2 5 10
出力例 3
5 6 5 7 5 8 5 9 5 10 5
Score: 450 points
Problem Statement
There is a grid with H rows and W columns. Initially, all cells are painted with color 0.
You will perform the following operations in the order i = 1, 2, \ldots, M.
-
If T_i = 1, repaint all cells in the A_i-th row with color X_i.
-
If T_i = 2, repaint all cells in the A_i-th column with color X_i.
After all operations are completed, for each color i that exists on the grid, find the number of cells that are painted with color i.
Constraints
- 1 \leq H, W, M \leq 2 \times 10^5
- T_i \in \lbrace 1, 2 \rbrace
- 1 \leq A_i \leq H for each i such that T_i = 1,
- 1 \leq A_i \leq W for each i such that T_i = 2.
- 0 \leq X_i \leq 2 \times 10^5
- All input values are integers.
Input
The input is given from Standard Input in the following format:
H W M T_1 A_1 X_1 T_2 A_2 X_2 \vdots T_M A_M X_M
Output
Let K be the number of distinct integers i such that there are cells painted with color i. Print K + 1 lines.
The first line should contain the value of K.
The second and subsequent lines should contain, for each color i that exists on the grid, the color number i and the number of cells painted with that color.
Specifically, the (i + 1)-th line (1 \leq i \leq K) should contain the color number c_i and the number of cells x_i painted with color c_i, in this order, separated by a space.
Here, print the color numbers in ascending order. That is, ensure that c_1 < c_2 < \ldots < c_K. Note also that x_i > 0 is required.
Sample Input 1
3 4 4 1 2 5 2 4 0 1 3 3 1 3 2
Sample Output 1
3 0 5 2 4 5 3
The operations will change the colors of the cells in the grid as follows:
0000 0000 0000 0000 0000 0000 → 5555 → 5550 → 5550 → 5550 0000 0000 0000 3333 2222
Eventually, there are five cells painted with color 0, four with color 2, and three with color 5.
Sample Input 2
1 1 5 1 1 1 1 1 10 2 1 100 1 1 1000 2 1 10000
Sample Output 2
1 10000 1
Sample Input 3
5 5 10 1 1 1 1 2 2 1 3 3 1 4 4 1 5 5 2 1 6 2 2 7 2 3 8 2 4 9 2 5 10
Sample Output 3
5 6 5 7 5 8 5 9 5 10 5
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 550 点
問題文
N 個の長さ M の数列 A_1, A_2, \ldots, A_N があります。i 番目の数列は M 個の整数 A_{i,1}, A_{i,2}, \ldots, A_{i,M} で表されます。
それぞれの長さが M の数列 X,Y について、X_i = Y_i となるような i(1 \leq i \leq M) の個数が奇数であるときに、X と Y は似ていると言います。
1 \leq i < j \leq N を満たす整数の組 (i,j) のうち、A_i と A_j が似ているものの個数を求めてください。
制約
- 1 \leq N \leq 2000
- 1 \leq M \leq 2000
- 1 \leq A_{i,j} \leq 999
- 入力は全て整数である。
入力
入力は以下の形式で標準入力から与えられる。
N M A_{1,1} A_{1,2} \ldots A_{1,M} A_{2,1} A_{2,2} \ldots A_{2,M} \vdots A_{N,1} A_{N,2} \ldots A_{N,M}
出力
答えを整数として出力せよ。
入力例 1
3 3 1 2 3 1 3 4 2 3 4
出力例 1
1
(i,j) = (1,2) は条件を満たします。なぜならば、A_{1,k} = A_{2,k} となるような k は k=1 の 1 個だけだからです。
(i,j) = (1,3) ,(2,3) は条件を満たさないため、条件を満たす (i,j) の組は (1,2) だけです。
入力例 2
6 5 8 27 27 10 24 27 8 2 4 5 15 27 26 17 24 27 27 27 27 27 27 7 22 11 27 19 27 27 27 27
出力例 2
5
Score: 550 points
Problem Statement
There are N sequences of length M, denoted as A_1, A_2, \ldots, A_N. The i-th sequence is represented by M integers A_{i,1}, A_{i,2}, \ldots, A_{i,M}.
Two sequences X and Y of length M are said to be similar if and only if the number of indices i (1 \leq i \leq M) such that X_i = Y_i is odd.
Find the number of pairs of integers (i,j) satisfying 1 \leq i < j \leq N such that A_i and A_j are similar.
Constraints
- 1 \leq N \leq 2000
- 1 \leq M \leq 2000
- 1 \leq A_{i,j} \leq 999
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N M A_{1,1} A_{1,2} \ldots A_{1,M} A_{2,1} A_{2,2} \ldots A_{2,M} \vdots A_{N,1} A_{N,2} \ldots A_{N,M}
Output
Print the answer as an integer.
Sample Input 1
3 3 1 2 3 1 3 4 2 3 4
Sample Output 1
1
The pair (i,j) = (1,2) satisfies the condition because there is only one index k such that A_{1,k} = A_{2,k}, which is k=1.
The pairs (i,j) = (1,3), (2,3) do not satisfy the condition, making (1,2) the only pair that does.
Sample Input 2
6 5 8 27 27 10 24 27 8 2 4 5 15 27 26 17 24 27 27 27 27 27 27 7 22 11 27 19 27 27 27 27
Sample Output 2
5