Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 100 点
問題文
英小文字からなる長さ N の文字列 S が与えられます。
S の中で a と b が隣接する箇所があれば Yes を、なければ No を出力してください。(a と b の順序は問いません。)
制約
- 2 \leq N \leq 100
- S は英小文字からなる長さ N の文字列
入力
入力は以下の形式で標準入力から与えられる。
N S
出力
S の中で a と b が隣接する箇所があれば Yes を、なければ No を出力せよ。
入力例 1
3 abc
出力例 1
Yes
文字列 abc は 1 文字目にある a と 2 文字目にある b が隣接しています。よって Yes を出力してください。
入力例 2
2 ba
出力例 2
Yes
文字列 ba は 2 文字目にある a と 1 文字目にある b が隣接しています。(a と b の順番は逆でも良い点に注意してください。)
入力例 3
7 atcoder
出力例 3
No
Score : 100 points
Problem Statement
You are given a string S of length N consisting of lowercase English letters.
If there are any adjacent occurrences of a and b in S, print Yes; otherwise, print No. (The order of a and b does not matter.)
Constraints
- 2 \leq N \leq 100
- S is a string of length N consisting of lowercase English letters.
Input
The input is given from Standard Input in the following format:
N S
Output
If there are any adjacent occurrences of a and b in S, print Yes; otherwise, print No.
Sample Input 1
3 abc
Sample Output 1
Yes
The string abc has a as the first character and b as the second character, which are adjacent. Thus, print Yes.
Sample Input 2
2 ba
Sample Output 2
Yes
The string ba has a as the second character and b as the first character, which are adjacent. (Note that the order of a and b does not matter.)
Sample Input 3
7 atcoder
Sample Output 3
No
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 100 点
問題文
英小文字のみからなる文字列 S が与えられます。
S の各文字を英大文字に変換して得られる文字列 T を出力してください。
制約
- S は英小文字のみからなる、長さが 1 以上 100 以下の文字列
入力
入力は以下の形式で標準入力から与えられる。
S
出力
T を出力せよ。
入力例 1
abc
出力例 1
ABC
abc の各文字を英大文字に変換すると ABC になります。
入力例 2
a
出力例 2
A
入力例 3
abcdefghjiklnmoqprstvuwxyz
出力例 3
ABCDEFGHJIKLNMOQPRSTVUWXYZ
Score : 100 points
Problem Statement
You are given a string S consisting of lowercase English letters.
Uppercase each character of S and print the resulting string T.
Constraints
- S is a string consisting of lowercase English letters whose length is between 1 and 100, inclusive.
Input
The input is given from Standard Input in the following format:
S
Output
Print T.
Sample Input 1
abc
Sample Output 1
ABC
Uppercase each character of abc, and you have ABC.
Sample Input 2
a
Sample Output 2
A
Sample Input 3
abcdefghjiklnmoqprstvuwxyz
Sample Output 3
ABCDEFGHJIKLNMOQPRSTVUWXYZ
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
正整数 N が与えられるので、 2^k \le N となる最大の整数 k を求めてください。
制約
- N は 1 \le N \le 10^{18} を満たす整数である
入力
入力は以下の形式で標準入力から与えられる。
N
出力
答えを整数として出力せよ。
入力例 1
6
出力例 1
2
- k=2 は 2^2=4 \le 6 を満たします。
- k \ge 3 である全ての整数 k について 2^k > 6 となります。
以上より、答えは k=2 となります。
入力例 2
1
出力例 2
0
2^0=1 であることに注意してください。
入力例 3
1000000000000000000
出力例 3
59
入力が 32 bit 整数に収まらない場合があります。
Score : 200 points
Problem Statement
Given a positive integer N, find the maximum integer k such that 2^k \le N.
Constraints
- N is an integer satisfying 1 \le N \le 10^{18}.
Input
Input is given from Standard Input in the following format:
N
Output
Print the answer as an integer.
Sample Input 1
6
Sample Output 1
2
- k=2 satisfies 2^2=4 \le 6.
- For every integer k such that k \ge 3, 2^k > 6 holds.
Therefore, the answer is k=2.
Sample Input 2
1
Sample Output 2
0
Note that 2^0=1.
Sample Input 3
1000000000000000000
Sample Output 3
59
The input value may not fit into a 32-bit integer.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
高橋君は容量が G ml のグラスと、容量が M ml のマグカップを 1 つずつ持っています。
ここで、G,M は G<M をみたします。
最初、グラスとマグカップはいずれも空です。
以下の操作を K 回繰り返した後で、グラスとマグカップに水がそれぞれ何 ml ずつ入っているか求めてください。
- グラスが水で満たされているとき、すなわちグラスにちょうど G ml 入っているとき、グラスの水をすべて捨てる。
- そうでなく、マグカップが空であるとき、マグカップを水で満たす。
- 上のいずれでもないとき、マグカップが空になるかグラスが水で満たされるまで、マグカップからグラスに水を移す。
制約
- 1\leq K\leq 100
- 1\leq G<M\leq 1000
- G,M,K は整数
入力
入力は以下の形式で標準入力から与えられる。
K G M
出力
操作を K 回行った後で、グラスとマグカップに水がそれぞれ何 ml ずつ入っているか、この順に空白区切りで出力せよ。
入力例 1
5 300 500
出力例 1
200 500
操作は次の順で行われます。最初、グラスとマグカップはいずれも空です。
- マグカップを水で満たす。グラスには 0 ml, マグカップには 500 ml 入った状態になる。
- グラスが満たされるまでマグカップからグラスに水を移す。グラスには 300 ml, マグカップには 200 ml 入った状態になる。
- グラスの水をすべて捨てる。グラスには 0 ml, マグカップには 200 ml 入った状態になる。
- マグカップが空になるまでマグカップからグラスに水を移す。グラスには 200 ml, マグカップには 0 ml 入った状態になる。
- マグカップを水で満たす。グラスには 200 ml, マグカップには 500 ml 入った状態になる。
よって、5 回の操作の後でグラスには 200 ml, マグカップには 500 ml 入った状態になります。 ゆえに、200, 500 を空白区切りでこの順に出力します。
入力例 2
5 100 200
出力例 2
0 0
Score : 200 points
Problem Statement
AtCoder Inc. sells glasses and mugs.
Takahashi has a glass with a capacity of G milliliters and a mug with a capacity of M milliliters.
Here, G<M.
Initially, both the glass and the mug are empty.
After performing the following operation K times, determine how many milliliters of water are in the glass and the mug, respectively.
- When the glass is filled with water, that is, the glass contains exactly G milliliters of water, discard all the water from the glass.
- Otherwise, if the mug is empty, fill the mug with water.
- Otherwise, transfer water from the mug to the glass until the mug is empty or the glass is filled with water.
Constraints
- 1\leq K\leq 100
- 1\leq G<M\leq 1000
- G, M, and K are integers.
Input
The input is given from Standard Input in the following format:
K G M
Output
Print the amounts, in milliliters, of water in the glass and the mug, in this order, separated by a space, after performing the operation K times.
Sample Input 1
5 300 500
Sample Output 1
200 500
The operation will be performed as follows. Initially, both the glass and the mug are empty.
- Fill the mug with water. The glass has 0 milliliters, and the mug has 500 milliliters of water.
- Transfer water from the mug to the glass until the glass is filled. The glass has 300 milliliters, and the mug has 200 milliliters of water.
- Discard all the water from the glass. The glass has 0 milliliters, and the mug has 200 milliliters of water.
- Transfer water from the mug to the glass until the mug is empty. The glass has 200 milliliters, and the mug has 0 milliliters of water.
- Fill the mug with water. The glass has 200 milliliters, and the mug has 500 milliliters of water.
Thus, after five operations, the glass has 200 milliliters, and the mug has 500 milliliters of water. Hence, print 200 and 500 in this order, separated by a space.
Sample Input 2
5 100 200
Sample Output 2
0 0
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
3\times3 のマス目に 1 から 9 までの数字が書き込まれており、上から i 行目、左から j 列目 (1\leq i\leq3,1\leq j\leq3) に書き込まれている数字は c _ {i,j} です。
異なるマスに同じ数字が書き込まれている場合もありますが、同じ数字が縦・横・斜めに 3 つ連続して書き込まれていることはありません。 より厳密には、c _ {i,j} について次の条件のすべてが成り立っていることが保証されます。
- どの 1\leq i\leq3 についても、c _ {i,1}=c _ {i,2}=c _ {i,3} ではない
- どの 1\leq j\leq3 についても、c _ {1,j}=c _ {2,j}=c _ {3,j} ではない
- c _ {1,1}=c _ {2,2}=c _ {3,3} ではない
- c _ {3,1}=c _ {2,2}=c _ {1,3} ではない
高橋くんは、それぞれのマスに書かれている数字をランダムな順番で知ります。 高橋くんは、縦・横・斜めの列のうちの 1 つでも次の条件を満たしたときがっかりします。
- はじめに知ったほうの 2 マスに書かれた数字が同じであり、最後に知ったマスに書かれた数字がそれと異なる。
高橋くんががっかりせずにすべてのマスに書かれた数字を知る確率を求めてください。
制約
- c _ {i,j}\in\lbrace1,2,3,4,5,6,7,8,9\rbrace\ (1\leq i\leq3,1\leq j\leq3)
- c _ {i,1}=c _ {i,2}=c _ {i,3} ではない (1\leq i\leq3)
- c _ {1,j}=c _ {2,j}=c _ {3,j} ではない (1\leq j\leq3)
- c _ {1,1}=c _ {2,2}=c _ {3,3} ではない
- c _ {1,3}=c _ {2,2}=c _ {3,1} ではない
入力
入力は以下の形式で標準入力から与えられる。
c _ {1,1} c _ {1,2} c _ {1,3}
c _ {2,1} c _ {2,2} c _ {2,3}
c _ {3,1} c _ {3,2} c _ {3,3}
出力
高橋くんががっかりせずにすべてのマスに書かれた数字を知る確率を 1 行で出力せよ。 真の値からの絶対誤差が 10 ^ {-8} 以下であるとき、正答と判定される。
入力例 1
3 1 9 2 5 6 2 7 1
出力例 1
0.666666666666666666666666666667
例えば、高橋くんが c _ {3,1}=2,c _ {2,1}=2,c _ {1,1}=3 の順に知った場合、高橋くんはがっかりしてしまいます。

