実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 100 点
問題文
以下のような、1 から 9 までの数字が書かれた 3 \times 3 の盤面があります。

1 以上 9 以下の整数 A,B が与えられます。ただし、A < B です。
A が書かれたマスと B が書かれたマスが左右に隣接しているか判定してください。
制約
- 1 \le A < B \le 9
- A, B は整数である。
入力
入力は以下の形式で標準入力から与えられる。
A B
出力
A が書かれたマスと B が書かれたマスが左右に隣接しているならば Yes、そうでないならば No を出力せよ。
入力例 1
7 8
出力例 1
Yes
7 が書かれたマスと 8 が書かれたマスは左右に隣り合っているので、Yes を出力します。
入力例 2
1 9
出力例 2
No
入力例 3
3 4
出力例 3
No
Score : 100 points
Problem Statement
We have the following 3 \times 3 board with integers from 1 through 9 written on it.

You are given two integers A and B between 1 and 9, where A < B.
Determine if the two squares with A and B written on them are adjacent horizontally.
Constraints
- 1 \le A < B \le 9
- A and B are integers.
Input
The input is given from Standard Input in the following format:
A B
Output
Print Yes if the two squares with A and B written on them are adjacent horizontally, and No otherwise.
Sample Input 1
7 8
Sample Output 1
Yes
The two squares with 7 and 8 written on them are adjacent horizontally, so print Yes.
Sample Input 2
1 9
Sample Output 2
No
Sample Input 3
3 4
Sample Output 3
No
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 100 点
問題文
長さ N の数列 A = (A_1, A_2, \dots, A_N) が与えられます。
あなたは次の操作をちょうど K 回行います。
- A の先頭の要素を取り除き、A の末尾に 0 を挿入する。
操作を行った後の A の要素をすべて出力してください。
制約
- 1 \leq N \leq 100
- 1 \leq K \leq 100
- 1 \leq A_i \leq 100
- 入力される値はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N K A_1 A_2 \dots A_N
出力
操作を行った後の A の要素を空白区切りで 1 行に出力せよ。
入力例 1
3 2 2 7 8
出力例 1
8 0 0
操作を行う前は A = (2, 7, 8) です。
操作を 1 回行った時点では A = (7, 8, 0) です。
操作を 2 回行った時点では A = (8, 0, 0) です。
よって (8, 0, 0) が答えです。
入力例 2
3 4 9 9 9
出力例 2
0 0 0
入力例 3
9 5 1 2 3 4 5 6 7 8 9
出力例 3
6 7 8 9 0 0 0 0 0
Score : 100 points
Problem Statement
You are given a sequence A = (A_1, A_2, \dots, A_N) of length N.
You perform the following operation exactly K times:
- remove the initial element of A and append a 0 to the tail of A.
Print all the elements of A after the operations.
Constraints
- 1 \leq N \leq 100
- 1 \leq K \leq 100
- 1 \leq A_i \leq 100
- All values in the input 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 elements of A after the operations in one line, separated by spaces.
Sample Input 1
3 2 2 7 8
Sample Output 1
8 0 0
Before the operations, A = (2, 7, 8).
After performing the operation once, A = (7, 8, 0).
After performing the operation twice, A = (8, 0, 0).
Thus, (8, 0, 0) is the answer.
Sample Input 2
3 4 9 9 9
Sample Output 2
0 0 0
Sample Input 3
9 5 1 2 3 4 5 6 7 8 9
Sample Output 3
6 7 8 9 0 0 0 0 0
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 200 点
問題文
整数 N が与えられます。
以下の指示に従って N の近似値を出力してください。
- N が 10^3-1 以下ならば、N をそのまま出力する。
- N が 10^3 以上 10^4-1 以下ならば、N の一の位を切り捨てて出力する。
- N が 10^4 以上 10^5-1 以下ならば、N の十の位以下を切り捨てて出力する。
- N が 10^5 以上 10^6-1 以下ならば、N の百の位以下を切り捨てて出力する。
- N が 10^6 以上 10^7-1 以下ならば、N の千の位以下を切り捨てて出力する。
- N が 10^7 以上 10^8-1 以下ならば、N の一万の位以下を切り捨てて出力する。
- N が 10^8 以上 10^9-1 以下ならば、N の十万の位以下を切り捨てて出力する。
制約
- N は 0 以上 10^9-1 以下の整数
入力
入力は以下の形式で標準入力から与えられる。
N
出力
答えを出力せよ。
入力例 1
20230603
出力例 1
20200000
20230603 は 10^7 以上 10^8-1 以下です。
したがって、一万以下の位を切り捨てて 20200000 を出力します。
入力例 2
0
出力例 2
0
入力例 3
304
出力例 3
304
入力例 4
500600
出力例 4
500000
Score : 200 points
Problem Statement
You are given an integer N.
Print an approximation of N according to the following instructions.
- If N is less than or equal to 10^3-1, print N as it is.
- If N is between 10^3 and 10^4-1, inclusive, truncate the ones digit of N and print the result.
- If N is between 10^4 and 10^5-1, inclusive, truncate the tens digit and all digits below it of N and print the result.
- If N is between 10^5 and 10^6-1, inclusive, truncate the hundreds digit and all digits below it of N and print the result.
- If N is between 10^6 and 10^7-1, inclusive, truncate the thousands digit and all digits below it of N and print the result.
- If N is between 10^7 and 10^8-1, inclusive, truncate the ten-thousands digit and all digits below it of N and print the result.
- If N is between 10^8 and 10^9-1, inclusive, truncate the hundred-thousands digit and all digits below it of N and print the result.
Constraints
- N is an integer between 0 and 10^9-1, inclusive.
Input
The input is given from Standard Input in the following format:
N
Output
Print the answer.
Sample Input 1
20230603
Sample Output 1
20200000
20230603 is between 10^7 and 10^8-1 (inclusive).
Therefore, truncate the ten-thousands digit and all digits below it, and print 20200000.
Sample Input 2
0
Sample Output 2
0
Sample Input 3
304
Sample Output 3
304
Sample Input 4
500600
Sample Output 4
500000
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 200 点
問題文
英小文字からなる文字列 S, T が与えられます。S の長さは N、T の長さは M です。(N \leq M が制約で保証されています)
S が T の 接頭辞 であるとは、T のはじめ N 文字からなる文字列が S と一致することを言います。
S が T の 接尾辞 であるとは、T の後ろ N 文字からなる文字列が S と一致することを言います。
S が T の接頭辞であり、かつ接尾辞でもある場合は 0 を、
S が T の接頭辞であるが、接尾辞でない場合は 1 を、
S が T の接尾辞であるが、接頭辞でない場合は 2 を、
S が T の接頭辞でも接尾辞でもない場合は 3 を出力してください。
制約
- 1 \leq N \leq M \leq 100
- S は英小文字からなる長さ N の文字列
- T は英小文字からなる長さ M の文字列
入力
入力は以下の形式で標準入力から与えられる。
N M S T
出力
問題文の指示に従って答えを出力せよ。
入力例 1
3 7 abc abcdefg
出力例 1
1
S は T の接頭辞ですが接尾辞ではありません。よって 1 を出力します。
入力例 2
3 4 abc aabc
出力例 2
2
S は T の接尾辞ですが接頭辞ではありません。
入力例 3
3 3 abc xyz
出力例 3
3
S は T の接頭辞でも接尾辞でもありません。
入力例 4
3 3 aaa aaa
出力例 4
0
S と T が完全に一致する場合もあります。この場合、S は T の接頭辞であり、かつ接尾辞でもあります。
Score : 200 points
Problem Statement
You are given two strings S and T consisting of lowercase English letters. The lengths of S and T are N and M, respectively. (The constraints guarantee that N \leq M.)
S is said to be a prefix of T when the first N characters of T coincide S.
S is said to be a suffix of T when the last N characters of T coincide S.
If S is both a prefix and a suffix of T, print 0;
If S is a prefix of T but not a suffix, print 1;
If S is a suffix of T but not a prefix, print 2;
If S is neither a prefix nor a suffix of T, print 3.
Constraints
- 1 \leq N \leq M \leq 100
- S is a string of length N consisting of lowercase English letters.
- T is a string of length M consisting of lowercase English letters.
Input
The input is given from Standard Input in the following format:
N M S T
Output
Print the answer according to the instructions in the problem statement.
Sample Input 1
3 7 abc abcdefg
Sample Output 1
1
S is a prefix of T but not a suffix, so you should print 1.
Sample Input 2
3 4 abc aabc
Sample Output 2
2
S is a suffix of T but not a prefix.
Sample Input 3
3 3 abc xyz
Sample Output 3
3
S is neither a prefix nor a suffix of T.
Sample Input 4
3 3 aaa aaa
Sample Output 4
0
S and T may coincide, in which case S is both a prefix and a suffix of T.
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 300 点
問題文
高橋君が運営する SNS「Twidai」にはユーザー 1 からユーザー N までの N 人のユーザーがいます。 Twidai では、ユーザーは別のユーザーをフォローすることや、フォローを解除することができます。
Twidai がサービスを開始してから、Q 回の操作が行われました。 i 回目 (1\leq i\leq Q) の操作は 3 つの整数 T _ i, A _ i, B _ i で表され、それぞれ次のような操作を表します。
- T _ i=1 のとき:ユーザー A _ i がユーザー B _ i をフォローしたことを表す。この操作の時点でユーザー A _ i がユーザー B _ i をフォローしている場合、ユーザーのフォロー状況に変化はない。
- T _ i=2 のとき:ユーザー A _ i がユーザー B _ i のフォローを解除したことを表す。この操作の時点でユーザー A _ i がユーザー B _ i をフォローしていない場合、ユーザーのフォロー状況に変化はない。
- T _ i=3 のとき:ユーザー A _ i とユーザー B _ i が互いにフォローしているかをチェックすることを表す。この操作の時点でユーザー A _ i がユーザー B _ i をフォローしており、かつユーザー B _ i がユーザー A _ i をフォローしているとき、このチェックに対して
Yesと答え、そうでないときこのチェックに対してNoと答える必要がある。
サービス開始時には、どのユーザーも他のユーザーをフォローしていません。
すべての T _ i=3 であるような操作に対して、i が小さいほうから順番に正しい答えを出力してください。
制約
- 2 \leq N \leq 10 ^ 9
- 1 \leq Q \leq 2\times10 ^ 5
- T _ i=1,2,3\ (1\leq i\leq Q)
- 1 \leq A _ i \leq N\ (1\leq i\leq Q)
- 1 \leq B _ i \leq N\ (1\leq i\leq Q)
- A _ i\neq B _ i\ (1\leq i\leq Q)
- T _ i=3 となる i\ (1\leq i\leq Q) が存在する
- 入力される値はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N Q T _ 1 A _ 1 B _ 1 T _ 2 A _ 2 B _ 2 \vdots T _ Q A _ Q B _ Q
出力
T _ i=3 であるような i\ (1\leq i\leq Q) の個数を X として、X 行出力せよ。 j\ (1\leq j\leq X) 行目には j 番目の T _ i=3 であるような操作に対する答えを出力せよ。
入力例 1
3 9 1 1 2 3 1 2 1 2 1 3 1 2 1 2 3 1 3 2 3 1 3 2 1 2 3 1 2
出力例 1
No Yes No No
Twidai には 3 人のユーザーがいます。 9 回の操作はそれぞれ次のようになっています。
- ユーザー 1 がユーザー 2 をフォローします。そのほかにフォローしている/されているユーザーはいません。
- ユーザー 1 とユーザー 2 が互いにフォローしているかチェックします。ユーザー 1 はユーザー 2 をフォローしていますが、ユーザー 2 はユーザー 1 をフォローしていません。この操作への正しい答えは
Noです。 - ユーザー 2 がユーザー 1 をフォローします。
- ユーザー 1 とユーザー 2 が互いにフォローしているかチェックします。ユーザー 1 はユーザー 2 をフォローしており、ユーザー 2 はユーザー 1 をフォローしています。この操作への正しい答えは
Yesです。 - ユーザー 2 がユーザー 3 をフォローします。
- ユーザー 3 がユーザー 2 をフォローします。
- ユーザー 1 とユーザー 3 が互いにフォローしているかチェックします。ユーザー 1 はユーザー 3 をフォローしておらず、ユーザー 3 もユーザー 1 をフォローしていません。この操作への正しい答えは
Noです。 - ユーザー 1 がユーザー 2 のフォローを解除します。
- ユーザー 1 とユーザー 2 が互いにフォローしているかチェックします。ユーザー 2 はユーザー 1 をフォローしていますが、ユーザー 1 はユーザー 2 をフォローしていません。この操作への正しい答えは
Noです。
入力例 2
2 8 1 1 2 1 2 1 3 1 2 1 1 2 1 1 2 1 1 2 2 1 2 3 1 2
出力例 2
Yes No
同じユーザーに対して何度もフォロー操作をする場合があります。
入力例 3
10 30 3 1 6 3 5 4 1 6 1 3 1 7 3 8 4 1 1 6 2 4 3 1 6 5 1 5 6 1 1 8 1 8 1 2 3 10 1 7 6 3 5 6 1 6 7 3 6 7 1 9 5 3 8 6 3 3 8 2 6 9 1 7 1 3 10 8 2 9 2 1 10 9 2 6 10 2 6 8 3 1 6 3 1 8 2 8 5 1 9 10
出力例 3
No No No No Yes Yes No No No Yes Yes
Score : 300 points
Problem Statement
Takahashi runs an SNS "Twidai," which has N users from user 1 through user N. In Twidai, users can follow or unfollow other users.
Q operations have been performed since Twidai was launched. The i-th (1\leq i\leq Q) operation is represented by three integers T_i, A_i, and B_i, whose meanings are as follows:
- If T_i = 1: it means that user A_i follows user B_i. If user A_i is already following user B_i at the time of this operation, it does not make any change.
- If T_i = 2: it means that user A_i unfollows user B_i. If user A_i is not following user B_i at the time of this operation, it does not make any change.
- If T_i = 3: it means that you are asked to determine if users A_i and B_i are following each other. You need to print
Yesif user A_i is following user B_i and user B_i is following user A_i, andNootherwise.
When the service was launched, no users were following any users.
Print the correct answers for all operations such that T_i = 3 in ascending order of i.
Constraints
- 2 \leq N \leq 10 ^ 9
- 1 \leq Q \leq 2\times10 ^ 5
- T _ i=1,2,3\ (1\leq i\leq Q)
- 1 \leq A _ i \leq N\ (1\leq i\leq Q)
- 1 \leq B _ i \leq N\ (1\leq i\leq Q)
- A _ i\neq B _ i\ (1\leq i\leq Q)
- There exists i\ (1\leq i\leq Q) such that T _ i=3.
- All values in the input are integers.
Input
The input is given from Standard Input in the following format:
N Q T _ 1 A _ 1 B _ 1 T _ 2 A _ 2 B _ 2 \vdots T _ Q A _ Q B _ Q
Output
Print X lines, where X is the number of i's (1\leq i\leq Q) such that T _ i=3. The j-th (1\leq j\leq X) line should contain the answer to the j-th operation such that T _ i=3.
Sample Input 1
3 9 1 1 2 3 1 2 1 2 1 3 1 2 1 2 3 1 3 2 3 1 3 2 1 2 3 1 2
Sample Output 1
No Yes No No
Twidai has three users. The nine operations are as follows.
- User 1 follows user 2. No other users are following or followed by any users.
- Determine if users 1 and 2 are following each other. User 1 is following user 2, but user 2 is not following user 1, so
Nois the correct answer to this operation. - User 2 follows user 1.
- Determine if users 1 and 2 are following each other. User 1 is following user 2, and user 2 is following user 1, so
Yesis the correct answer to this operation. - User 2 follows user 3.
- User 3 follows user 2.
- Determine if users 1 and 3 are following each other. User 1 is not following user 3, and user 3 is not following user 1, so
Nois the correct answer to this operation. - User 1 unfollows user 2.
- Determine if users 1 and 2 are following each other. User 2 is following user 1, but user 1 is not following user 2, so
Nois the correct answer to this operation.
Sample Input 2
2 8 1 1 2 1 2 1 3 1 2 1 1 2 1 1 2 1 1 2 2 1 2 3 1 2
Sample Output 2
Yes No
A user may follow the same user multiple times.
Sample Input 3
10 30 3 1 6 3 5 4 1 6 1 3 1 7 3 8 4 1 1 6 2 4 3 1 6 5 1 5 6 1 1 8 1 8 1 2 3 10 1 7 6 3 5 6 1 6 7 3 6 7 1 9 5 3 8 6 3 3 8 2 6 9 1 7 1 3 10 8 2 9 2 1 10 9 2 6 10 2 6 8 3 1 6 3 1 8 2 8 5 1 9 10
Sample Output 3
No No No No Yes Yes No No No Yes Yes
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 300 点
問題文
ある地方に、1 から N の番号がついた N 個の街と、1 から M の番号がついた M 本の道路があります。
i 番目の道路は街 A_i と街 B_i を双方向に結び、長さは C_i です。
好きな街からスタートして同じ街を二度以上通らずに別の街へ移動するときの、通る道路の長さの和としてありえる最大値を求めてください。
制約
- 2 \leq N \leq 10
- 1 \leq M \leq \frac{N(N-1)}{2}
- 1\leq A_i < B_i \leq N
- (A_i,B_i) は相異なる
- 1\leq C_i \leq 10^8
- 入力は全て整数である
入力
入力は以下の形式で標準入力から与えられる。
N M A_1 B_1 C_1 \vdots A_M B_M C_M
出力
答えを出力せよ。
入力例 1
4 4 1 2 1 2 3 10 1 3 100 1 4 1000
出力例 1
1110
4\to 1\to 3\to 2 と移動すると、通る道路の長さの和は 1110 となります。
入力例 2
10 1 5 9 1
出力例 2
1
道路と繋がっていない街が存在するかもしれません。
入力例 3
10 13 1 2 1 1 10 1 2 3 1 3 4 4 4 7 2 4 8 1 5 8 1 5 9 3 6 8 1 6 9 5 7 8 1 7 9 4 9 10 3
出力例 3
20

