Time Limit: 2 sec / Memory Limit: 1024 MB
配点 : 300 点
問題文
3 つの正整数 A, B, C が与えられます。
\sum_{a=1}^{A} \sum_{b=1}^{B} \sum_{c=1}^{C} abc
を 998244353 で割った余りを求めてください。
制約
- 1 \leq A, B, C \leq 10^9
入力
入力は以下の形式で標準入力から与えられる。
A B C
出力
求めた値を 998244353 で割った余りを出力せよ。
入力例 1
1 2 3
出力例 1
18
(1 \times 1 \times 1) + (1 \times 1 \times 2) + (1 \times 1 \times 3) + (1 \times 2 \times 1) + (1 \times 2 \times 2) + (1 \times 2 \times 3) = 1 + 2 + 3 + 2 + 4 + 6 = 18 となります。
入力例 2
1000000000 987654321 123456789
出力例 2
951633476
998244353 で割った余りを求めることに注意してください。
Score : 300 points
Problem Statement
Given are three positive integers A, B, and C. Compute the following value modulo 998244353:
\sum_{a=1}^{A} \sum_{b=1}^{B} \sum_{c=1}^{C} abc
Constraints
- 1 \leq A, B, C \leq 10^9
Input
Input is given from standard input in the following format:
A B C
Output
Print the value modulo 998244353.
Sample Input 1
1 2 3
Sample Output 1
18
We have: (1 \times 1 \times 1) + (1 \times 1 \times 2) + (1 \times 1 \times 3) + (1 \times 2 \times 1) + (1 \times 2 \times 2) + (1 \times 2 \times 3) = 1 + 2 + 3 + 2 + 4 + 6 = 18.
Sample Input 2
1000000000 987654321 123456789
Sample Output 2
951633476
Be sure to compute the value modulo 998244353.
Time Limit: 2 sec / Memory Limit: 1024 MB
配点 : 400 点
問題文
整数 N,K が与えられます. 4 つの整数の組 (a,b,c,d) であって,以下の条件を両方満たすものは何個あるでしょうか.
- 1 \leq a,b,c,d \leq N
- a+b-c-d=K
制約
- 1 \leq N \leq 10^5
- -2(N-1) \leq K \leq 2(N-1)
- 入力される数はすべて整数.
入力
入力は以下の形式で標準入力から与えられる.
N K
出力
答えを出力せよ.
入力例 1
2 1
出力例 1
4
以下の 4 通りです.
- (a,b,c,d)=(2,1,1,1)
- (a,b,c,d)=(1,2,1,1)
- (a,b,c,d)=(2,2,2,1)
- (a,b,c,d)=(2,2,1,2)
入力例 2
2525 -425
出力例 2
10314607400
Score : 400 points
Problem Statement
Given are integers N and K. How many quadruples of integers (a,b,c,d) satisfy both of the following conditions?
- 1 \leq a,b,c,d \leq N
- a+b-c-d=K
Constraints
- 1 \leq N \leq 10^5
- -2(N-1) \leq K \leq 2(N-1)
- All numbers in input are integers.
Input
Input is given from standard input in the following format:
N K
Output
Print the answer.
Sample Input 1
2 1
Sample Output 1
4
Four quadruples below satisfy the conditions:
- (a,b,c,d)=(2,1,1,1)
- (a,b,c,d)=(1,2,1,1)
- (a,b,c,d)=(2,2,2,1)
- (a,b,c,d)=(2,2,1,2)
Sample Input 2
2525 -425
Sample Output 2
10314607400
Time Limit: 2 sec / Memory Limit: 1024 MB
配点 : 500 点
問題文
N \times N の行列と、整数 K が与えられます。この行列の i 行目、j 列目の値を a_{i, j} とします。この行列は、 1, 2, \dots, N^2 をちょうど一つずつ要素に含みます。
sigma くんは、以下の 2 種類の操作を、好きな順序で 好きな回数 行えます。
- 全ての i (1 \leq i \leq N) について a_{i, x} + a_{i, y} \leq K を満たす x, y(1 \leq x < y \leq N) を選び、行列の x, y 列目をswapする。
- 全ての i (1 \leq i \leq N) について a_{x, i} + a_{y, i} \leq K を満たす x, y(1 \leq x < y \leq N) を選び、行列の x, y 行目をswapする。
最終的に得られる行列は何種類存在するでしょうか? \bmod 998244353 で答えてください。
制約
- 1 \leq N \leq 50
- 1 \leq K \leq 2 \times N^2
- a_{i, j} は 1, 2, \dots, N^2 の並び替え
- 入力される数は全て整数である。
入力
入力は以下の形式で標準入力から与えられる.
N K a_{1, 1} a_{1, 2} ... a_{1, N} a_{2, 1} a_{2, 2} ... a_{2, N} : a_{N, 1} a_{N, 2} ... a_{N, N}
出力
最終的に得られる行列が何種類存在するかを \bmod 998244353 で出力せよ。
入力例 1
3 13 3 2 7 4 8 9 1 6 5
出力例 1
12
例えば x = 1, y = 2 として列ベクトルを swap でき、以下のようになります。
2 3 7 8 4 9 6 1 5
その後更に x = 1, y = 3 として行ベクトルを swap でき、以下のようになります。
6 1 5 8 4 9 2 3 7
入力例 2
10 165 82 94 21 65 28 22 61 80 81 79 93 35 59 85 96 1 78 72 43 5 12 15 97 49 69 53 18 73 6 58 60 14 23 19 44 99 64 17 29 67 24 39 56 92 88 7 48 75 36 91 74 16 26 10 40 63 45 76 86 3 9 66 42 84 38 51 25 2 33 41 87 54 57 62 47 31 68 11 83 8 46 27 55 70 52 98 20 77 89 34 32 71 30 50 90 4 37 95 13 100
出力例 2
348179577
Score : 500 points
Problem Statement
Given are an N \times N matrix and an integer K. The entry in the i-th row and j-th column of this matrix is denoted as a_{i, j}. This matrix contains each of 1, 2, \dots, N^2 exactly once.
Sigma can repeat the following two kinds of operation arbitrarily many times in any order.
- Pick two integers x, y (1 \leq x < y \leq N) that satisfy a_{i, x} + a_{i, y} \leq K for all i (1 \leq i \leq N) and swap the x-th and the y-th columns.
- Pick two integers x, y (1 \leq x < y \leq N) that satisfy a_{x, i} + a_{y, i} \leq K for all i (1 \leq i \leq N) and swap the x-th and the y-th rows.
How many matrices can he obtain by these operations? Find it modulo 998244353.
Constraints
- 1 \leq N \leq 50
- 1 \leq K \leq 2 \times N^2
- a_{i, j}'s are a rearrangement of 1, 2, \dots, N^2.
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N K a_{1, 1} a_{1, 2} ... a_{1, N} a_{2, 1} a_{2, 2} ... a_{2, N} : a_{N, 1} a_{N, 2} ... a_{N, N}
Output
Print the number of matrices Sigma can obtain modulo 998244353.
Sample Input 1
3 13 3 2 7 4 8 9 1 6 5
Sample Output 1
12
For example, Sigma can swap two columns, by setting x = 1, y = 2. After that, the resulting matrix will be:
2 3 7 8 4 9 6 1 5
After that, he can swap two row vectors by setting x = 1, y = 3, resulting in the following matrix:
6 1 5 8 4 9 2 3 7
Sample Input 2
10 165 82 94 21 65 28 22 61 80 81 79 93 35 59 85 96 1 78 72 43 5 12 15 97 49 69 53 18 73 6 58 60 14 23 19 44 99 64 17 29 67 24 39 56 92 88 7 48 75 36 91 74 16 26 10 40 63 45 76 86 3 9 66 42 84 38 51 25 2 33 41 87 54 57 62 47 31 68 11 83 8 46 27 55 70 52 98 20 77 89 34 32 71 30 50 90 4 37 95 13 100
Sample Output 2
348179577
Time Limit: 2 sec / Memory Limit: 1024 MB
配点 : 600 点
問題文
正整数 N, K が与えられます。以下の条件を全て満たす有理数の多重集合は何種類存在しますか?
- 多重集合の要素数は N で、要素の総和は K
- 多重集合の要素は全て 1, \frac{1}{2}, \frac{1}{4}, \frac{1}{8}, \dots 、つまり \frac{1}{2^i} (i = 0,1,\dots) のいずれか。
答えは大きくなるかもしれないので、\bmod 998244353 で出力してください。
制約
- 1 \leq K \leq N \leq 3000
- 入力される数は全て整数である。
入力
入力は以下の形式で標準入力から与えられる。
N K
出力
条件を満たす多重集合の種類数を \bmod 998244353 で出力せよ。
入力例 1
4 2
出力例 1
2
以下の 2 つが条件を満たします。
- {1, \frac{1}{2}, \frac{1}{4}, \frac{1}{4}}
- {\frac{1}{2}, \frac{1}{2}, \frac{1}{2}, \frac{1}{2}}
入力例 2
2525 425
出力例 2
687232272
Score : 600 points
Problem Statement
You are given two positive integers N and K. How many multisets of rational numbers satisfy all of the following conditions?
- The multiset has exactly N elements and the sum of them is equal to K.
- Each element of the multiset is one of 1, \frac{1}{2}, \frac{1}{4}, \frac{1}{8}, \dots. In other words, each element can be represented as \frac{1}{2^i}\ (i = 0,1,\dots).
The answer may be large, so print it modulo 998244353.
Constraints
- 1 \leq K \leq N \leq 3000
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N K
Output
Print the number of multisets of rational numbers that satisfy all of the given conditions modulo 998244353.
Sample Input 1
4 2
Sample Output 1
2
The following two multisets satisfy all of the given conditions:
- {1, \frac{1}{2}, \frac{1}{4}, \frac{1}{4}}
- {\frac{1}{2}, \frac{1}{2}, \frac{1}{2}, \frac{1}{2}}
Sample Input 2
2525 425
Sample Output 2
687232272
Time Limit: 2 sec / Memory Limit: 1024 MB
配点 : 800 点
問題文
N \times N の行列を考えます。この行列の i 行目、j 列目の値を a_{i, j} とします。i = 1 か j = 1 を満たす a_{i, j} については 0, 1, 2 のいずれかの値が入力で与えられます。残りの値は以下の規則に従い定めます。
- a_{i,j} = \mathrm{mex}(a_{i-1,j}, a_{i,j-1}) (2 \leq i, j \leq N)。ただし \mathrm{mex}(x, y) は次の表に従う。
\mathrm{mex}(x, y) | y=0 | y=1 | y=2 |
---|---|---|---|
x=0 | 1 | 2 | 1 |
x=1 | 2 | 0 | 0 |
x=2 | 1 | 0 | 0 |
行列の要素のうち、値が 0, 1, 2 であるものはそれぞれ何個でしょうか?
制約
- 1 \leq N \leq 500{,}000
- 入力される a_{i, j} の値はすべて 0, 1, 2 のいずれか
入力
入力は以下の形式で標準入力から与えられる.
N a_{1, 1} a_{1, 1} ... a_{1, N} a_{2, 1} : a_{N, 1}
出力
0 の個数、1 の個数、2 の個数を空白区切りで出力せよ。
入力例 1
4 1 2 0 2 0 0 0
出力例 1
7 4 5
行列は以下のようになります。
1 2 0 2 0 1 2 0 0 2 0 1 0 1 2 0
Score : 800 points
Problem Statement
Consider an N \times N matrix. Let us denote by a_{i, j} the entry in the i-th row and j-th column. For a_{i, j} where i=1 or j=1 holds, its value is one of 0, 1 and 2 and given in the input. The remaining entries are defined as follows:
- a_{i,j} = \mathrm{mex}(a_{i-1,j}, a_{i,j-1}) (2 \leq i, j \leq N) where \mathrm{mex}(x, y) is defined by the following table:
\mathrm{mex}(x, y) | y=0 | y=1 | y=2 |
---|---|---|---|
x=0 | 1 | 2 | 1 |
x=1 | 2 | 0 | 0 |
x=2 | 1 | 0 | 0 |
How many entries of the matrix are 0, 1, and 2, respectively?
Constraints
- 1 \leq N \leq 500{,}000
- a_{i,j}'s given in input are one of 0, 1 and 2.
Input
Input is given from Standard Input in the following format:
N a_{1, 1} a_{1, 1} ... a_{1, N} a_{2, 1} : a_{N, 1}
Output
Print the number of 0's, 1's, and 2's separated by whitespaces.
Sample Input 1
4 1 2 0 2 0 0 0
Sample Output 1
7 4 5
The matrix is as follows:
1 2 0 2 0 1 2 0 0 2 0 1 0 1 2 0
Time Limit: 2 sec / Memory Limit: 1024 MB
配点 : 900 点
問題文
N 頂点 M 辺の単純無向グラフがあります. 頂点には 1 から N までの,辺には 1 から M までの番号がついています. 各頂点 i (1 \leq i \leq N) には,2 つの整数 A_i,B_i が書かれています. また,辺 i (1 \leq i \leq M) は,頂点 U_i と V_i を結ぶ辺です.
今から,すぬけくんが 0 個以上の頂点を選んで削除します. 頂点 i を削除するのにかかるコストは A_i です. 削除された頂点に接続する辺も同時に消えます. 頂点を削除し終えたあとのスコアを,次のように計算します.
- スコアは,各連結成分のスコアの総和である.
- ある連結成分のスコアは,その成分内の頂点の B_i の総和の絶対値である.
すぬけくんの利得を,( スコア - コストの総和 ) とします. すぬけくんの利得の最大値を求めてください.
制約
- 1 \leq N \leq 300
- 1 \leq M \leq 300
- 1 \leq A_i \leq 10^6
- -10^6 \leq B_i \leq 10^6
- 1 \leq U_i,V_i \leq N
- グラフは自己ループや多重辺を含まない.
- 入力はすべて整数である.
入力
入力は以下の形式で標準入力から与えられる.
N M A_1 A_2 \cdots A_N B_1 B_2 \cdots B_N U_1 V_1 U_2 V_2 \vdots U_M V_M
出力
すぬけくんの利得の最大値を出力せよ.
入力例 1
4 4 4 1 2 3 0 2 -3 1 1 2 2 3 3 4 4 2
出力例 1
1
頂点 2 を消すと,コストが 1 かかります. このとき,グラフは 2 つの連結成分に分かれます. 頂点 1 からなる連結成分のスコアは |0|=0 で,頂点 3,4 からなる連結成分のスコアは |-3+1|=2 です. よって利得は 0+2-1=1 になります. 利得を 1 より大きくすることはできないので,1 が答えです.
入力例 2
10 12 733454 729489 956011 464983 822120 364691 271012 762026 751760 965431 -817837 -880667 -822819 -131079 740891 581865 -191711 -383018 273044 476880 3 1 4 1 6 9 3 8 1 6 10 5 5 6 1 5 4 3 7 1 7 4 10 3
出力例 2
2306209
入力例 3
4 2 1 1 1 1 1 1 -1 -1 1 2 3 4
出力例 3
4
与えられるグラフは連結とは限りません.
Score : 900 points
Problem Statement
Given is a simple undirected graph with N vertices and M edges. Its vertices are numbered 1, 2, \ldots, N and its edges are numbered 1, 2, \ldots, M. On Vertex i (1 \leq i \leq N) two integers A_i and B_i are written. Edge i (1 \leq i \leq M) connects Vertices U_i and V_i.
Snuke picks zero or more vertices and delete them. Deleting Vertex i costs A_i. When a vertex is deleted, edges that are incident to the vertex are also deleted. The score after deleting vertices is calculated as follows:
- The score is the sum of the scores of all connected components.
- The score of a connected component is the absolute value of the sum of B_i of the vertices in the connected component.
Snuke's profit is (score) - (the sum of costs). Find the maximum possible profit Snuke can gain.
Constraints
- 1 \leq N \leq 300
- 1 \leq M \leq 300
- 1 \leq A_i \leq 10^6
- -10^6 \leq B_i \leq 10^6
- 1 \leq U_i,V_i \leq N
- The given graph does not contain self loops or multiple edges.
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N M A_1 A_2 \cdots A_N B_1 B_2 \cdots B_N U_1 V_1 U_2 V_2 \vdots U_M V_M
Output
Print the maximum possible profit Snuke can gain.
Sample Input 1
4 4 4 1 2 3 0 2 -3 1 1 2 2 3 3 4 4 2
Sample Output 1
1
Deleting Vertex 2 costs 1. After that, the graph is separated into two connected components. The score of the component consisting of Vertex 1 is |0| = 0. The score of the component consisting of Vertices 3 and 4 is |(-3) + 1| = 2. Therefore, Snuke's profit is 0 + 2 - 1 = 1. He cannot gain more than 1, so the answer is 1.
Sample Input 2
10 12 733454 729489 956011 464983 822120 364691 271012 762026 751760 965431 -817837 -880667 -822819 -131079 740891 581865 -191711 -383018 273044 476880 3 1 4 1 6 9 3 8 1 6 10 5 5 6 1 5 4 3 7 1 7 4 10 3
Sample Output 2
2306209
Sample Input 3
4 2 1 1 1 1 1 1 -1 -1 1 2 3 4
Sample Output 3
4
The given graph is not necessarily connected.