対して、高橋くんが c _ {1,1},c _ {1,2},c _ {1,3},c _ {2,1},c _ {2,2},c _ {2,3},c _ {3,1},c _ {3,2},c _ {3,3} の順に数字を知った場合、がっかりすることなくすべての数字を知ることができます。
高橋くんががっかりすることなくすべての数字を知ることができる確率は \dfrac 23 です。 絶対誤差が 10 ^ {-8} 以下であれば正答と判定されるため、0.666666657 や 0.666666676 のように出力しても正解になります。
入力例 2
7 7 6 8 6 8 7 7 6
出力例 2
0.004982363315696649029982363316
入力例 3
3 6 7 1 9 7 5 7 5
出力例 3
0.4
Score : 300 points
Problem Statement
There is a 3\times3 grid with numbers between 1 and 9, inclusive, written in each square. The square at the i-th row from the top and j-th column from the left (1\leq i\leq3,1\leq j\leq3) contains the number c _ {i,j}.
The same number may be written in different squares, but not in three consecutive cells vertically, horizontally, or diagonally. More precisely, it is guaranteed that c _ {i,j} satisfies all of the following conditions.
- c _ {i,1}=c _ {i,2}=c _ {i,3} does not hold for any 1\leq i\leq3.
- c _ {1,j}=c _ {2,j}=c _ {3,j} does not hold for any 1\leq j\leq3.
- c _ {1,1}=c _ {2,2}=c _ {3,3} does not hold.
- c _ {3,1}=c _ {2,2}=c _ {1,3} does not hold.
Takahashi will see the numbers written in each cell in random order. He will get disappointed when there is a line (vertical, horizontal, or diagonal) that satisfies the following condition.
- The first two squares he sees contain the same number, but the last square contains a different number.
Find the probability that Takahashi sees the numbers in all the squares without getting disappointed.
Constraints
- c _ {i,j}\in\lbrace1,2,3,4,5,6,7,8,9\rbrace\ (1\leq i\leq3,1\leq j\leq3)
- c _ {i,1}=c _ {i,2}=c _ {i,3} does not hold for any 1\leq i\leq3.
- c _ {1,j}=c _ {2,j}=c _ {3,j} does not hold for any 1\leq j\leq3.
- c _ {1,1}=c _ {2,2}=c _ {3,3} does not hold.
- c _ {3,1}=c _ {2,2}=c _ {1,3} does not hold.
Input
The input is given from Standard Input in the following format:
c _ {1,1} c _ {1,2} c _ {1,3}
c _ {2,1} c _ {2,2} c _ {2,3}
c _ {3,1} c _ {3,2} c _ {3,3}
Output
Print one line containing the probability that Takahashi sees the numbers in all the squares without getting disappointed. Your answer will be considered correct if the absolute error from the true value is at most 10 ^ {-8}.
Sample Input 1
3 1 9 2 5 6 2 7 1
Sample Output 1
0.666666666666666666666666666667
For example, if Takahashi sees c _ {3,1}=2,c _ {2,1}=2,c _ {1,1}=3 in this order, he will get disappointed.