Score : 300 points
Problem Statement
A region has N towns numbered 1 to N, and M roads numbered 1 to M.
The i-th road connects town A_i and town B_i bidirectionally with length C_i.
Find the maximum possible total length of the roads you traverse when starting from a town of your choice and getting to another town without passing through the same town more than once.
Constraints
- 2 \leq N \leq 10
- 1 \leq M \leq \frac{N(N-1)}{2}
- 1 \leq A_i < B_i \leq N
- The pairs (A_i,B_i) are distinct.
- 1\leq C_i \leq 10^8
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N M A_1 B_1 C_1 \vdots A_M B_M C_M
Output
Print the answer.
Sample Input 1
4 4 1 2 1 2 3 10 1 3 100 1 4 1000
Sample Output 1
1110
If you travel as 4\to 1\to 3\to 2, the total length of the roads you traverse is 1110.
Sample Input 2
10 1 5 9 1
Sample Output 2
1
There may be a town that is not connected to a road.
Sample Input 3
10 13 1 2 1 1 10 1 2 3 1 3 4 4 4 7 2 4 8 1 5 8 1 5 9 3 6 8 1 6 9 5 7 8 1 7 9 4 9 10 3
Sample Output 3
20

実行時間制限: 2.5 sec / メモリ制限: 1024 MiB
配点 : 400 点
問題文
項数が N の正整数列 A=(a_1,\ldots,a_N) が与えられます。
A の項を 1 個以上選ぶ方法は 2^N-1 通りありますが、そのうち選んだ項の平均値が整数であるものが何通りかを 998244353 で割った余りを求めてください。
制約
- 1 \leq N \leq 100
- 1 \leq a_i \leq 10^9
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N a_1 \ldots a_N
出力
答えを出力せよ。
入力例 1
3 2 6 2
出力例 1
6
A の項を選ぶ方法それぞれに対する平均値は以下のようになります。
-
a_1 のみを選んだ場合、平均値は \frac{a_1}{1}=\frac{2}{1} = 2 であり、整数である。
-
a_2 のみを選んだ場合、平均値は \frac{a_2}{1}=\frac{6}{1} = 6 であり、整数である。
-
a_3 のみを選んだ場合、平均値は \frac{a_3}{1}=\frac{2}{1} = 2 であり、整数である。
-
a_1 と a_2 を選んだ場合、平均値は \frac{a_1+a_2}{2}=\frac{2+6}{2} = 4 であり、整数である。
-
a_1 と a_3 を選んだ場合、平均値は \frac{a_1+a_3}{2}=\frac{2+2}{2} = 2 であり、整数である。
-
a_2 と a_3 を選んだ場合、平均値は \frac{a_2+a_3}{2}=\frac{6+2}{2} = 4 であり、整数である。
-
a_1 と a_2 と a_3 を選んだ場合、平均値は \frac{a_1+a_2+a_3}{3}=\frac{2+6+2}{3} = \frac{10}{3} であり、整数ではない。
以上より、6 通りの選び方が条件を満たします。
入力例 2
5 5 5 5 5 5
出力例 2
31
どのように A の項を 1 個以上選んでも平均値が 5 になります。
Score : 400 points
Problem Statement
You are given a sequence of positive integers A=(a_1,\ldots,a_N) of length N.
There are (2^N-1) ways to choose one or more terms of A. How many of them have an integer-valued average? Find the count modulo 998244353.
Constraints
- 1 \leq N \leq 100
- 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 \ldots a_N
Output
Print the answer.
Sample Input 1
3 2 6 2
Sample Output 1
6
For each way to choose terms of A, the average is obtained as follows:
-
If just a_1 is chosen, the average is \frac{a_1}{1}=\frac{2}{1} = 2, which is an integer.
-
If just a_2 is chosen, the average is \frac{a_2}{1}=\frac{6}{1} = 6, which is an integer.
-
If just a_3 is chosen, the average is \frac{a_3}{1}=\frac{2}{1} = 2, which is an integer.
-
If a_1 and a_2 are chosen, the average is \frac{a_1+a_2}{2}=\frac{2+6}{2} = 4, which is an integer.
-
If a_1 and a_3 are chosen, the average is \frac{a_1+a_3}{2}=\frac{2+2}{2} = 2, which is an integer.
-
If a_2 and a_3 are chosen, the average is \frac{a_2+a_3}{2}=\frac{6+2}{2} = 4, which is an integer.
-
If a_1, a_2, and a_3 are chosen, the average is \frac{a_1+a_2+a_3}{3}=\frac{2+6+2}{3} = \frac{10}{3}, which is not an integer.
Therefore, 6 ways satisfy the condition.
Sample Input 2
5 5 5 5 5 5
Sample Output 2
31
Regardless of the choice of one or more terms of A, the average equals 5.
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 500 点
問題文
N 頂点 M 辺の無向グラフが与えられます。 頂点は頂点 1 ,頂点 2 , \ldots ,頂点 N、辺は辺 1 ,辺 2 , \ldots ,辺 M と番号付けられており、特に辺 i (1 \leq i \leq M) は頂点 U_i と頂点 V_i を結んでいます。 また、このグラフは単純であることが保証されます。すなわち、自己ループや多重辺は存在しません。
このグラフの M 本の辺すべてに向き付けをする方法は 2^M 通り考えられますが、 そのうち、どの頂点についても、その頂点から他の頂点に向かう辺がちょうど 1 本ずつ存在するような向き付けの方法は何通りありますか。 答えは非常に大きくなる可能性があるので、998244353 で割った余りを出力してください。
制約
- 2 \leq N \leq 2\times 10^5
- 1 \leq M \leq 2\times 10^5
- 1 \leq U_i,V_i \leq N
- U_i \neq V_i
- 入力は全て整数である。
- 与えられるグラフは単純である。
入力
入力は以下の形式で標準入力から与えられる。
N M U_1 V_1 U_2 V_2 \vdots U_M V_M
出力
答えを出力せよ。
入力例 1
3 3 1 2 1 3 2 3
出力例 1
2
条件をみたす辺の向き付けの方法は、
- 1\rightarrow 2 , 2\rightarrow 3 , 1\leftarrow 3
- 1\leftarrow 2 , 2\leftarrow 3 , 1\rightarrow 3
の 2 通りです。
入力例 2
2 1 1 2
出力例 2
0
すべての頂点から 1 本ずつ辺が出ているようにすることは明らかに不可能です。
入力例 3
7 7 1 2 2 3 3 4 4 2 5 6 6 7 7 5
出力例 3
4
Score : 500 points
Problem Statement
Given is an undirected graph with N vertices and M edges. The vertices are called Vertex 1, Vertex 2, \ldots, Vertex N, and the edges are called Edge 1, Edge 2, \ldots, Edge M. Edge i (1 \leq i \leq M) connects Vertex U_i and Vertex V_i. It is guaranteed that the graph is simple: it has no self-loops and no multi-edges.
There are 2^M ways to direct every edge in this graph. We want each vertex to have exactly one edge going from that vertex to another vertex. How many ways are there to direct the edges in that way? Since the answer may be enormous, print it modulo 998244353.
Constraints
- 2 \leq N \leq 2\times 10^5
- 1 \leq M \leq 2\times 10^5
- 1 \leq U_i,V_i \leq N
- U_i \neq V_i
- All values in input are integers.
- The given graph is simple.
Input
Input is given from Standard Input in the following format:
N M U_1 V_1 U_2 V_2 \vdots U_M V_M
Output
Print the answer.
Sample Input 1
3 3 1 2 1 3 2 3
Sample Output 1
2
There are two ways to direct the edges to achieve the objective:
- 1\rightarrow 2 , 2\rightarrow 3 , 1\leftarrow 3
- 1\leftarrow 2 , 2\leftarrow 3 , 1\rightarrow 3
Sample Input 2
2 1 1 2
Sample Output 2
0
It is obviously impossible to make every vertex have one edge going from that vertex.
Sample Input 3
7 7 1 2 2 3 3 4 4 2 5 6 6 7 7 5
Sample Output 3
4
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 500 点
問題文
長さ N の数列 A が与えられます。 数列の長さが 2 以上のとき、隣接する二つの値を選び、それらを削除し、それらが元にあった位置にそれらの和を挿入するという操作を好きなだけ行えます。 0 回以上の操作の後の数列として考えられるものは何通りあるか求め、998244353 で割ったあまりを出力してください。
制約
- 1 \leq N \leq 2\times 10^5
- |A_i| \leq 10^9
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N A_1 A_2 \cdots A_N
出力
答えを出力せよ。
入力例 1
3 1 -1 1
出力例 1
4
0 回以上の操作の後の数列として考えられるのは以下の 4 通りです。
- {1,-1,1}
- {1,0}
- {0,1}
- {1}
入力例 2
10 377914575 -275478149 0 -444175904 719654053 -254224494 -123690081 377914575 -254224494 -21253655
出力例 2
321
Score : 500 points
Problem Statement
Given is a sequence A of length N. You can do this operation any number of times: when the length of the sequence is at least 2, choose two adjacent values, delete them, and insert their sum where they were. How many sequences can result from zero or more operations? Find the count modulo 998244353.
Constraints
- 1 \leq N \leq 2\times 10^5
- |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 \cdots A_N
Output
Print the answer.
Sample Input 1
3 1 -1 1
Sample Output 1
4
The following four sequences can result from zero or more operations.
- {1,-1,1}
- {1,0}
- {0,1}
- {1}
Sample Input 2
10 377914575 -275478149 0 -444175904 719654053 -254224494 -123690081 377914575 -254224494 -21253655
Sample Output 2
321