実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 300 点
問題文
整数 N が与えられるので、以下の問題を解いてください。
f(x)= ( x 以下の正整数で、 x と桁数が同じものの数) とします。
f(1)+f(2)+\dots+f(N) を 998244353 で割った余りを求めてください。
制約
- N は整数
- 1 \le N < 10^{18}
入力
入力は以下の形式で標準入力から与えられる。
N
出力
答えを整数として出力せよ。
入力例 1
16
出力例 1
73
- 1 以上 9 以下の正整数 x について、 x 以下の整数で、 x と桁数が同じものは 1,2,\dots,x です。
- これより、 f(1)=1,f(2)=2,...,f(9)=9 となります。
- 10 以上 16 以下の正整数 x について、 x 以下の整数で、 x と桁数が同じものは 10,11,\dots,x です。
- これより、 f(10)=1,f(11)=2,...,f(16)=7 となります。
結局、求める答えは 73 です。
入力例 2
238
出力例 2
13870
入力例 3
999999999999999999
出力例 3
762062362
998244353 で割った余りを求めることに注意してください。
Score : 300 points
Problem Statement
Given an integer N, solve the following problem.
Let f(x)= (The number of positive integers at most x with the same number of digits as x).
Find f(1)+f(2)+\dots+f(N) modulo 998244353.
Constraints
- N is an integer.
- 1 \le N < 10^{18}
Input
Input is given from Standard Input in the following format:
N
Output
Print the answer as an integer.
Sample Input 1
16
Sample Output 1
73
- For a positive integer x between 1 and 9, the positive integers at most x with the same number of digits as x are 1,2,\dots,x.
- Thus, we have f(1)=1,f(2)=2,...,f(9)=9.
- For a positive integer x between 10 and 16, the positive integers at most x with the same number of digits as x are 10,11,\dots,x.
- Thus, we have f(10)=1,f(11)=2,...,f(16)=7.
The final answer is 73.
Sample Input 2
238
Sample Output 2
13870
Sample Input 3
999999999999999999
Sample Output 3
762062362
Be sure to find the sum modulo 998244353.
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 300 点
問題文
整数 N が与えられます。N の各桁の数字を取り出して並べ(並べる順序は好きに変えてよい)、2 つの正整数に分離することを考えましょう。
例えば、123 という整数に対しては以下の 6 通りの分離の仕方が考えられます。
- 12 と 3
- 21 と 3
- 13 と 2
- 31 と 2
- 23 と 1
- 32 と 1
なお、ここで分離されたあとの 2 整数に leading zero が含まれていてはなりません。例えば、101 という整数を 1 と 01 の 2 つに分離することはできません。また上述の「正整数に分離する」という条件より、101 を 11 と 0 の 2 つに分離することもできません。
適切に N を分離したとき、分離後の 2 数の積の最大値はいくらになりますか?
制約
- N は 1 以上 10^9 以下の整数
- N には 0 でない桁が 2 つ以上含まれる
入力
入力は以下の形式で標準入力から与えられる。
N
出力
分離後の 2 数の積の最大値を出力せよ。
入力例 1
123
出力例 1
63
問題文中にある通り、以下の 6 通りの分離の仕方が考えられます。
- 12 と 3
- 21 と 3
- 13 と 2
- 31 と 2
- 23 と 1
- 32 と 1
積はそれぞれ 36, 63, 26, 62, 23, 32 であり、この中の最大値は 63 です。
入力例 2
1010
出力例 2
100
考えられる分離の仕方は以下の 2 通りです。
- 100 と 1
- 10 と 10
いずれの場合にも積は 100 となります。
入力例 3
998244353
出力例 3
939337176
Score : 300 points
Problem Statement
You are given an integer N. Consider permuting the digits in N and separate them into two positive integers.
For example, for the integer 123, there are six ways to separate it, as follows:
- 12 and 3,
- 21 and 3,
- 13 and 2,
- 31 and 2,
- 23 and 1,
- 32 and 1.
Here, the two integers after separation must not contain leading zeros. For example, it is not allowed to separate the integer 101 into 1 and 01. Additionally, since the resulting integers must be positive, it is not allowed to separate 101 into 11 and 0, either.
What is the maximum possible product of the two resulting integers, obtained by the optimal separation?
Constraints
- N is an integer between 1 and 10^9 (inclusive).
- N contains two or more digits that are not 0.
Input
Input is given from Standard Input in the following format:
N
Output
Print the maximum possible product of the two integers after separation.
Sample Input 1
123
Sample Output 1
63
As described in Problem Statement, there are six ways to separate it:
- 12 and 3,
- 21 and 3,
- 13 and 2,
- 31 and 2,
- 23 and 1,
- 32 and 1.
The products of these pairs, in this order, are 36, 63, 26, 62, 23, 32, with 63 being the maximum.
Sample Input 2
1010
Sample Output 2
100
There are two ways to separate it:
- 100 and 1,
- 10 and 10.
In either case, the product is 100.
Sample Input 3
998244353
Sample Output 3
939337176
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 400 点
問題文
高橋君は 2 以上の整数が書かれた N 個のボールを持っており、これらを細長い筒の中に落としていきます。i \, (1 \leq i \leq N) 回目には、a_i が書かれたボールを落とします。
ボールは特殊な材質でできており、筒の中において k \, (k \geq 2) が書かれたボールが k 個連続すると、それら k 個のボールは全て消えてしまいます。
各 i \, (1 \leq i \leq N) について、i 個目のボールを筒の中に落とした後、筒の中に何個のボールがあるか求めてください。
制約
- 1 \leq N \leq 2 \times 10^5
- 2 \leq a_i \leq 2 \times 10^5 \, (1 \leq i \leq N)
- 入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N a_1 \ldots a_N
出力
N 行出力せよ。i \, (1 \leq i \leq N) 行目には、i 個目のボールを筒の中に落とした後、筒の中にあるボールの個数を出力せよ。
入力例 1
5 3 2 3 2 2
出力例 1
1 2 3 4 3
筒の中は次のように変化します。
- 1 個目のボールを落とす。筒の中にあるボールに書かれた整数は 3 である。
- 2 個目のボールを落とす。筒の中にあるボールに書かれた整数は下から順に 3, 2 である。
- 3 個目のボールを落とす。筒の中にあるボールに書かれた整数は下から順に 3, 2, 3 である。
- 4 個目のボールを落とす。筒の中にあるボールに書かれた整数は下から順に 3, 2, 3, 2 である。
- 5 個目のボールを落とす。筒の中にあるボールに書かれた整数は下から順に 3, 2, 3, 2, 2 となるが、2 が書かれたボールが 2 個連続しているのでこれらは消え、下から順に 3, 2, 3 となる。

