Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 2 点
問題文
あなたは D 日の間、毎日次の 4 つの行動のうちどれか 1 つを行います。
- 1 円払ってガムを買う。
- 3 円払って飴を買う。
- 4 円払ってチョコを買う。
- 6 円払って麩菓子を買う。
あなたは D 日間で合計 N 円を払いました。条件を満たす D 日間の行動は何通りありますか?答えを 998244353 で割った余りを求めてください。
ただし、2 つの行動は、買ったものが 2 つの行動の間で異なる日が存在する時に別々に数えます。
制約
- 1 \leq D \leq 2 \times 10^5
- 1 \leq N \leq 10^6
- D, N は整数
入力
入力は以下の形式で標準入力から与えられる。
D N
出力
答えを出力せよ。
入力例 1
2 7
出力例 1
4
条件を満たす 2 日間の行動は次の 4 通りです。
- 1 日目に 1 円払ってガムを買い、2 日目に 6 円払って麩菓子を買う。
- 1 日目に 3 円払って飴を買い、2 日目に 4 円払ってチョコを買う。
- 1 日目に 4 円払ってチョコを買い、2 日目に 3 円払って飴を買う。
- 1 日目に 6 円払って麩菓子を買い、2 日目に 1 円払ってガムを買う。
入力例 2
200000 1000000
出力例 2
688682037
Score: 2 points
Problem Statement
For D days, each day you choose exactly one of the following four actions:
- Pay 1 yen and buy gum.
- Pay 3 yen and buy candy.
- Pay 4 yen and buy chocolate.
- Pay 6 yen and buy wheat gluten snack.
After D days, you have paid a total of N yen.
How many possible sequences of D days satisfy this condition? Output the answer modulo 998244353.
Two sequences are considered different if there exists at least one day on which the purchased item is different.
Constraints
- 1 \leq D \leq 2 \times 10^5
- 1 \leq N \leq 10^6
- D, N are integers
Input
The input is given from standard input in the following format:
D N
Output
Print the answer.
Sample Input 1
2 7
Sample Output 1
4
There are 4 valid action sequences for 2 days:
- On day 1, pay 1 yen for gum; on day 2, pay 6 yen for wheat gluten snack.
- On day 1, pay 3 yen for candy; on day 2, pay 4 yen for chocolate.
- On day 1, pay 4 yen for chocolate; on day 2, pay 3 yen for candy.
- On day 1, pay 6 yen for wheat gluten snack; on day 2, pay 1 yen for gum.
Sample Input 2
200000 1000000
Sample Output 2
688682037
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 2 点
問題文
整数 N が与えられます。次の条件を全て満たす非負整数の組 (a, b, c, d) の個数を 998244353 で割った余りを求めてください。
- a + b + c + d = N
- a は 0 または 1
- b は 0 または 1 または 2
- c は偶数
- d は 3 の倍数
制約
- 0 \leq N \leq 10^9
- N は整数
入力
入力は以下の形式で標準入力から与えられる。
N
出力
答えを出力せよ。
入力例 1
5
出力例 1
6
条件を満たす (a,b,c,d) は次の 6 個です。
- (0,0,2,3)
- (0,1,4,0)
- (0,2,0,3)
- (1,0,4,0)
- (1,1,0,3)
- (1,2,2,0)
入力例 2
1000000000
出力例 2
1755648
Score: 2 points
Problem Statement
You are given an integer N.
Find the number of non-negative integer quadruples (a, b, c, d) that satisfy all of the following conditions, and output the result modulo 998244353:
- a + b + c + d = N
- a is 0 or 1
- b is 0, 1, or 2
- c is even
- d is a multiple of 3
Constraints
- 0 \leq N \leq 10^9
- N is an integer
Input
The input is given from standard input in the following format:
N
Output
Print the answer.
Sample Input 1
5
Sample Output 1
6
The following 6 quadruples (a,b,c,d) satisfy the conditions:
- (0,0,2,3)
- (0,1,4,0)
- (0,2,0,3)
- (1,0,4,0)
- (1,1,0,3)
- (1,2,2,0)
Sample Input 2
1000000000
Sample Output 2
1755648
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 3 点
問題文
M 以下の非負整数からなる長さ N の整数列のうち、総和が S であるものの個数を 998244353 で割った余りを求めてください。
制約
- 1 \leq N \leq 2 \times 10^5
- 1 \leq M \leq 2 \times 10^5
- 1 \leq S \leq 2 \times 10^5
- N, M, S は整数
入力
入力は以下の形式で標準入力から与えられる。
N M S
出力
答えを出力せよ。
入力例 1
3 2 4
出力例 1
6
条件を満たす数列は次の 6 個です。
- (0,2,2)
- (1,1,2)
- (1,2,1)
- (2,0,2)
- (2,1,1)
- (2,2,0)
入力例 2
12345 678 90123
出力例 2
226012779
Score: 3 points
Problem Statement
Among integer sequences of length N consisting of non-negative integers not greater than M, find the number of sequences whose total sum is exactly S.
Output the result modulo 998244353.
Constraints
- 1 \leq N \leq 2 \times 10^5
- 1 \leq M \leq 2 \times 10^5
- 1 \leq S \leq 2 \times 10^5
- N, M, S are integers
Input
The input is given from standard input in the following format:
N M S
Output
Print the answer.
Sample Input 1
3 2 4
Sample Output 1
6
There are 6 sequences that satisfy the condition:
- (0,2,2)
- (1,1,2)
- (1,2,1)
- (2,0,2)
- (2,1,1)
- (2,2,0)
Sample Input 2
12345 678 90123
Sample Output 2
226012779
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 3 点
問題文
M 以下の非負整数からなる長さ N の整数列 A=(a_1,a_2,\dots,a_N) であって、次の条件を満たすものの個数を 998244353 で割った余りを求めてください。
- A を昇順にソートした列を B=(b_1,b_2,\dots,b_N) とする。この時、 1 \leq i \leq N-1 を満たす i 全てについて b_i と b_{i+1} の偶奇が異なる。
制約
- 1 \leq N \leq 2 \times 10^5
- 1 \leq M \leq 2 \times 10^5
- N, M は整数
入力
入力は以下の形式で標準入力から与えられる。
N M
出力
答えを出力せよ。
入力例 1
2 3
出力例 1
8
条件を満たす数列は次の 8 個です。
- (0,1)
- (0,3)
- (1,0)
- (1,2)
- (2,1)
- (2,3)
- (3,0)
- (3,2)
入力例 2
12345 67890
出力例 2
761484871
Score: 3 points
Problem Statement
Consider integer sequences A=(a_1,a_2,\dots,a_N) of length N, where each element is a non-negative integer not greater than M.
Count how many such sequences satisfy the following condition, and output the result modulo 998244353.
- Let B=(b_1,b_2,\dots,b_N) be the sequence obtained by sorting A in ascending order.
For every i such that 1 \leq i \leq N-1, the parity of b_i and b_{i+1} must be different.
Constraints
- 1 \leq N \leq 2 \times 10^5
- 1 \leq M \leq 2 \times 10^5
- N, M are integers
Input
The input is given from standard input in the following format:
N M
Output
Print the answer.
Sample Input 1
2 3
Sample Output 1
8
There are 8 sequences that satisfy the condition:
- (0,1)
- (0,3)
- (1,0)
- (1,2)
- (2,1)
- (2,3)
- (3,0)
- (3,2)
Sample Input 2
12345 67890
Sample Output 2
761484871
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 3 点
問題文
M 以下の正整数からなる長さ N の整数列 A = (a_1,a_2,\dots,a_N) のうち、次の条件を満たすものの個数を 998244353 で割った余りを求めてください。
- 1 \leq m \leq M を満たす整数 m 全てについて、A における m の登場回数は m 回以下である。
制約
- 1 \leq N \leq 300
- 1 \leq M \leq 300
- N, M は整数
入力
入力は以下の形式で標準入力から与えられる。
N M
出力
答えを出力せよ。
入力例 1
2 3
出力例 1
8
条件を満たす数列は次の 8 個です。
- (1, 2)
- (1, 3)
- (2, 1)
- (2, 2)
- (2, 3)
- (3, 1)
- (3, 2)
- (3, 3)
入力例 2
300 300
出力例 2
478329414
Score: 3 points
Problem Statement
Consider integer sequences A = (a_1,a_2,\dots,a_N) of length N, where each element is a positive integer not greater than M.
Count how many such sequences satisfy the following condition, and output the result modulo 998244353.
- For every integer m such that 1 \leq m \leq M, the number of times m appears in A is at most m.
Constraints
- 1 \leq N \leq 300
- 1 \leq M \leq 300
- N, M are integers
Input
The input is given from standard input in the following format:
N M
Output
Print the answer.
Sample Input 1
2 3
Sample Output 1
8
There are 8 sequences that satisfy the condition:
- (1, 2)
- (1, 3)
- (2, 1)
- (2, 2)
- (2, 3)
- (3, 1)
- (3, 2)
- (3, 3)
Sample Input 2
300 300
Sample Output 2
478329414
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 3 点
問題文
1 から N までの番号がついた N 枚の紙があります。紙同士は区別できます。
あなたはそれぞれの紙を赤色・青色・黄色のいずれかの色で塗っていきます。
ただし、塗り方は次の条件を全て満たす必要があります。
- それぞれの紙はちょうど 1 色に塗られる必要がある。
- 青色に塗られた紙の枚数は偶数枚である。
- 黄色に塗られた紙の枚数は奇数枚である。
条件を満たす色の塗り方の個数を 998244353 で割った余りを求めてください。
ただし、2 つの色の塗り方は、塗られた色が異なる紙が存在する時に別々に数えます。
制約
- 1 \leq N \leq 10^9
- N は整数
入力
入力は以下の形式で標準入力から与えられる。
N
出力
答えを出力せよ。
入力例 1
3
出力例 1
7
条件を満たす塗り方は次の 7 通りです。ここで (c_1, c_2, c_3) は、 1 枚目を c_1 色に、2 枚目を c_2 色に、3 枚目を c_3 色に塗ることを意味します。
- (赤, 赤, 黄)
- (赤, 黄, 赤)
- (黄, 赤, 赤)
- (青, 青, 黄)
- (青, 黄, 青)
- (黄, 青, 青)
- (黄, 黄, 黄)
入力例 2
1000000000
出力例 2
224965629
Score: 3 points
Problem Statement
There are N sheets of paper, numbered from 1 to N.
Each sheet can be painted in one of three colors: red, blue, or yellow.
The coloring must satisfy the following conditions:
- Each sheet must be painted in exactly one color.
- The number of sheets painted blue must be even.
- The number of sheets painted yellow must be odd.
Find the number of valid colorings that satisfy the conditions, and output the result modulo 998244353.
Two colorings are considered different if there exists at least one sheet that is painted in different colors.
Constraints
- 1 \leq N \leq 10^9
- N is an integer
Input
The input is given from standard input in the following format:
N
Output
Print the answer.
Sample Input 1
3
Sample Output 1
7
There are 7 valid colorings.
Here, (c_1, c_2, c_3) means that sheet 1 is painted in color c_1, sheet 2 in c_2, and sheet 3 in c_3.
- (red, red, yellow)
- (red, yellow, red)
- (yellow, red, red)
- (blue, blue, yellow)
- (blue, yellow, blue)
- (yellow, blue, blue)
- (yellow, yellow, yellow)
Sample Input 2
1000000000
Sample Output 2
224965629
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 3 点
問題文
1 円硬貨、2 円硬貨、\dots, M 円硬貨が無限にあります。同じ金額の硬貨同士は区別できません。
整数 N, L が与えられます。m=1, 2, \dots, M-L+1 について次の問題を解いてください。
- あなたは m 円硬貨, m+1 円硬貨, \dots, m+L-1 円硬貨を自由に使うことが出来ます。(形式的に言い換えると、m \leq x \leq m+L-1 を満たす x において x 円硬貨を自由に使うことが出来ます。)
これらを用いて N 円ちょうどを払う方法の個数を 998244353 で割った余りを求めてください。
ただし、2 つの払い方は、払う枚数が 2 つの払い方の間で異なる硬貨が存在する時に別々に数えます。
制約
- 1 \leq L \leq M \leq N \leq 5000
- N, M, L は整数
入力
入力は以下の形式で標準入力から与えられる。
N M L
出力
M-L+1 行出力せよ。i 行目には m = i の時の答えを出力せよ。
入力例 1
5 3 2
出力例 1
3 1
m=1 の場合、1 円硬貨と 2 円硬貨を用いて 5 円ちょうどを払う方法は以下の 3 通りです。
- 1 円硬貨を 5 枚払う。
- 1 円硬貨を 3 枚、2 円硬貨を 1 枚払う。
- 1 円硬貨を 1 枚、2 円硬貨を 2 枚払う。
m=2 の場合、2 円硬貨と 3 円硬貨を用いて 5 円ちょうどを払う方法は以下の 1 通りです。
- 2 円硬貨を 1 枚、3 円硬貨を 1 枚払う。
入力例 2
5000 2500 2495
出力例 2
878712345 520404421 886134625 125526485 307727973 257205353
Score: 3 points
Problem Statement
You have an unlimited number of coins of denominations 1, 2, \dots, M yen.
Coins of the same denomination are indistinguishable.
You are given integers N and L. For each m = 1, 2, \dots, M-L+1, solve the following problem:
- You may use coins of denominations m, m+1, \dots, m+L-1 freely.
(Formally, you may use coins of denomination x for all x satisfying m \leq x \leq m+L-1.)
Find the number of ways to pay exactly N yen using these coins, modulo 998244353.
Two payment methods are considered different if there exists at least one denomination for which the number of coins used differs.
Constraints
- 1 \leq L \leq M \leq N \leq 5000
- N, M, L are integers
Input
The input is given from standard input in the following format:
N M L
Output
Print M-L+1 lines. On the i-th line, output the answer for m = i.
Sample Input 1
5 3 2
Sample Output 1
3 1
For m=1, using coins of denominations 1 and 2, there are 3 ways to pay exactly 5 yen:
- Pay 5 coins of 1 yen.
- Pay 3 coins of 1 yen and 1 coin of 2 yen.
- Pay 1 coin of 1 yen and 2 coins of 2 yen.
For m=2, using coins of denominations 2 and 3, there is 1 way to pay exactly 5 yen:
- Pay 1 coin of 2 yen and 1 coin of 3 yen.
Sample Input 2
5000 2500 2495
Sample Output 2
878712345 520404421 886134625 125526485 307727973 257205353
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 3 点
問題文
2 次元座標上の (0, 0) に駒が置かれています。
あなたは次の一連の操作を 0 回以上自由な回数行うことができます。
- まず、0 \leq a \leq 1 かつ 0 \leq b を満たす整数対 (a, b) を選ぶ。ただし (a, b) = (0, 0) は選ぶことが出来ない。
- そして、駒が今置かれている座標を (x, y) として、駒を (x+a, y+b) に移動させる。
操作を全て終了した後に駒が (N, M) に置かれた状態になるような操作列の個数を 998244353 で割った余りを求めてください。
制約
- 1 \leq N \leq 2 \times 10^5
- 1 \leq M \leq 2 \times 10^5
- 入力される値は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N M
出力
答えを出力せよ。
入力例 1
2 1
出力例 1
5
条件を満たす各操作列について、操作で経由するマスをそれぞれ列挙すると次の 5 通りになります。
- (0, 0) \to (0, 1) \to (1, 1) \to (2, 1)
- (0, 0) \to (1, 0) \to (1, 1) \to (2, 1)
- (0, 0) \to (1, 0) \to (2, 0) \to (2, 1)
- (0, 0) \to (1, 0) \to (2, 1)
- (0, 0) \to (1, 1) \to (2, 1)
入力例 2
12345 67890
出力例 2
824829859
Score: 3 points
Problem Statement
On a 2D coordinate plane, a piece is placed at (0, 0).
You may perform the following operation any number of times (including zero):
- Choose an integer pair (a, b) such that 0 \leq a \leq 1, 0 \leq b, and (a, b) \neq (0, 0).
- If the current position of the piece is (x, y), move it to (x+a, y+b).
Find the number of operation sequences that result in the piece being at (N, M) after all operations, and output the answer modulo 998244353.
Constraints
- 1 \leq N \leq 2 \times 10^5
- 1 \leq M \leq 2 \times 10^5
- All input values are integers
Input
The input is given from standard input in the following format:
N M
Output
Print the answer.
Sample Input 1
2 1
Sample Output 1
5
For each valid operation sequence, the visited coordinates are as follows (5 possibilities):
- (0, 0) \to (0, 1) \to (1, 1) \to (2, 1)
- (0, 0) \to (1, 0) \to (1, 1) \to (2, 1)
- (0, 0) \to (1, 0) \to (2, 0) \to (2, 1)
- (0, 0) \to (1, 0) \to (2, 1)
- (0, 0) \to (1, 1) \to (2, 1)
Sample Input 2
12345 67890
Sample Output 2
824829859
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 3 点
問題文
N 個の相異なる整数 A_1, A_2, \dots, A_N があります。
この中から K 個の整数を選びます。選び方の スコア を選んだ整数の総積として定義します。
K 個の整数を選ぶ方法は \binom{N}{K} 通りありますが、それらに対するスコアの総和を 998244353 で割った余りを求めてください。
制約
- 1 \leq N \leq 2 \times 10^5
- 1 \leq K \leq N
- 1 \leq A_i \leq 10^8
- i \neq j ならば A_i \neq A_j
- 入力される値は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N K A_1 A_2 \dots A_N
出力
答えを出力せよ。
入力例 1
3 2 2 3 5
出力例 1
31
K 個の整数を選ぶ方法およびそのスコアを列挙すると次のようになります。
- A_1 = 2 と A_2 = 3 を選ぶ。スコアは 2 \times 3 = 6 となる。
- A_1 = 2 と A_3 = 5 を選ぶ。スコアは 2 \times 5 = 10 となる。
- A_2 = 3 と A_3 = 5 を選ぶ。スコアは 3 \times 5 = 15 となる。
入力例 2
10 5 1 2 3 4 5 6 7 8 9 10
出力例 2
902055
Score: 3 points
Problem Statement
You are given N distinct integers A_1, A_2, \dots, A_N.
You will choose K of them. The score of a choice is defined as the product of the chosen integers.
There are \binom{N}{K} possible ways to choose K integers.
Find the sum of their scores, and output the result modulo 998244353.
Constraints
- 1 \leq N \leq 2 \times 10^5
- 1 \leq K \leq N
- 1 \leq A_i \leq 10^8
- If i \neq j, then A_i \neq A_j
- All input values are integers
Input
The input is given from standard input in the following format:
N K A_1 A_2 \dots A_N
Output
Print the answer.
Sample Input 1
3 2 2 3 5
Sample Output 1
31
The possible ways to choose K integers and their scores are:
- Choose A_1 = 2 and A_2 = 3. The score is 2 \times 3 = 6.
- Choose A_1 = 2 and A_3 = 5. The score is 2 \times 5 = 10.
- Choose A_2 = 3 and A_3 = 5. The score is 3 \times 5 = 15.
Sample Input 2
10 5 1 2 3 4 5 6 7 8 9 10
Sample Output 2
902055
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 4 点
問題文
マス 0, マス 1, \dots, マス N の N+1 個のマスからなるスゴロクがあります。
また、正整数 A_1, A_2, \dots, A_M が等確率で出る M 面サイコロがあります。ここで A_1, A_2, \dots, A_M は相異なります。
また、マス B_1, マス B_2, \dots, マス B_L には落とし穴があります。ここで 1 \leq B_i \leq N-1 が成り立ち、また B_1, B_2, \dots, B_L は相異なります。
あなたはこのスゴロクを使ってゲームをします。ゲームの手順は次の通りです:
- はじめに駒をマス 0 に置く。そして、ゲームが続いている間、次の操作を行う。
- サイコロを振る。駒があるマスを x、サイコロで出た整数を y として駒をマス \min(N, x+y) に動かす。
- 操作によって落とし穴があるマスに駒を動かした場合はあなたは負けとなり、ゲームを終了する。
- 落とし穴に駒を動かすことなくマス N に駒を移動できた場合はあなたは勝ちとなり、ゲームを終了する。
あなたがゲームに勝つ確率を \text{mod }998244353 で計算してください。
確率 \text{mod }998244353 とは
求める確率は必ず有理数となることが証明できます。 またこの問題の制約下では、その値を互いに素な 2 つの整数 P, Q を用いて \frac{P}{Q} と表したとき、R \times Q \equiv P\pmod{998244353} かつ 0 \leq R \lt 998244353 を満たす整数 R がただ一つ存在することが証明できます。この R を求めてください。制約
- 2 \leq N \leq 2.5 \times 10^5
- 1 \leq M \leq N
- 1 \leq L \leq N-1
- 1 \leq A_1 \lt A_2 \lt \dots \lt A_M \leq N
- 1 \leq B_1 \lt B_2 \lt \dots \lt B_L \leq N-1
- 入力される値は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N M L A_1 A_2 \dots A_M B_1 B_2 \dots B_L
出力
あなたがゲームに勝つ確率を \text{mod }998244353 で計算した時の答えを出力せよ。
入力例 1
2 2 1 1 2 1
出力例 1
499122177
サイコロで 2 が出た場合にのみあなたは勝つことができます。よって答えは \frac{1}{2} です。
入力例 2
250000 10 8 1 2 3 4 5 6 7 8 9 100000 21994 47718 98917 104184 160670 204838 205220 207793
出力例 2
718440495
Score: 4 points
Problem Statement
There is a board game with N+1 squares numbered 0, 1, \dots, N.
You also have an M-sided die, where each side shows a distinct positive integer A_1, A_2, \dots, A_M with equal probability.
Additionally, there are traps on squares B_1, B_2, \dots, B_L. Here, 1 \leq B_i \leq N-1, and all B_i are distinct.
You will play the following game:
- Place your piece on square 0 at the beginning. While the game continues, repeat:
- Roll the die. If your piece is on square x and the die shows y, move the piece to square \min(N, x+y).
- If the piece lands on a trap square, you lose immediately.
- If the piece reaches square N without landing on a trap, you win immediately.
Compute the probability that you win the game, modulo 998244353.
What does probability modulo 998244353 mean?
It can be proven that the probability is always a rational number. Under the constraints of this problem, if the probability is written as \tfrac{P}{Q} with coprime integers P and Q, then there exists a unique integer R such that R \times Q \equiv P \pmod{998244353} and 0 \leq R < 998244353. You are asked to compute this R.Constraints
- 2 \leq N \leq 2.5 \times 10^5
- 1 \leq M \leq N
- 1 \leq L \leq N-1
- 1 \leq A_1 < A_2 < \dots < A_M \leq N
- 1 \leq B_1 < B_2 < \dots < B_L \leq N-1
- All input values are integers
Input
The input is given from standard input in the following format:
N M L A_1 A_2 \dots A_M B_1 B_2 \dots B_L
Output
Print the probability that you win the game, modulo 998244353.
Sample Input 1
2 2 1 1 2 1
Sample Output 1
499122177
You can only win if the die shows 2. Thus, the probability is \tfrac{1}{2}.
Sample Input 2
250000 10 8 1 2 3 4 5 6 7 8 9 100000 21994 47718 98917 104184 160670 204838 205220 207793
Sample Output 2
718440495
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 4 点
問題文
整数 N が与えられます。 (1, 2, \dots, N) の順列 p = (p_1, p_2, \dots, p_N) であって次の条件を満たすものの個数を 998244353 で割った余りを求めてください。
- 1 \leq i \leq N-1 を満たす全ての整数 i について \max(p_1, p_2, \dots, p_i) \neq i が成り立つ。
制約
- 1 \leq N \leq 2.5 \times 10^5
- N は整数
入力
入力は以下の形式で標準入力から与えられる。
N
出力
答えを出力せよ。
入力例 1
3
出力例 1
3
条件を満たす順列 p は次の 3 個です。
- (2,3,1)
- (3,1,2)
- (3,2,1)
入力例 2
123456
出力例 2
923416117
Score: 4 points
Problem Statement
You are given an integer N.
Consider permutations p = (p_1, p_2, \dots, p_N) of (1, 2, \dots, N).
Count how many such permutations satisfy the following condition, and output the result modulo 998244353.
- For every integer i such that 1 \leq i \leq N-1, it must hold that \max(p_1, p_2, \dots, p_i) \neq i.
Constraints
- 1 \leq N \leq 2.5 \times 10^5
- N is an integer
Input
The input is given from standard input in the following format:
N
Output
Print the answer.
Sample Input 1
3
Sample Output 1
3
The following 3 permutations p satisfy the condition:
- (2,3,1)
- (3,1,2)
- (3,2,1)
Sample Input 2
123456
Sample Output 2
923416117
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 4 点
問題文
整数 N が与えられます。 (1, 2, \dots, N) の順列 p = (p_1, p_2, \dots, p_N) であって次の条件を満たすものの個数を 998244353 で割った余りを求めてください。
- 1 \leq i \leq N を満たす全ての整数 i について p_{p_i} \neq i が成り立つ。
制約
- 1 \leq N \leq 2.5 \times 10^5
- N は整数
入力
入力は以下の形式で標準入力から与えられる。
N
出力
答えを出力せよ。
入力例 1
3
出力例 1
2
条件を満たす順列 p は次の 2 個です。
- (2,3,1)
- (3,1,2)
入力例 2
123456
出力例 2
916370671
Score: 4 points
Problem Statement
You are given an integer N.
Consider permutations p = (p_1, p_2, \dots, p_N) of (1, 2, \dots, N).
Count how many such permutations satisfy the following condition, and output the result modulo 998244353.
- For every integer i such that 1 \leq i \leq N, it must hold that p_{p_i} \neq i.
Constraints
- 1 \leq N \leq 2.5 \times 10^5
- N is an integer
Input
The input is given from standard input in the following format:
N
Output
Print the answer.
Sample Input 1
3
Sample Output 1
2
The following 2 permutations p satisfy the condition:
- (2,3,1)
- (3,1,2)
Sample Input 2
123456
Sample Output 2
916370671
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 4 点
問題文
頂点に 1 から N の番号がついた N 頂点の単純連結無向グラフの個数を 998244353 で割った余りを求めてください。
制約
- 1 \leq N \leq 2.5 \times 10^5
- N は整数
入力
入力は以下の形式で標準入力から与えられる。
N
出力
答えを出力せよ。
入力例 1
3
出力例 1
4
3 頂点の単純連結無向グラフは、 2 辺のグラフが 3 個、3 辺のグラフが 1 個で合計 4 個あります。
入力例 2
123456
出力例 2
317059543
Score: 4 points
Problem Statement
Count the number of simple connected undirected graphs with N vertices labeled 1 through N.
Output the result modulo 998244353.
Constraints
- 1 \leq N \leq 2.5 \times 10^5
- N is an integer
Input
The input is given from standard input in the following format:
N
Output
Print the answer.
Sample Input 1
3
Sample Output 1
4
For N=3, the simple connected undirected graphs are:
- 3 graphs with 2 edges,
- 1 graph with 3 edges,
for a total of 4.
Sample Input 2
123456
Sample Output 2
317059543
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 4 点
問題文
1 円硬貨, 2 円硬貨, \dots, N 円硬貨があります。i 円硬貨は A_i 枚あります。同じ金額の硬貨同士は区別できません。
これらの硬貨を用いて N 円ちょうどを支払う方法の個数を 998244353 で割った余りを求めてください。ただし、2 つの払い方は、払う枚数が 2 つの払い方の間で異なる硬貨が存在する時に別々に数えます。
制約
- 1 \leq N \leq 2.5 \times 10^5
- 1 \leq A_i \leq N
- 入力される値は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N A_1 A_2 \dots A_N
出力
答えを出力せよ。
入力例 1
3 1 2 3
出力例 1
2
3 円ちょうどを支払う方法は次の 2 通りです。
- 1 円硬貨と 2 円硬貨を 1 枚ずつ用いて支払う。
- 3 円硬貨を 1 枚用いて支払う。
入力例 2
10 3 1 4 1 5 9 2 6 5 3
出力例 2
20
Score: 4 points
Problem Statement
You have coins of denominations 1, 2, \dots, N yen. For each denomination i, you have A_i coins.
Coins of the same denomination are indistinguishable.
Find the number of ways to pay exactly N yen using these coins, and output the result modulo 998244353.
Two payment methods are considered different if there exists at least one denomination for which the number of coins used differs.
Constraints
- 1 \leq N \leq 2.5 \times 10^5
- 1 \leq A_i \leq 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
Output
Print the answer.
Sample Input 1
3 1 2 3
Sample Output 1
2
There are 2 ways to pay exactly 3 yen:
- Use one 1-yen coin and one 2-yen coin.
- Use one 3-yen coin.
Sample Input 2
10 3 1 4 1 5 9 2 6 5 3
Sample Output 2
20
Time Limit: 3 sec / Memory Limit: 1024 MiB
配点 : 5 点
問題文
頂点に 1 から N の番号がついていて、頂点 1 を根とする N 頂点の根付き木のうち次の条件を満たすものの個数を 998244353 で割った余りを求めてください。
- 1 \leq i \leq N を満たす全ての整数 i について、i の子の個数は 0 または素数である。
制約
- 3 \leq N \leq 2.5 \times 10^5
- N は整数
入力
入力は以下の形式で標準入力から与えられる。
N
出力
答えを出力せよ。
入力例 1
3
出力例 1
1
例えば頂点 2 と頂点 3 の親がともに頂点 1 である根付き木は条件を満たします。なぜならば、頂点 1 の子の個数は 2 個(素数) で、頂点 2 と頂点 3 の子の個数は 0 個だからです。
条件を満たす木は上に説明した木の 1 個のみです。
入力例 2
123456
出力例 2
607180670
Score: 5 points
Problem Statement
Consider rooted trees with N vertices, where the vertices are labeled 1 through N, and vertex 1 is the root.
Count how many such rooted trees satisfy the following condition, and output the result modulo 998244353.
- For every integer i such that 1 \leq i \leq N, the number of children of vertex i is either 0 or a prime number.
Constraints
- 3 \leq N \leq 2.5 \times 10^5
- N is an integer
Input
The input is given from standard input in the following format:
N
Output
Print the answer.
Sample Input 1
3
Sample Output 1
1
For example, consider the rooted tree where both vertex 2 and vertex 3 have parent 1.
This satisfies the condition because vertex 1 has 2 children (a prime number), and vertices 2 and 3 both have 0 children.
This is the only rooted tree that satisfies the condition.
Sample Input 2
123456
Sample Output 2
607180670
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 5 点
問題文
整数 N, M, K が与えられます。m = 1, 2, \dots, M について次の問題を解いてください。
1 から N までの番号のついた N 個のボールと、0 から m までの番号のついた m+1 個の箱があります。
箱 0 にはボールが K 個まで入ります。それ以外の箱に入るボールの個数の上限はありません。
箱に N 個全てのボールを入れる方法の個数を 998244353 で割った余りを求めてください。ただし、2 つのボールを入れる方法は、入っている箱の番号が 2 つの方法の間で異なるボールが存在する時に別々に数えます。
制約
- 1 \leq N \leq 10^5
- 1 \leq M \leq 10^5
- 1 \leq K \leq N
- 入力される値は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N M K
出力
M 行出力せよ。i 行目には m=i の時の答えを出力せよ。
入力例 1
3 2 1
出力例 1
4 20
m=1 の場合を考えます。条件を満たすボールの入れ方は次の 4 通りです。
- 箱 1 にボール 1,2,3 を入れる。
- 箱 0 にボール 1 を、箱 1 にボール 2,3 を入れる。
- 箱 0 にボール 2 を、箱 1 にボール 1,3 を入れる。
- 箱 0 にボール 3 を、箱 1 にボール 1,2 を入れる。
入力例 2
12345 5 6789
出力例 2
583034791 982161077 613932842 770852810 194914198
Score: 5 points
Problem Statement
You are given integers N, M, K.
For each m = 1, 2, \dots, M, solve the following problem:
There are N balls numbered 1 through N, and m+1 boxes numbered 0 through m.
Box 0 can hold at most K balls. The other boxes have no upper limit.
Find the number of ways to place all N balls into the boxes, modulo 998244353.
Two placements are considered different if there exists at least one ball that is placed in different boxes between the two placements.
Constraints
- 1 \leq N \leq 10^5
- 1 \leq M \leq 10^5
- 1 \leq K \leq N
- All input values are integers
Input
The input is given from standard input in the following format:
N M K
Output
Print M lines. On the i-th line, output the answer for m = i.
Sample Input 1
3 2 1
Sample Output 1
4 20
Consider the case m=1. There are 4 valid placements of the balls:
- Put balls 1,2,3 into box 1.
- Put ball 1 into box 0, and balls 2,3 into box 1.
- Put ball 2 into box 0, and balls 1,3 into box 1.
- Put ball 3 into box 0, and balls 1,2 into box 1.
Sample Input 2
12345 5 6789
Sample Output 2
583034791 982161077 613932842 770852810 194914198
Time Limit: 4 sec / Memory Limit: 1024 MiB
配点 : 5 点
問題文
2 個のサイコロがあり、それぞれサイコロ 1, サイコロ 2 と呼びます。
サイコロ 1 は正整数 A_1, A_2, \dots, A_N が等確率で出る N 面サイコロです。ここで A_1, A_2, \dots, A_N は相異なります。
サイコロ 2 は正整数 B_1, B_2, \dots, B_M が等確率で出る M 面サイコロです。ここで B_1, B_2, \dots, B_M は相異なります。
正整数 K が与えられます。k=1,2,\dots,K について次の問題を解いてください。
- サイコロ 1 とサイコロ 2 を同時に振った時の、出た整数の和の k 乗の期待値を \text{mod }998244353 で求めよ。
期待値 \text{mod }998244353 とは
求める期待値は必ず有理数となることが証明できます。 またこの問題の制約下では、その値を互いに素な 2 つの整数 P, Q を用いて \frac{P}{Q} と表したとき、R \times Q \equiv P\pmod{998244353} かつ 0 \leq R \lt 998244353 を満たす整数 R がただ一つ存在することが証明できます。この R を求めてください。制約
- 1 \leq N \leq 10^5
- 1 \leq M \leq 10^5
- 1 \leq K \leq 10^5
- 1 \leq A_1 \lt A_2 \lt \dots \lt A_N \leq 10^8
- 1 \leq B_1 \lt B_2 \lt \dots \lt B_M \leq 10^8
- 入力される値は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N M K A_1 A_2 \dots A_N B_1 B_2 \dots B_M
出力
K 行出力せよ。i 行目には k=i の時の答えを出力せよ。
入力例 1
3 2 3 1 2 3 4 5
出力例 1
499122183 166374102 499122469
例えばサイコロ 1 とサイコロ 2 を同時に振って 3 と 5 が出た場合、和の 3 乗は (3+5)^3=512 になります。
入力例 2
8 9 5 26056440 37770730 49119845 54471601 59187620 86450214 95205990 97771081 12521133 14054302 19786177 21524935 39265456 53591023 65158870 86176948 87221915
出力例 2
981084750 45312313 562611236 522662310 196292405
Score: 5 points
Problem Statement
There are two dice, called die 1 and die 2.
- Die 1 is an N-sided die, where each side shows a distinct positive integer A_1, A_2, \dots, A_N with equal probability.
- Die 2 is an M-sided die, where each side shows a distinct positive integer B_1, B_2, \dots, B_M with equal probability.
You are also given a positive integer K.
For each k = 1, 2, \dots, K, solve the following problem:
- When rolling die 1 and die 2 simultaneously, compute the expected value of (\text{sum of the outcomes})^k modulo 998244353.
What does expected value modulo 998244353 mean?
It can be proven that the expected value is always a rational number. Under the constraints of this problem, if the value can be expressed as \tfrac{P}{Q} with coprime integers P and Q, then there exists a unique integer R such that R \times Q \equiv P \pmod{998244353} and 0 \leq R < 998244353. You are asked to compute this R.Constraints
- 1 \leq N \leq 10^5
- 1 \leq M \leq 10^5
- 1 \leq K \leq 10^5
- 1 \leq A_1 < A_2 < \dots < A_N \leq 10^8
- 1 \leq B_1 < B_2 < \dots < B_M \leq 10^8
- All input values are integers
Input
The input is given from standard input in the following format:
N M K A_1 A_2 \dots A_N B_1 B_2 \dots B_M
Output
Print K lines. On the i-th line, output the answer for k = i.
Sample Input 1
3 2 3 1 2 3 4 5
Sample Output 1
499122183 166374102 499122469
For example, if die 1 shows 3 and die 2 shows 5, then the cube of the sum is (3+5)^3 = 512.
Sample Input 2
8 9 5 26056440 37770730 49119845 54471601 59187620 86450214 95205990 97771081 12521133 14054302 19786177 21524935 39265456 53591023 65158870 86176948 87221915
Sample Output 2
981084750 45312313 562611236 522662310 196292405
Time Limit: 3 sec / Memory Limit: 1024 MiB
配点 : 5 点
問題文
頂点に 1, 2, \dots, 2^N+1 の番号がついた 2^N+1 頂点 2^N 辺の単純無向グラフがあります。i 番目の辺は頂点 i と頂点 i+1 を結んでいます。
あなたは頂点 1 に駒を置きます。その後、以下の操作をちょうど T 回繰り返します。
- 現在駒がある頂点を v とする。v に隣接する頂点の中から 1 個の頂点を一様ランダムに選び、選んだ頂点に駒を移動させる。
T 回の操作を終了した時点で頂点 X に駒がある確率を \text{mod }998244353 で求めてください。
確率 \text{mod }998244353 とは
求める確率は必ず有理数となることが証明できます。 またこの問題の制約下では、その値を互いに素な 2 つの整数 P, Q を用いて \frac{P}{Q} と表したとき、R \times Q \equiv P\pmod{998244353} かつ 0 \leq R \lt 998244353 を満たす整数 R がただ一つ存在することが証明できます。この R を求めてください。制約
- 1 \leq N \leq 20
- 1 \leq T \leq 10^{18}
- 1 \leq X \leq 2^N+1
- 入力される値は全て整数
部分点
この問題には部分点が設定されている。
- N \leq 14 を満たすデータセットに正解した場合、3 点が与えられる。
入力
入力は以下の形式で標準入力から与えられる。
N T X
出力
答えを出力せよ。
入力例 1
2 3 2
出力例 1
249561089
条件を満たす移動およびその確率を列挙すると、
- 頂点 1 \to 頂点 2 \to 頂点 3 \to 頂点 2 と移動する確率が \frac{1}{4}、
- 頂点 1 \to 頂点 2 \to 頂点 1 \to 頂点 2 と移動する確率が \frac{1}{2}
となります。よって答えは \frac{3}{4} です。
入力例 2
10 12345 678
出力例 2
530802129
Score: 5 points
Problem Statement
There is a simple undirected graph with 2^N+1 vertices and 2^N edges, where the vertices are numbered 1, 2, \dots, 2^N+1.
The i-th edge connects vertex i and vertex i+1.
You place a piece on vertex 1. Then you repeat the following operation exactly T times:
- Let the current vertex be v. Choose one adjacent vertex of v uniformly at random, and move the piece to that vertex.
After T operations, compute the probability that the piece is on vertex X, modulo 998244353.
What does probability modulo 998244353 mean?
It can be proven that the probability is always a rational number. Under the constraints of this problem, if the probability is written as \tfrac{P}{Q} with coprime integers P and Q, then there exists a unique integer R such that R \times Q \equiv P \pmod{998244353} and 0 \leq R < 998244353. You are asked to compute this R.Constraints
- 1 \leq N \leq 20
- 1 \leq T \leq 10^{18}
- 1 \leq X \leq 2^N+1
- All input values are integers
Partial Score
This problem has partial scoring:
- If you solve all datasets with N \leq 14, you will earn 3 points.
Input
The input is given from standard input in the following format:
N T X
Output
Print the answer.
Sample Input 1
2 3 2
Sample Output 1
249561089
The possible moves and their probabilities are:
- Move 1 \to 2 \to 3 \to 2 with probability \tfrac{1}{4}.
- Move 1 \to 2 \to 1 \to 2 with probability \tfrac{1}{2}.
Thus, the answer is \tfrac{3}{4}.
Sample Input 2
10 12345 678
Sample Output 2
530802129
Time Limit: 5 sec / Memory Limit: 1024 MiB
配点 : 6 点
問題文
次の問題を 部分問題 と呼びます。
頂点に 1 から N の番号がついた N 頂点の木および整数 K が与えられます。ここで K=1 または K=N が成り立ちます。
Alice と Bob がゲームをします。ゲームは以下の手順で進行します。
- まず、Alice が頂点 1, 頂点 2, \dots, 頂点 K のいずれかに駒を 1 個置く。
- その後、Bob から初めて交互に次の操作を繰り返す:駒が置かれている頂点に隣接する頂点のうちまだ駒が置かれたことがない頂点を 1 個選び、その頂点に駒を動かす。
- 自分の手番で操作ができなくなった人が負けで、そうでない人が勝ちとなる。
双方が最適にゲームをした時、勝つのはどちらですか?
整数 U および \mathrm{type} \in \lbrace 1, 2 \rbrace が与えられます。
N = 2, 3, \dots, U について次の問題を解いてください。
- 整数 N, K が与えられる。ここで K の値は \mathrm{type}=1 のとき 1 を、\mathrm{type}=2 のとき N を取る。
この N, K が部分問題の N, K と一致するとする。この時、部分問題の入力としてあり得る、頂点に 1 から N の番号がついた N 頂点の木は N^{N-2} 個あるが、このうち部分問題の答えが Alice であるような木の個数を 998244353 で割った余りを求めよ。
制約
- 2 \leq U \leq 2.5 \times 10^5
- \mathrm{type} \in \lbrace 1, 2 \rbrace
- 入力される値は全て整数
配点
この問題は次のように採点される。
- \mathrm{type}=1 を満たすデータセットに正解した場合、3 点が与えられる。
- \mathrm{type}=2 を満たすデータセットに正解した場合、3 点が与えられる。
入力
入力は以下の形式で標準入力から与えられる。
U \mathrm{type}
出力
U-1 行出力せよ。i 行目には N=i+1 の時の答えを出力せよ。
入力例 1
4 1
出力例 1
0 2 3
\mathrm{type}=1 の時、常に K=1 が成り立ちます。
N=3 の場合、条件を満たす木は 1-2-3 と辺が結ばれた木と 1-3-2 と辺が結ばれた木の 2 個です。
入力例 2
10 2
出力例 2
0 3 4 125 576 16807 154624 4782969 69760000
\mathrm{type}=2 の時、常に K=N が成り立ちます。
Score: 6 points
Problem Statement
We define the following as a subproblem:
You are given a tree with N vertices labeled 1 through N, and an integer K where K=1 or K=N.
Alice and Bob play a game with the following rules:
- First, Alice places a piece on one of the vertices 1, 2, \dots, K.
- Then, starting with Bob, they alternately perform the following operation:
- Choose a vertex adjacent to the current piece that has not yet been visited, and move the piece there.
- The player who cannot make a move on their turn loses, and the other player wins.
Assuming both play optimally, determine who wins the game.
You are given an integer U and a value \mathrm{type} \in {1, 2}.
For each N = 2, 3, \dots, U, solve the following problem:
- You are given integers N and K, where
K = 1 if \mathrm{type} = 1, and K = N if \mathrm{type} = 2.
Suppose these values match the N and K of the subproblem above. There are N^{N-2} possible trees with N vertices labeled 1 through N.
Among them, count how many trees yield the answer "Alice" for the subproblem, and output the result modulo 998244353.
Constraints
- 2 \leq U \leq 2.5 \times 10^5
- \mathrm{type} \in {1, 2}
- All input values are integers
Scoring
This problem has the following scoring rules:
- If you solve all datasets with \mathrm{type} = 1, you will earn 3 points.
- If you solve all datasets with \mathrm{type} = 2, you will earn 3 points.
Input
The input is given from standard input in the following format:
U \mathrm{type}
Output
Print U - 1 lines. On the i-th line, output the answer for N = i + 1.
Sample Input 1
4 1
Sample Output 1
0 2 3
When \mathrm{type} = 1, K = 1 always holds.
For N = 3, there are 2 valid trees: one with edges 1-2-3, and another with edges 1-3-2.
Sample Input 2
10 2
Sample Output 2
0 3 4 125 576 16807 154624 4782969 69760000
When \mathrm{type} = 2, K = N always holds.
Time Limit: 8 sec / Memory Limit: 1024 MiB
配点 : 7 点
問題文
長さ N の正整数列 A = (A_1, A_2, \dots, A_N) および正整数 T が与えられます。
\sum_{i=1}^N A_i か所の地点があります。異なる地点は互いに区別できます。各地点には整数で表される色で塗られていて、色 i で塗られた地点は A_i か所あります。
はじめ、あなたは色 1 で塗られた地点を 1 か所選び、その地点に移動して印をつけます。その後、あなたは次の操作をちょうど T 回繰り返します。
- 自分が今いる地点とは異なる色の地点を自由に選び、その地点に移動する。
T 回全ての操作が終了した時点ではじめに印をつけた地点にいるような移動の方法の個数を 998244353 で割った余りを求めてください。
制約
- 1 \leq N \leq 10^5
- 1 \leq T \leq 10^{18}
- 1 \leq A_i \leq 10^9
- 入力される値は全て整数
部分点
この問題には部分点が設定されている。
- N \leq 3 \times 10^3 を満たすデータセットに正解した場合、5 点が与えられる。
入力
入力は以下の形式で標準入力から与えられる。
N T A_1 A_2 \dots A_N
出力
答えを出力せよ。
入力例 1
3 3 2 1 2
出力例 1
4
- はじめに移動して印をつけた地点を地点 1、
- 地点 1 でない色 1 で塗られた地点を地点 2、
- 色 2 で塗られた地点を地点 3、
- 色 3 で塗られた 2 か所の地点をそれぞれ地点 4 と地点 5
と呼ぶことにします。この時、条件を満たす移動は次の 4 通りです。
- 地点 1 \to 地点 3 \to 地点 4 \to 地点 1
- 地点 1 \to 地点 3 \to 地点 5 \to 地点 1
- 地点 1 \to 地点 4 \to 地点 3 \to 地点 1
- 地点 1 \to 地点 5 \to 地点 3 \to 地点 1
入力例 2
10 31415926535897932 766294630 440423914 59187620 725560241 585990757 965580536 623321126 550925214 122410709 549392045
出力例 2
66487687
Score: 7 points
Problem Statement
You are given a sequence of positive integers A = (A_1, A_2, \dots, A_N) of length N, and a positive integer T.
There are \sum_{i=1}^N A_i distinct locations. Each location is painted with a color represented by an integer, and there are exactly A_i locations painted with color i.
Initially, you choose one of the locations painted with color 1, move to that location, and mark it. Then, you repeat the following operation exactly T times:
- Choose any location with a different color from your current one, and move there.
Count the number of ways such that after all T operations, you are back at the location you initially marked. Output the result modulo 998244353.
Constraints
- 1 \leq N \leq 10^5
- 1 \leq T \leq 10^{18}
- 1 \leq A_i \leq 10^9
- All input values are integers
Partial Score
This problem has partial scoring:
- If you solve all datasets with N \leq 3 \times 10^3, you will earn 5 points.
Input
The input is given from standard input in the following format:
N T A_1 A_2 \dots A_N
Output
Print the answer.
Sample Input 1
3 3 2 1 2
Sample Output 1
4
Let us label the locations as follows:
- The initially marked location: location 1
- The other location painted with color 1: location 2
- The location painted with color 2: location 3
- The two locations painted with color 3: locations 4 and 5
Then, there are 4 valid sequences of moves:
- 1 \to 3 \to 4 \to 1
- 1 \to 3 \to 5 \to 1
- 1 \to 4 \to 3 \to 1
- 1 \to 5 \to 3 \to 1
Sample Input 2
10 31415926535897932 766294630 440423914 59187620 725560241 585990757 965580536 623321126 550925214 122410709 549392045
Sample Output 2
66487687
Time Limit: 12 sec / Memory Limit: 1024 MiB
配点 : 7 点
問題文
次の問題を 部分問題 と呼びます。
1 から N の番号がついた N 個の番組があります。番組 i は時刻 A_i から時刻 B_i まで放送しています。
あなたは 2 台の録画機を使って全ての番組を録画することにしました。
ここで、番組の集合 S について、1 台の録画機で S に含まれる番組を全て録画できる条件は、S に時間が被る番組の組が含まれないことです。(端点のみが被る場合は問題ないです。)
- 厳密に述べると、ある S の異なる元 i, j であって \max(A_i, A_j) \lt \min(B_i, B_j) を満たすものが存在しない時に全ての番組を録画できます。
あなたは 2 台の録画機を使って全ての番組を録画することが可能ですか?厳密に述べると、番組の集合 \lbrace 1, 2, \dots, N \rbrace の分割 S_1, S_2 であって S_1 と S_2 がともに 1 台の録画機で全て録画可能である番組の集合であるようなものが存在しますか?
可能である場合はYesを、そうでない場合はNoを出力してください。制約
- 0 \leq A_i \lt B_i \leq T
- N, T, A_i, B_i は整数
N および U が与えられます。T=1,2,\dots,U について次の問題を解いてください。
- N, T が部分問題の N, T と同じ値だとする。この時、部分問題の入力としてあり得る (A_1, B_1), \dots, (A_N, B_N) は \left(\dfrac{T(T+1)}{2}\right)^N 通りあるが、そのうち部分問題の答えが
Yesであるものの個数を 998244353 で割った余りを求めよ。
制約
- 1 \leq N \leq 6 \times 10^4
- 1 \leq U \leq 6 \times 10^4
- N, U は整数
部分点
この問題には部分点が設定されている。
- N \leq 5 \times 10^3 かつ U \leq 5 \times 10^3 を満たすデータセットに正解した場合、4 点が与えられる。
入力
入力は以下の形式で標準入力から与えられる。
N U
出力
U 行出力せよ。i 行目には T=i の時の答えを出力せよ。
入力例 1
3 4
出力例 1
0 12 114 558
T=2 の場合、(A_1, B_1) = (0, 2), (A_2, B_2) = (0, 1), (A_3, B_3) = (1, 2) のような入力が条件を満たします。
入力例 2
7 10
出力例 2
0 0 0 6300 260820 4161780 39414060 265208580 398083867 112841142
Score: 7 points
Problem Statement
We define the following as a subproblem:
There are N programs numbered 1 through N. Program i is broadcast from time A_i to time B_i.
You want to record all programs using 2 recorders.For a set of programs S, the condition that all programs in S can be recorded by a single recorder is that no two programs in S overlap in time. (It is acceptable if they only touch at the endpoints.)
- More formally, all programs in S can be recorded if there are no distinct i, j \in S such that \max(A_i, A_j) < \min(B_i, B_j) holds.
The question is whether it is possible to record all programs using 2 recorders.
More precisely, does there exist a partition S_1, S_2 of {1, 2, \dots, N} such that both S_1 and S_2 can each be recorded by a single recorder?
OutputYesif it is possible, otherwise outputNo.Constraints:
- 0 \leq A_i < B_i \leq T
- N, T, A_i, B_i are integers
You are given N and U.
For each T = 1, 2, \dots, U, solve the following problem:
- Suppose N, T are the same as in the subproblem. Then, the number of possible inputs (A_1, B_1), \dots, (A_N, B_N) is \left(\dfrac{T(T+1)}{2}\right)^N.
Among them, count how many yield the answerYesin the subproblem, and output the result modulo 998244353.
Constraints
- 1 \leq N \leq 6 \times 10^4
- 1 \leq U \leq 6 \times 10^4
- N, U are integers
Partial Score
This problem has partial scoring:
- If you solve all datasets with N \leq 5 \times 10^3 and U \leq 5 \times 10^3, you will earn 4 points.
Input
The input is given from standard input in the following format:
N U
Output
Print U lines. On the i-th line, output the answer for T = i.
Sample Input 1
3 4
Sample Output 1
0 12 114 558
For example, when T=2, an input such as (A_1, B_1) = (0, 2), (A_2, B_2) = (0, 1), (A_3, B_3) = (1, 2) satisfies the condition.
Sample Input 2
7 10
Sample Output 2
0 0 0 6300 260820 4161780 39414060 265208580 398083867 112841142
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 7 点
問題文
2 次元座標上の (0, 0) に駒が置かれています。あなたは次の操作を N 回行います。
- 0 \leq i \leq 11 を満たす整数 i を選ぶ。駒が今置かれている座標を (x, y) として、駒を (x + \cos(30i)^\circ, y + \sin(30i)^\circ) に移動させる。
N 回の操作後に (H, W) に駒が置かれた状態になるような操作列の個数を 998244353 で割った余りを求めてください。
制約
- 1 \leq N \leq 2.5 \times 10^5
- -N \leq H \leq N
- -N \leq W \leq N
- N, H, W は整数
部分点
この問題には部分点が設定されている。
- (H, W) = (0, 0) を満たすデータセットに正解した場合、5 点が与えられる。
入力
入力は以下の形式で標準入力から与えられる。
N H W
出力
条件を満たす操作列の個数を 998244353 で割った余りを出力せよ。
入力例 1
2 0 0
出力例 1
12
0 \leq n \leq 11 を満たす整数 n 全てについて、1 回目の操作で i = n を選んだ後に 2 回目の操作で i = (n+6) \bmod {12} を選べば条件を満たします。よって答えは 12 通りです。
入力例 2
123456 0 0
出力例 2
352845935
入力例 3
50 -12 34
出力例 3
391874286
入力例 4
234567 89012 -34567
出力例 4
523418763
Score: 7 points
Problem Statement
On a 2D coordinate plane, there is a piece placed at (0, 0).
You will perform the following operation N times:
- Choose an integer i such that 0 \leq i \leq 11.
If the current position of the piece is (x, y), move it to (x + \cos(30i)^\circ, y + \sin(30i)^\circ).
Count the number of operation sequences that result in the piece being back at (H, W) after N operations, and output the result modulo 998244353.
Constraints
- 1 \leq N \leq 2.5 \times 10^5
- -N \leq H \leq N
- -N \leq W \leq N
- N, H, W are integers
Partial Score
This problem has partial scoring:
- If you solve all datasets with (H, W) = (0, 0), you will earn 5 points.
Input
The input is given from standard input in the following format:
N H W
Output
Print the number of valid operation sequences, modulo 998244353.
Sample Input 1
2 0 0
Sample Output 1
12
For every integer n such that 0 \leq n \leq 11, if the first operation chooses i = n and the second operation chooses i = (n+6) \bmod 12, the condition is satisfied. Thus, there are 12 valid sequences.
Sample Input 2
123456 0 0
Sample Output 2
352845935
Sample Input 3
50 -12 34
Sample Output 3
391874286
Sample Input 4
234567 89012 -34567
Sample Output 4
523418763
Time Limit: 5 sec / Memory Limit: 1024 MiB
配点 : 8 点
問題文
頂点に 1 から N までの番号がついた N 頂点 M 辺の単純無向グラフ G が与えられます。i 番目の辺は頂点 A_i と頂点 B_i を結んでいます。
G の全域部分グラフ(全ての頂点を含む部分グラフ)のうち、次の条件を満たすものの個数を 998244353 で割った余りを求めてください。
- 頂点 1 と頂点 N がともに含まれる閉路が存在する。
制約
- 3 \leq N \leq 16
- 3 \leq M \leq \binom{N}{2}
- 1 \leq A_i \lt B_i \leq N
- i \neq j ならば (A_i, B_i) \neq (A_j, B_j)
- 入力される値は全て整数
部分点
この問題には部分点が設定されている。
- N \leq 10 を満たすデータセットに正解した場合、4 点が与えられる。
入力
入力は以下の形式で標準入力から与えられる。
N M A_1 B_1 A_2 B_2 \vdots A_M B_M
出力
G の全域部分グラフのうち、条件を満たすものの個数を 998244353 で割った余りを出力せよ。
入力例 1
4 5 1 2 1 3 1 4 2 4 3 4
出力例 1
8
例えば辺集合が 1 番目の辺、2 番目の辺、3 番目の辺、5 番目の辺からなる全域部分グラフは条件を満たします。なぜならば、2 番目の辺、3 番目の辺、5 番目の辺が頂点 1 と頂点 4 がともに含まれる閉路をなすからです。
入力例 2
6 15 1 2 1 3 2 3 1 4 2 4 3 4 1 5 2 5 3 5 4 5 1 6 2 6 3 6 4 6 5 6
出力例 2
20448
Score: 8 points
Problem Statement
You are given a simple undirected graph G with N vertices and M edges, where the vertices are numbered 1 through N.
The i-th edge connects vertex A_i and vertex B_i.
Among all spanning subgraphs of G(that is, subgraphs covering all vertices of G), count how many satisfy the following condition, and output the result modulo 998244353:
- There exists a cycle that contains both vertex 1 and vertex N.
Constraints
- 3 \leq N \leq 16
- 3 \leq M \leq \binom{N}{2}
- 1 \leq A_i < B_i \leq N
- If i \neq j, then (A_i, B_i) \neq (A_j, B_j)
- All input values are integers
Partial Score
This problem has partial scoring:
- If you solve all datasets with N \leq 10, you will earn 4 points.
Input
The input is given from standard input in the following format:
N M A_1 B_1 A_2 B_2 \vdots A_M B_M
Output
Print the number of spanning subgraphs of G that satisfy the condition, modulo 998244353.
Sample Input 1
4 5 1 2 1 3 1 4 2 4 3 4
Sample Output 1
8
For example, the spanning subgraph consisting of edges 1, 2, 3, and 5 satisfies the condition, because edges 2, 3, and 5 form a cycle that contains both vertex 1 and vertex 4.
Sample Input 2
6 15 1 2 1 3 2 3 1 4 2 4 3 4 1 5 2 5 3 5 4 5 1 6 2 6 3 6 4 6 5 6
Sample Output 2
20448
Time Limit: 12 sec / Memory Limit: 1024 MiB
配点 : 1 点
注記
この問題は 他の問題を通し終えて暇になった人向けの難問 です。配点も難易度に比べてかなり低めに設定されています。
他の問題を通していない方は先に他の問題を通すことを推奨します。
問題文
\mathbb{F} _ {998244353} 係数の形式的冪級数 F(x) = \sum_{i=0}^{N-1} f_i x^i が与えられます。ここで N \geq 2 かつ F(x) \bmod{x^2} = x が成り立ちます。この時、
- G(G(x)) \equiv F(x) \pmod{x^N} かつ
- G(x) \bmod{x^2} = x
を満たす \mathbb{F} _ {998244353} 係数の形式的冪級数 G(x) = \sum_{i=0}^{N-1} g_i x^i は存在して、かつ一意に定まります。この G(x) を求めてください。
制約
- 2 \leq N \leq 8000
- f_0 = 0
- f_1 = 1
- 0 \leq f_i \lt 998244353 (2 \leq i \leq N-1)
- 入力される値は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N
f_0 f_1 \dots f_{N-1}
出力
答えを以下の形式で出力せよ。
g_0 g_1 \dots g_{N-1}
入力例 1
3 0 1 4
出力例 1
0 1 2
G(x)=x+2x^2 は条件を満たします。
入力例 2
7 0 1 766294629 440423913 59187619 725560240 585990756
出力例 2
0 1 882269491 824730961 772850352 694658399 134447547
Score: 1 points
Note
This problem is a hard challenge intended for those who have finished all other problems and still have time left.
The score is set relatively low compared to its difficulty.
If you have not solved the other problems yet, it is recommended to do those first.
Problem Statement
You are given a formal power series F(x) = \sum_{i=0}^{N-1} f_i x^i over \mathbb{F} _ {998244353}, where N \geq 2 and F(x) \bmod{x^2} = x.
It can be proven that there exists a unique formal power series G(x) = \sum_{i=0}^{N-1} g_i x^i over \mathbb{F} _ {998244353} such that:
- G(G(x)) \equiv F(x) \pmod{x^N}, and
- G(x) \bmod{x^2} = x.
Your task is to find this G(x).
Constraints
- 2 \leq N \leq 8000
- f_0 = 0
- f_1 = 1
- 0 \leq f_i < 998244353 for 2 \leq i \leq N-1
- All input values are integers
Input
The input is given from standard input in the following format:
N
f_0 f_1 \dots f_{N-1}
Output
Print the answer in the following format:
g_0 g_1 \dots g_{N-1}
Sample Input 1
3 0 1 4
Sample Output 1
0 1 2
G(x) = x + 2x^2 satisfies the conditions.
Sample Input 2
7 0 1 766294629 440423913 59187619 725560240 585990756
Sample Output 2
0 1 882269491 824730961 772850352 694658399 134447547