On the other hand, if Takahashi sees c _ {1,1},c _ {1,2},c _ {1,3},c _ {2,1},c _ {2,2},c _ {2,3},c _ {3,1},c _ {3,2},c _ {3,3} in this order, he will see all numbers without getting disappointed.
The probability that Takahashi sees all the numbers without getting disappointed is \dfrac 23. Your answer will be considered correct if the absolute error from the true value is at most 10 ^ {-8}, so outputs such as 0.666666657 and 0.666666676 would also be accepted.
Sample Input 2
7 7 6 8 6 8 7 7 6
Sample Output 2
0.004982363315696649029982363316
Sample Input 3
3 6 7 1 9 7 5 7 5
Sample Output 3
0.4
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 点
問題文
1, 2, \ldots, 2N と番号づけられた 2N 人の人が舞踏会に参加します。 彼らは N 個の 2 人組にわかれてダンスを踊ります。
2 人組を構成する人のうち、番号の小さい方の人が人 i 、番号の大きい方の人が人 j のとき、
その 2 人組の「相性」は A_{i, j} です。
N 個の 2 人組の相性がそれぞれ B_1, B_2, \ldots, B_N であるとき、
「舞踏会全体の楽しさ」はそれらのビットごとの排他的論理和である B_1 \oplus B_2 \oplus \cdots \oplus B_N です。
「 2N 人の参加者が N 個の 2 人組に分かれる方法」を自由に選べるとき、「舞踏会全体の楽しさ」としてあり得る最大値を出力してください。
制約
- 1 \leq N \leq 8
- 0 \leq A_{i, j} < 2^{30}
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N
A_{1, 2} A_{1, 3} A_{1, 4} \cdots A_{1, 2N}
A_{2, 3} A_{2, 4} \cdots A_{2, 2N}
A_{3, 4} \cdots A_{3, 2N}
\vdots
A_{2N-1, 2N}
出力
舞踏会全体の楽しさとしてあり得る最大値を出力せよ。
入力例 1
2 4 0 1 5 3 2
出力例 1
6
人 i と人 j からなる 2 人組を \lbrace i, j\rbrace で表します。 4 人が 2 個の 2 人組にわかれる方法は下記の 3 通りです。
- \lbrace 1, 2\rbrace, \lbrace 3, 4\rbrace という 2 組にわかれる。 このとき、舞踏会全体の楽しさは A_{1, 2} \oplus A_{3, 4} = 4 \oplus 2 = 6 です。
- \lbrace 1, 3\rbrace, \lbrace 2, 4\rbrace という 2 組にわかれる。 このとき、舞踏会全体の楽しさは A_{1, 3} \oplus A_{2, 4} = 0 \oplus 3 = 3 です。
- \lbrace 1, 4\rbrace, \lbrace 2, 3\rbrace という 2 組にわかれる。 このとき、舞踏会全体の楽しさは A_{1, 4} \oplus A_{2, 3} = 1 \oplus 5 = 4 です。
よって、舞踏会全体の楽しさとしてあり得る最大値は 6 です。
入力例 2
1 5
出力例 2
5
人 1 と人 2 からなる 2 人組のみが作られ、このときの舞踏会全体の楽しさは 5 です。
入力例 3
5 900606388 317329110 665451442 1045743214 260775845 726039763 57365372 741277060 944347467 369646735 642395945 599952146 86221147 523579390 591944369 911198494 695097136 138172503 571268336 111747377 595746631 934427285 840101927 757856472 655483844 580613112 445614713 607825444 252585196 725229185 827291247 105489451 58628521 1032791417 152042357 919691140 703307785 100772330 370415195 666350287 691977663 987658020 1039679956 218233643 70938785
出力例 3
1073289207
Score : 400 points
Problem Statement
2N people numbered 1, 2, \ldots, 2N attend a ball. They will group into N pairs and have a dance.
If Person i and Person j pair up, where i is smaller than j, the affinity of that pair is A_{i, j}.
If the N pairs have the affinity of B_1, B_2, \ldots, B_N, the total fun of the ball is the bitwise XOR of them: B_1 \oplus B_2 \oplus \cdots \oplus B_N.
Print the maximum possible total fun of the ball when the 2N people can freely group into N pairs.
Constraints
- 1 \leq N \leq 8
- 0 \leq A_{i, j} < 2^{30}
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
A_{1, 2} A_{1, 3} A_{1, 4} \cdots A_{1, 2N}
A_{2, 3} A_{2, 4} \cdots A_{2, 2N}
A_{3, 4} \cdots A_{3, 2N}
\vdots
A_{2N-1, 2N}
Output
Print the maximum possible total fun of the ball.
Sample Input 1
2 4 0 1 5 3 2
Sample Output 1
6
Let \lbrace i, j\rbrace denote a pair of Person i and Person j. There are three ways for the four people to group into two pairs, as follows.
- Group into \lbrace 1, 2\rbrace, \lbrace 3, 4\rbrace. The total fun of the ball here is A_{1, 2} \oplus A_{3, 4} = 4 \oplus 2 = 6.
- Group into \lbrace 1, 3\rbrace, \lbrace 2, 4\rbrace. The total fun of the ball here is A_{1, 3} \oplus A_{2, 4} = 0 \oplus 3 = 3.
- Group into \lbrace 1, 4\rbrace, \lbrace 2, 3\rbrace. The total fun of the ball here is A_{1, 4} \oplus A_{2, 3} = 1 \oplus 5 = 4.
Therefore, the maximum possible total fun of the ball is 6.
Sample Input 2
1 5
Sample Output 2
5
There will be just a pair of Person 1 and Person 2, where the total fun of the ball is 5.
Sample Input 3
5 900606388 317329110 665451442 1045743214 260775845 726039763 57365372 741277060 944347467 369646735 642395945 599952146 86221147 523579390 591944369 911198494 695097136 138172503 571268336 111747377 595746631 934427285 840101927 757856472 655483844 580613112 445614713 607825444 252585196 725229185 827291247 105489451 58628521 1032791417 152042357 919691140 703307785 100772330 370415195 666350287 691977663 987658020 1039679956 218233643 70938785
Sample Output 3
1073289207
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 500 点
問題文
高橋君は双六で遊んでいます。
この双六には 0 から N の番号がついた N+1 個のマスがあります。 高橋君はマス 0 からスタートし、マス N を目指します。
この双六では、1 から M までの M 種類の目が等確率で出るルーレットを使います。 高橋君はルーレットを回して出た目の数だけ進みます。もし、マス N を超えて進むことになる場合、マス N を超えた分だけ引き返します。
例えば、 N=4 で高橋君がマス 3 にいるとき、ルーレットを回して出た目が 4 の場合は、マス 4 を 3+4-4=3 マス超えてしまいます。そのため、 3 マスだけマス 4 から引き返し、マス 1 に移動します。
高橋君がマス N に到達するとゴールとなり、双六を終了します。
高橋君がルーレットを K 回まで回す時、ゴールできる確率を \text{mod } 998244353 で求めてください。
確率 \text{mod } 998244353 の定義
この問題で求める確率は必ず有理数になることが証明できます。 また、この問題の制約下では、求める確率を既約分数 \frac{y}{x} で表したときに x が 998244353 で割り切れないことが保証されます。
このとき xz \equiv y \pmod{998244353} を満たすような 0 以上 998244352 以下の整数 z が一意に定まります。この z を答えてください。
制約
- M \leq N \leq 1000
- 1 \leq M \leq 10
- 1 \leq K \leq 1000
- 入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N M K
出力
答えを出力せよ。
入力例 1
2 2 1
出力例 1
499122177
1 回ルーレットを回してゴールできるのは、ルーレットで 2 が出るときです。よってゴールできる確率は \frac{1}{2} です。
このとき、2\times 499122177 \equiv 1 \pmod{998244353} が成り立つので、答えとして 499122177 を出力してください。
入力例 2
10 5 6
出力例 2
184124175
入力例 3
100 1 99
出力例 3
0
Score : 500 points
Problem Statement
Takahashi is playing sugoroku, a board game.
The board has N+1 squares, numbered 0 to N. Takahashi starts at square 0 and goes for square N.
The game uses a roulette wheel with M numbers from 1 to M that appear with equal probability. Takahashi spins the wheel and moves by the number of squares indicated by the wheel. If this would send him beyond square N, he turns around at square N and goes back by the excessive number of squares.
For instance, assume that N=4 and Takahashi is at square 3. If the wheel shows 4, the excessive number of squares beyond square 4 is 3+4-4=3. Thus, he goes back by three squares from square 4 and arrives at square 1.
When Takahashi arrives at square N, he wins and the game ends.
Find the probability, modulo 998244353, that Takahashi wins when he may spin the wheel at most K times.
How to print a probability modulo 998244353
It can be proved that the sought probability is always a rational number. Additionally, under the Constraints of this problem, when the sought probability is represented as an irreducible fraction \frac{y}{x}, it is guaranteed that x is not divisible by 998244353.
Here, there is a unique integer z between 0 and 998244352 such that xz \equiv y \pmod{998244353}. Print this z.
Constraints
- M \leq N \leq 1000
- 1 \leq M \leq 10
- 1 \leq K \leq 1000
- All values in the input are integers.
Input
The input is given from Standard Input in the following format:
N M K
Output
Print the answer.
Sample Input 1
2 2 1
Sample Output 1
499122177
Takahashi wins in one spin if the wheel shows 2. Therefore, the probability of winning is \frac{1}{2}.
We have 2\times 499122177 \equiv 1 \pmod{998244353}, so the answer to be printed is 499122177.
Sample Input 2
10 5 6
Sample Output 2
184124175
Sample Input 3
100 1 99
Sample Output 3
0
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 500 点
問題文
1,\ldots,N の番号がついた N 枚のカードがあり、カード i の表には P_i が、裏には Q_i が書かれています。
ここで、P=(P_1,\ldots,P_N) 及び Q=(Q_1,\ldots,Q_N) はそれぞれ (1, 2, \dots, N) の並び替えです。
N 枚のカードから何枚かを選ぶ方法のうち、次の条件を満たすものは何通りありますか? 998244353 で割った余りを求めてください。
条件:1,2,\ldots,N のどの数も選んだカードのいずれかに書かれている
制約
- 1 \leq N \leq 2\times 10^5
- 1 \leq P_i,Q_i \leq N
- P,Q はそれぞれ (1, 2, \dots, N) の並び替えである
- 入力に含まれる値は全て整数である
入力
入力は以下の形式で標準入力から与えられる。
N P_1 P_2 \ldots P_N Q_1 Q_2 \ldots Q_N
出力
答えを出力せよ。
入力例 1
3 1 2 3 2 1 3
出力例 1
3
例えばカード 1,3 を選ぶと、1 はカード 1 の表に、2 はカード 1 の裏に、3 はカード 3 の表に書かれているため条件を満たします。
条件を満たすカードの選び方は \{1,3\},\{2,3\},\{1,2,3\} の 3 通りです。
入力例 2
5 2 3 5 4 1 4 2 1 3 5
出力例 2
12
入力例 3
8 1 2 3 4 5 6 7 8 1 2 3 4 5 6 7 8
出力例 3
1
Score : 500 points
Problem Statement
There are N cards numbered 1,\ldots,N.  Card i has P_i written on the front and Q_i written on the back.
Here, P=(P_1,\ldots,P_N) and Q=(Q_1,\ldots,Q_N) are permutations of (1, 2, \dots, N).
How many ways are there to choose some of the N cards such that the following condition is satisfied? Find the count modulo 998244353.
Condition: every number 1,2,\ldots,N is written on at least one of the chosen cards.
Constraints
- 1 \leq N \leq 2\times 10^5
- 1 \leq P_i,Q_i \leq N
- P and Q are permutations of (1, 2, \dots, N).
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N P_1 P_2 \ldots P_N Q_1 Q_2 \ldots Q_N
Output
Print the answer.
Sample Input 1
3 1 2 3 2 1 3
Sample Output 1
3
For example, if you choose Cards 1 and 3, then 1 is written on the front of Card 1, 2 on the back of Card 1, and 3 on the front of Card 3, so this combination satisfies the condition.
There are 3 ways to choose cards satisfying the condition: \{1,3\},\{2,3\},\{1,2,3\}.
Sample Input 2
5 2 3 5 4 1 4 2 1 3 5
Sample Output 2
12
Sample Input 3
8 1 2 3 4 5 6 7 8 1 2 3 4 5 6 7 8
Sample Output 3
1