入力例 2
10 2 3 2 3 3 3 2 3 3 2
出力例 2
1 2 3 4 5 3 2 3 1 0
Score : 400 points
Problem Statement
Takahashi has N balls. Each ball has an integer not less than 2 written on it. He will insert them in a cylinder one by one. The integer written on the i-th ball is a_i.
The balls are made of special material. When k balls with k (k \geq 2) written on them line up in a row, all these k balls will disappear.
For each i (1 \leq i \leq N), find the number of balls after inserting the i-th ball.
Constraints
- 1 \leq N \leq 2 \times 10^5
- 2 \leq a_i \leq 2 \times 10^5 \, (1 \leq i \leq N)
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N a_1 \ldots a_N
Output
Print N lines. The i-th line (1 \leq i \leq N) should contain the number of balls after inserting the i-th ball.
Sample Input 1
5 3 2 3 2 2
Sample Output 1
1 2 3 4 3
The content of the cylinder changes as follows.
- After inserting the 1-st ball, the cylinder contains the ball with 3.
- After inserting the 2-nd ball, the cylinder contains 3, 2 from bottom to top.
- After inserting the 3-rd ball, the cylinder contains 3, 2, 3 from bottom to top.
- After inserting the 4-th ball, the cylinder contains 3, 2, 3, 2 from bottom to top.
- After inserting the 5-th ball, the cylinder momentarily has 3, 2, 3, 2, 2 from bottom to top. The two consecutive balls with 2 disappear, and the cylinder eventually contains 3, 2, 3 from bottom to top.

