Time Limit: 2 sec / Memory Limit: 1024 MB
配点 : 100 点
問題文
関数 f を f(x) = x^2 + 2x + 3 と定義します。
整数 t が入力されるので、 f(f(f(t)+t)+f(f(t))) を求めてください。
ただし、答えは 2 \times 10^9 以下の整数であることが保証されます。
制約
- t は 0 以上 10 以下の整数である
入力
入力は以下の形式で標準入力から与えられる。
t
出力
答えを整数として出力せよ。
入力例 1
0
出力例 1
1371
答えは以下の手順によって計算されます。
- f(t) = t^2 + 2t + 3 = 0 \times 0 + 2 \times 0 + 3 = 3
- f(t)+t = 3 + 0 = 3
- f(f(t)+t) = f(3) = 3 \times 3 + 2 \times 3 + 3 = 18
- f(f(t)) = f(3) = 18
- f(f(f(t)+t)+f(f(t))) = f(18+18) = f(36) = 36 \times 36 + 2 \times 36 + 3 = 1371
入力例 2
3
出力例 2
722502
入力例 3
10
出力例 3
1111355571
Score : 100 points
Problem Statement
Let us define a function f as f(x) = x^2 + 2x + 3.
Given an integer t, find f(f(f(t)+t)+f(f(t))).
Here, it is guaranteed that the answer is an integer not greater than 2 \times 10^9.
Constraints
- t is an integer between 0 and 10 (inclusive).
Input
Input is given from Standard Input in the following format:
t
Output
Print the answer as an integer.
Sample Input 1
0
Sample Output 1
1371
The answer is computed as follows.
- f(t) = t^2 + 2t + 3 = 0 \times 0 + 2 \times 0 + 3 = 3
- f(t)+t = 3 + 0 = 3
- f(f(t)+t) = f(3) = 3 \times 3 + 2 \times 3 + 3 = 18
- f(f(t)) = f(3) = 18
- f(f(f(t)+t)+f(f(t))) = f(18+18) = f(36) = 36 \times 36 + 2 \times 36 + 3 = 1371
Sample Input 2
3
Sample Output 2
722502
Sample Input 3
10
Sample Output 3
1111355571
Time Limit: 2 sec / Memory Limit: 1024 MB
配点 : 200 点
問題文
二次元平面上に N 個の点があります。i 個目の点の座標は (x_i,y_i) です。
この中から 2 個の点を選ぶとき、それらを結ぶ線分の長さの最大値を求めてください。
制約
- 2 \leq N \leq 100
- -1000 \leq x_i,y_i \leq 1000
- (x_i,y_i) \neq (x_j,y_j)\ (i \neq j)
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N x_1 y_1 x_2 y_2 \hspace{0.4cm} \vdots x_N y_N
出力
2 点を結ぶ線分の長さの最大値を出力せよ。
想定解との絶対誤差または相対誤差が 10^{-6} 以下であれば正解とみなされる。
入力例 1
3 0 0 0 1 1 1
出力例 1
1.4142135624
1 個目の点と 3 個目の点を選んだときそれらを結ぶ線分の長さは \sqrt 2 = 1.41421356237\dots となり、これが最大です。
入力例 2
5 315 271 -2 -621 -205 -511 -952 482 165 463
出力例 2
1455.7159750446
Score : 200 points
Problem Statement
There are N points in a two-dimensional plane. The coordinates of the i-th point are (x_i,y_i).
Find the maximum length of a segment connecting two of these points.
Constraints
- 2 \leq N \leq 100
- -1000 \leq x_i,y_i \leq 1000
- (x_i,y_i) \neq (x_j,y_j)\ (i \neq j)
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N x_1 y_1 x_2 y_2 \hspace{0.4cm} \vdots x_N y_N
Output
Print the maximum length of a segment connecting two of the points.
Your answer will be considered correct when the absolute or relative error from the judge's answer is at most 10^{-6}.
Sample Input 1
3 0 0 0 1 1 1
Sample Output 1
1.4142135624
For the 1-st and 3-rd points, the length of the segment connecting them is \sqrt 2 = 1.41421356237\dots, which is the maximum length.
Sample Input 2
5 315 271 -2 -621 -205 -511 -952 482 165 463
Sample Output 2
1455.7159750446
Time Limit: 2 sec / Memory Limit: 1024 MB
配点 : 300 点
問題文
10 進法で表記したときに 0,2 のみからなる正整数のうち、 K 番目に小さいものを求めてください。
制約
- K は 1 以上 10^{18} 以下の整数
入力
入力は以下の形式で標準入力から与えられる。
K
出力
答えを整数として出力せよ。
ただし、たとえ答えが大きな整数であっても、求める答えを正確に整数として出力する必要がある。たとえば、 2.34e+22
のような指数表記や、 0523
のような先頭に不要な 0 を付けたような表記は許されない。
入力例 1
3
出力例 1
22
10 進法で表記した時に 0,2 のみからなる正整数を小さい方から並べると、 2,20,22,\dots となります。
このうち K=3 番目である 22 を出力してください。
入力例 2
11
出力例 2
2022
入力例 3
923423423420220108
出力例 3
220022020000202020002022022000002020002222002200002022002200
たとえ答えが大きな整数であっても、求める答えを正確に整数として出力する必要があることに注意してください。
Score : 300 points
Problem Statement
Among the positive integers that consist of 0's and 2's when written in base 10, find the K-th smallest integer.
Constraints
- K is an integer between 1 and 10^{18} (inclusive).
Input
Input is given from Standard Input in the following format:
K
Output
Print the answer as an integer.
Here, the exact value must be printed as an integer, even if it is big. Exponential notations such as 2.34e+22
, for example, or unnecessary leading zeros such as 0523
are not allowed.
Sample Input 1
3
Sample Output 1
22
The positive integers that consist of 0's and 2's when written in base 10 are 2,20,22,\dots in ascending order.
The (K=) 3-rd of them, which is 22, should be printed.
Sample Input 2
11
Sample Output 2
2022
Sample Input 3
923423423420220108
Sample Output 3
220022020000202020002022022000002020002222002200002022002200
Note that the exact value of the answer must be printed as an integer, even if it is big.
Time Limit: 2 sec / Memory Limit: 1024 MB
配点 : 400 点
問題文
(1,2,\ldots,N) の順列 P=(P_1,P_2,\ldots,P_N)、および正整数 K が与えられます。
i=K,K+1,\ldots,N について、以下を求めてください。
- P の先頭 i 項のうち、K 番目に大きい値
制約
- 1 \leq K \leq N \leq 5 \times 10^5
- (P_1,P_2,\ldots,P_N) は (1,2,\ldots,N) の並び替えによって得られる
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N K P_1 P_2 \ldots P_N
出力
i=K,K+1,\ldots,N についてこの順に、問題文中で問われている値を改行区切りで出力せよ。
入力例 1
3 2 1 2 3
出力例 1
1 2
- P の先頭 2 項、すなわち (P_1,P_2)=(1,2) の中で K=2 番目に大きい値は 1 となります。
- P の先頭 3 項、すなわち (P_1,P_2,P_3)=(1,2,3) の中で K=2 番目に大きい値は 2 となります。
入力例 2
11 5 3 7 2 5 11 6 1 9 8 10 4
出力例 2
2 3 3 5 6 7 7
Score : 400 points
Problem Statement
Given are a permutation P=(P_1,P_2,\ldots,P_N) of (1,2,\ldots,N) and a positive integer K.
For each i=K,K+1,\ldots,N, find the following.
- The K-th greatest value among the first i terms of P.
Constraints
- 1 \leq K \leq N \leq 5 \times 10^5
- (P_1,P_2,\ldots,P_N) is a permutation of (1,2,\ldots,N).
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N K P_1 P_2 \ldots P_N
Output
For each i=K, K+1, \ldots, N, in this order, print the specified value in Problem Statement, separated by newlines.
Sample Input 1
3 2 1 2 3
Sample Output 1
1 2
- The (K=) 2-nd greatest value among the first 2 terms of P, (P_1,P_2)=(1,2), is 1.
- The (K=) 2-nd greatest value among the first 3 terms of P, (P_1,P_2,P_3)=(1,2,3), is 2.
Sample Input 2
11 5 3 7 2 5 11 6 1 9 8 10 4
Sample Output 2
2 3 3 5 6 7 7
Time Limit: 2 sec / Memory Limit: 1024 MB
配点 : 500 点
問題文
以下の条件を満たす正の整数 n を、 等差数 と呼びます。
- (n を先頭に余計な 0 を付けずに 10 進法で表記した際、) n の上から i 桁目を d_i とする。このとき、 n が k 桁の整数であったとすると、 (d_2-d_1)=(d_3-d_2)=\dots=(d_k-d_{k-1}) が成立する。
- この条件は、「 数列 (d_1,d_2,\dots,d_k) が等差数列である」と言い換えることができる。
- 但し、 n が 1 桁の整数である時、 n は等差数であるものとする。
たとえば、 234,369,86420,17,95,8,11,777 は等差数ですが、 751,919,2022,246810,2356 は等差数ではありません。
等差数のうち、 X 以上で最小のものを求めてください。
制約
- X は 1 以上 10^{17} 以下の整数である
入力
入力は以下の形式で標準入力から与えられる。
X
出力
答えを整数として出力せよ。
入力例 1
152
出力例 1
159
152 以上で最小の等差数は 159 です。
入力例 2
88
出力例 2
88
X 自身が等差数である場合もあります。
入力例 3
8989898989
出力例 3
9876543210
Score : 500 points
Problem Statement
Let us call a positive integer n that satisfies the following condition an arithmetic number.
- Let d_i be the i-th digit of n from the top (when n is written in base 10 without unnecessary leading zeros.) Then, (d_2-d_1)=(d_3-d_2)=\dots=(d_k-d_{k-1}) holds, where k is the number of digits in n.
- This condition can be rephrased into the sequence (d_1,d_2,\dots,d_k) being arithmetic.
- If n is a 1-digit integer, it is assumed to be an arithmetic number.
For example, 234,369,86420,17,95,8,11,777 are arithmetic numbers, while 751,919,2022,246810,2356 are not.
Find the smallest arithmetic number not less than X.
Constraints
- X is an integer between 1 and 10^{17} (inclusive).
Input
Input is given from Standard Input in the following format:
X
Output
Print the answer as an integer.
Sample Input 1
152
Sample Output 1
159
The smallest arithmetic number not less than 152 is 159.
Sample Input 2
88
Sample Output 2
88
X itself may be an arithmetic number.
Sample Input 3
8989898989
Sample Output 3
9876543210
Time Limit: 2 sec / Memory Limit: 1024 MB
配点 : 500 点
問題文
文字列 S が与えられます。S の空でない、連続するとは限らない部分列を並び替えて得られる文字列は何種類ありますか?
答えは非常に大きくなる場合があるので、998244353 で割ったあまりを出力してください。
制約
- S は英小文字のみからなる長さ 1 以上 5000 以下の文字列
入力
入力は以下の形式で標準入力から与えられる。
S
出力
S の部分列を並び替えて得られる文字列の種類数を 998244353 で割ったあまりを出力せよ。
入力例 1
aab
出力例 1
8
S の部分列を並び替えて得られる文字列は、a
, b
, aa
, ab
, ba
, aab
, aba
, baa
の 8 種類です。
入力例 2
aaa
出力例 2
3
入力例 3
abcdefghijklmnopqrstuvwxyz
出力例 3
149621752
998244353 で割ったあまりを出力することに注意してください。
Score : 500 points
Problem Statement
Given is a string S. How many different strings can be obtained as a permutation of a non-empty, not necessarily contiguous subsequence of S?
Since the count can be enormous, print it modulo 998244353.
Constraints
- S is a string of length 1 and 5000 (inclusive) consisting of lowercase English letters.
Input
Input is given from Standard Input in the following format:
S
Output
Print the number of different strings that can be obtained as a permutation of a subsequence of S, modulo 998244353.
Sample Input 1
aab
Sample Output 1
8
There are 8 different strings that can be obtained as a permutation of a subsequence of S: a
, b
, aa
, ab
, ba
, aab
, aba
, baa
.
Sample Input 2
aaa
Sample Output 2
3
Sample Input 3
abcdefghijklmnopqrstuvwxyz
Sample Output 3
149621752
Be sure to print the count modulo 998244353.
Time Limit: 2 sec / Memory Limit: 1024 MB
配点 : 600 点
問題文
長さ N の数列 A が与えられます。
A を空でない、連続した部分列 B_1,B_2,\ldots,B_k に切り分ける方法は 2^{N-1} 通りありますが、そのすべてについて以下の値を求め、総和を 998244353 で割ったあまりを出力してください。
- \prod_{i=1}^{k} (\max(B_i)-\min(B_i))
ここである数列 B_i=(B_{i,1},B_{i,2},\ldots,B_{i,j}) について、\max(B_i) を B_i に含まれる要素の最大値、\min(B_i) を B_i に含まれる要素の最小値と定義します。
制約
- 1 \leq N \leq 3 \times 10^5
- 1 \leq A_i \leq 10^9
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N A_1 A_2 \ldots A_N
出力
求めた値の総和を 998244353 で割ったあまりを出力せよ。
入力例 1
3 1 2 3
出力例 1
2
A=(1,2,3) を空でない連続した部分列に切り分ける方法は以下の 4 通りです。
- (1) と (2) と (3)
- (1) と (2,3)
- (1,2) と (3)
- (1,2,3)
それぞれにおける \prod_{i=1}^{k} (\max(B_i)-\min(B_i)) は順に 0, 0, 0, 2 であるため、その総和である 2 を出力します。
入力例 2
4 1 10 1 10
出力例 2
90
入力例 3
10 699498050 759726383 769395239 707559733 72435093 537050110 880264078 699299140 418322627 134917794
出力例 3
877646588
998244353 で割ったあまりを出力することに注意してください。
Score : 600 points
Problem Statement
Given is a sequence A of N numbers.
There are 2^{N-1} ways to divide A into non-empty contiguous subsequences B_1,B_2,\ldots,B_k. Find the value below for each of those ways, and print the sum, modulo 998244353, of those values.
- \prod_{i=1}^{k} (\max(B_i)-\min(B_i))
Here, for a sequence B_i=(B_{i,1},B_{i,2},\ldots,B_{i,j}), \max(B_i) and \min(B_i) are defined to be the maximum and minimum values of an element of B_i, respectively.
Constraints
- 1 \leq N \leq 3 \times 10^5
- 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 A_1 A_2 \ldots A_N
Output
Print the sum, modulo 998244353, of the values found.
Sample Input 1
3 1 2 3
Sample Output 1
2
There are 4 ways to divide A=(1,2,3) into non-empty contiguous subsequences, as follows.
- (1), (2), (3)
- (1), (2,3)
- (1,2), (3)
- (1,2,3)
\prod_{i=1}^{k} (\max(B_i)-\min(B_i)) for these divisions are 0, 0, 0, 2, respectively. The sum of them, 2, should be printed.
Sample Input 2
4 1 10 1 10
Sample Output 2
90
Sample Input 3
10 699498050 759726383 769395239 707559733 72435093 537050110 880264078 699299140 418322627 134917794
Sample Output 3
877646588
Be sure to print the sum modulo 998244353.
Time Limit: 4 sec / Memory Limit: 1024 MB
配点 : 600 点
問題文
1 から N までの番号のついた N 個の整数の組 (x_i,y_i) と、整数 K が与えられます。
以下の条件を満たす整数の組 (p,q) を「出力」で指定する形式に従ってすべて列挙してください。
- 1 \le p < q \le N
- \sqrt{(x_p-x_q)^2+(y_p-y_q)^2} \le K
ただし、そのような整数の組が 4 \times 10^5 組以下であることは保証されます。
制約
- 入力はすべて整数
- 1 \le N \le 2 \times 10^5
- 1 \le K \le 1.5 \times 10^9
- 0 \le x_i,y_i \le 10^9
- 列挙すべき整数の組は 4 \times 10^5 組以下である
入力
入力は以下の形式で標準入力から与えられる。
N K x_1 y_1 x_2 y_2 \vdots x_N y_N
出力
以下の形式で出力せよ。
M p_1 q_1 p_2 q_2 \vdots p_M q_M
まず、 1 行目に整数 M を出力せよ。 M は出力する整数の組の個数を表す。
続く M 行に、列挙するべき整数の組 (p_i,q_i) を 1 行に 1 つずつ空白区切りで、 辞書順で 出力せよ。
ただし、整数の組 (a,b),(c,d) が以下の条件のどちらかを満たすとき、またその時に限り、 整数の組 (a,b) が整数の組 (c,d) より辞書順で前であるとする。
- a<c である。
- a=c であり、かつ b<d である。
入力例 1
6 5 2 0 2 2 3 4 0 0 5 5 8 3
出力例 1
9 1 2 1 3 1 4 2 3 2 4 2 5 3 4 3 5 5 6
条件を満たす整数の組は以下の 9 個なので、これを出力形式に従って出力して下さい。
(1,2),(1,3),(1,4),(2,3),(2,4),(2,5),(3,4),(3,5),(5,6)
入力例 2
2 1414213562 0 0 1000000000 1000000000
出力例 2
0
条件を満たす整数の組が 0 組である場合もあります。
入力例 3
10 150 300 300 300 400 300 500 400 300 400 400 400 400 400 500 500 300 500 400 500 500
出力例 3
29 1 2 1 4 1 5 1 6 2 3 2 4 2 5 2 6 2 7 3 5 3 6 3 7 4 5 4 6 4 8 4 9 5 6 5 7 5 8 5 9 5 10 6 7 6 8 6 9 6 10 7 9 7 10 8 9 9 10
x_i=x_j かつ y_i=y_j であるような整数の組 (i,j) (i < j) が存在する場合もあります。
Score : 600 points
Problem Statement
Given are N pairs of integers (x_i,y_i), numbered 1 to N, and an integer K.
List all pairs of integers (p,q) that satisfy the conditions below, in the format specified in Output.
- 1 \le p < q \le N
- \sqrt{(x_p-x_q)^2+(y_p-y_q)^2} \le K
Here, it is guaranteed that there are at most 4 \times 10^5 such pairs of integers.
Constraints
- All values in input are integers.
- 1 \le N \le 2 \times 10^5
- 1 \le K \le 1.5 \times 10^9
- 0 \le x_i,y_i \le 10^9
- There are at most 4 \times 10^5 pairs of integers that should be listed.
Input
Input is given from Standard Input in the following format:
N K x_1 y_1 x_2 y_2 \vdots x_N y_N
Output
Print the answer in the following format.
M p_1 q_1 p_2 q_2 \vdots p_M q_M
The first line should contain an integer M, representing the number of pairs of integers to be listed.
The subsequent M lines should contain the pairs of integers to be listed (p_i,q_i) in lexicographical order, each in its own line, separated by a space.
Here, a pair of integers (a,b) comes before a pair of integers (c,d) if and only if one of the following conditions is satisfied.
- a<c.
- a=c and b<d.
Sample Input 1
6 5 2 0 2 2 3 4 0 0 5 5 8 3
Sample Output 1
9 1 2 1 3 1 4 2 3 2 4 2 5 3 4 3 5 5 6
There are 9 pairs of integers that satisfy the conditions, which should be printed in the specified format.
(1,2),(1,3),(1,4),(2,3),(2,4),(2,5),(3,4),(3,5),(5,6)
Sample Input 2
2 1414213562 0 0 1000000000 1000000000
Sample Output 2
0
There may be zero pairs of integers that satisfy the conditions.
Sample Input 3
10 150 300 300 300 400 300 500 400 300 400 400 400 400 400 500 500 300 500 400 500 500
Sample Output 3
29 1 2 1 4 1 5 1 6 2 3 2 4 2 5 2 6 2 7 3 5 3 6 3 7 4 5 4 6 4 8 4 9 5 6 5 7 5 8 5 9 5 10 6 7 6 8 6 9 6 10 7 9 7 10 8 9 9 10
There may be pairs of integers (i,j) (i < j) such that x_i=x_j and y_i=y_j.