Sample Input 2
10 2 3 2 3 3 3 2 3 3 2
Sample Output 2
1 2 3 4 5 3 2 3 1 0
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 450 点
問題文
N - 1 個の白いボールと 1 個の黒いボールがあります。これらの N 個のボールが横一列に並んでおり、はじめ黒いボールが最も左にあります。
高橋くんは、これから以下の操作をちょうど K 回行います。
- 1 以上 N 以下の整数を一様ランダムに選ぶ試行を 2 回行う。選んだ整数をそれぞれ a, b とする。さらに、 a \neq b であれば左から a 番目のボールと b 番目のボールを交換する。
K 回の操作のあと黒いボールがある位置を左から x 番目とします。x の期待値を \text{mod} \ 998244353 で求めてください。
期待値 \text{mod} \ 998244353 とは
求める期待値は必ず有理数になることが証明できます。 また、この問題の制約のもとでは、その値を既約分数 \frac{P}{Q} で表した時、Q \not \equiv 0 \pmod{998244353} となることも証明できます。 よって、R \times Q \equiv P \pmod{998244353}, 0 \leq R < 998244353 を満たす整数 R が一意に定まります。 この R を答えてください。制約
- 1 \leq N \leq 998244352
- 1 \leq K \leq 10^5
入力
入力は以下の形式で標準入力から与えられる。
N K
出力
答えを 1 行に出力せよ。
入力例 1
2 1
出力例 1
499122178
1 回の操作が終わった後、黒いボールが左から 1 番目にある確率、 2 番目にある確率はそれぞれ \displaystyle \frac{1}{2} です。よって期待値は \displaystyle \frac{3}{2} です。
入力例 2
3 2
出力例 2
554580198
入力例 3
4 4
出力例 3
592707587
Score : 450 points
Problem Statement
There are N - 1 white balls and one black ball. These N balls are arranged in a row, with the black ball initially at the leftmost position.
Takahashi will perform the following operation exactly K times.
- Choose an integer uniformly at random between 1 and N, inclusive, twice. Let a and b the chosen integers. If a \neq b, swap the a-th and b-th balls from the left.
After K operations, let the black ball be at the x-th position from the left. Find the expected value of x, modulo 998244353.
What is expected value modulo 998244353?
It can be proved that the sought expected value will always be rational. Additionally, under the constraints of this problem, it can be proved that if this value is expressed as an irreducible fraction \frac{P}{Q}, then Q \not \equiv 0 \pmod{998244353}. Therefore, there exists a unique integer R such that R \times Q \equiv P \pmod{998244353}, 0 \leq R < 998244353. Report this R.Constraints
- 1 \leq N \leq 998244352
- 1 \leq K \leq 10^5
Input
The input is given from Standard Input in the following format:
N K
Output
Print the answer in one line.
Sample Input 1
2 1
Sample Output 1
499122178
After one operation, the probabilities that the black ball is at the 1st position and the 2nd position from the left are both \displaystyle \frac{1}{2}. Thus, the expected value is \displaystyle \frac{3}{2}.
Sample Input 2
3 2
Sample Output 2
554580198
Sample Input 3
4 4
Sample Output 3
592707587
実行時間制限: 3 sec / メモリ制限: 1024 MiB
配点 : 500 点
問題文
縦 10^9 マス、横 10^9 マスのマス目があります。上から i 番目、左から j 番目のマスを (i,j) と表記します。
i=1,2,\ldots,N に対し (r_i,c_i) には正整数 x_i が、他の 10^{18}-N 個のマスには 0 が書かれています。
あなたはあるマス (R,C) を選び、 (R,C) と行または列が同じ 2 \times 10^9 - 1 個のマスに書かれた整数の総和 S を求めました。
S として考えられる最大値を求めてください。
制約
- 1 \leq N \leq 2 \times 10^5
- 1 \leq r_i,c_i,x_i \leq 10^9
- i \neq j ならば (r_i,c_i) \neq (r_j,c_j)
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N r_1 c_1 x_1 \vdots r_N c_N x_N
出力
答えを出力せよ。
入力例 1
4 1 1 2 1 2 9 2 1 8 3 2 3
出力例 1
20
(R,C) として (2,2) を選ぶと S が 20 となります。これが最大値です。
入力例 2
1 1 1000000000 1
出力例 2
1
入力例 3
15 158260522 877914575 602436426 24979445 861648772 623690081 433933447 476190629 262703497 211047202 971407775 628894325 731963982 822804784 450968417 430302156 982631932 161735902 880895728 923078537 707723857 189330739 910286918 802329211 404539679 303238506 317063340 492686568 773361868 125660016 650287940 839296263 462224593 492601449 384836991 191890310 576823355 782177068 404011431 818008580 954291757 160449218 155374934 840594328 164163676
出力例 3
1510053068
Score : 500 points
Problem Statement
We have a grid with 10^9 rows and 10^9 columns. Let (i,j) denote the square at the i-th row from the top and j-th column from the left.
For i=1,2,\ldots,N, a positive integer x_i is written on (r_i,c_i). On the other 10^{18}-N squares, 0 is written.
You choose a square (R,C) and compute the sum S of the integers written on the 2 \times 10^9 - 1 squares that share a row or column with (R,C).
Find the maximum possible value of S.
Constraints
- 1 \leq N \leq 2 \times 10^5
- 1 \leq r_i,c_i,x_i \leq 10^9
- (r_i,c_i) \neq (r_j,c_j) if i \neq j.
- All values in the input are integers.
Input
The input is given from Standard Input in the following format:
N r_1 c_1 x_1 \vdots r_N c_N x_N
Output
Print the answer.
Sample Input 1
4 1 1 2 1 2 9 2 1 8 3 2 3
Sample Output 1
20
If you choose (2,2) as (R,C), then S will be 20, which is the maximum possible value.
Sample Input 2
1 1 1000000000 1
Sample Output 2
1
Sample Input 3
15 158260522 877914575 602436426 24979445 861648772 623690081 433933447 476190629 262703497 211047202 971407775 628894325 731963982 822804784 450968417 430302156 982631932 161735902 880895728 923078537 707723857 189330739 910286918 802329211 404539679 303238506 317063340 492686568 773361868 125660016 650287940 839296263 462224593 492601449 384836991 191890310 576823355 782177068 404011431 818008580 954291757 160449218 155374934 840594328 164163676
Sample Output 3
1510053068