AtCoder Regular Contestd86
AtCoder Regular Contestd86
Problem Statement
For two N × N matrices A and B whose elements are 0 or 1, we say that A and B are similar if they satisfy
the following conditions:
i = 1, … , N .
The sums of corresponding columns are equal. That is, A1,j
+ ⋯ + AN ,j = B1,j + ⋯ + BN ,j for
any j = 1, … , N .
Furthermore, for an N × N matrix A whose elements are 0 or 1, and integers i, j (1 ≤ i, j ≤ N ), we say
that the element at row i column j is fixed if Ai,j = Bi,j holds for any matrix B that is similar to A.
The i-th query: If there exists an N × N matrix whose elements are 0 or 1 such that exactly Ki
Constraints
2 ≤ N ≤ 30
1 ≤ Q ≤ N2 + 1
0 ≤ Ki ≤ N 2
Ki
= Kj (1 ≤ i < j ≤ Q)
Input
The input is given from Standard Input in the following format:
N Q
K1
K2
⋮
KQ
Output
Output Q lines. For the i-th line (1 ≤ i ≤ Q), output the answer for the i-th query.
Sample Input 1
3 3
0
9
7
Sample Output 1
Yes
Yes
No
Query 1: For example, the following matrix X has exactly 0 fixed elements.
1 0 0
0 1 0
0 0 1
This is because all the following matrices, obtained by cyclically shifting the columns, are similar to X , and
each element can be either 0 or 1.
0 0 1
1 0 0
0 1 0
0 1 0
0 0 1
1 0 0
Query 2: For example, the following matrix X has exactly 9 fixed elements.
0 0 1
0 1 1
1 1 1
This is because no other matrix similar to X exists, and all elements are fixed.
Sample Output 2
No
Yes
No
Yes
No
Yes
B - Typical Permutation Descriptor
Problem Statement
You are given a sequence of integers (A1 , … , AN ) of length N . This sequence satisfies 0
≤ Ai < i for
each i = 1, … , N . Find the number of permutations (P1 , … , PN ) of (1, … , N ) that satisfy the
For each i = 1, … , N :
Pj > Pi for any integer j with Ai < j < i
For the sequence (A1 , … , AN ) given in the input, it is guaranteed that there exists a permutation satisfying
the conditions.
Constraints
1 ≤ N ≤ 3 × 105
0 ≤ Ai < i
For A1 , … , AN , there exists a permutation satisfying the conditions in the problem statement.
Input
The input is given from Standard Input in the following format:
N
A1 A2 … AN
Output
Print the number of permutations satisfying the conditions, modulo 998244353.
Sample Input 1
4
0 1 0 3
Sample Output 1
3
There are three such permutations: (2, 3, 1, 4), (2, 4, 1, 3), and (3, 4, 1, 2).
Sample Input 2
22
0 1 2 2 2 2 2 2 1 9 9 9 9 0 14 15 15 15 14 19 19 19
Sample Output 2
353820794
Problem Statement
Mr. Ball and Mr. Box will play a game with balls and boxes.
Initially, Mr. Ball has 10100 balls of each of M different types, and Mr. Box has 10100 yen. There are N boxes,
where the i-th box has capacity Vi and costs Pi yen. During the game, Mr. Box can buy any box at any time.
In this game, the following operations are repeated until the game ends:
Mr. Ball will play optimally to minimize Mr. Box's final money, while Mr. Box will play optimally to maximize it.
How much will Mr. Box's money increase throughout the game?
Here, both players have access to all information. In particular, Mr. Ball can see the capacity, price, and
contents (type and number of balls) of each box. Also, note that Mr. Box's initial money is large enough that he
will never run out of money to buy boxes.
Constraints
1 ≤ T , N , M ≤ 3 × 105
1 ≤ Vi , Pi ≤ 109
T
case1
case2
⋮
caseT
N M
V1 P1
V2 P2
⋮
VN PN
Output
Print the difference between Mr. Box's final and initial money when both players play optimally.
Sample Input 1
3
3 2
1 1000000000
3 1
3 1
1 300000
1000000000 1
10 4
22 5
26 45
72 21
47 39
97 2
75 35
82 24
17 46
32 22
28 67
Sample Output 1
2
0
28
In the first test case, there are two types of balls and three boxes. Let us call the two types of balls white and
black balls, and call the i-th box box i. Here is an example of how the game could proceed where the money
increases by 2 yen.
Finally, box 2 contains 3 white balls and box 3 contains 1 black ball. Mr. Box spent 2 yen and received 4 yen,
so his money increased by 2 yen.
In the second test case, Mr. Ball can play in a way that prevents Mr. Box from earning any money.
D - Polish Mania
Problem Statement
Whether a non-empty sequence of non-negative integers (V1 , V2 , … , VM ) is Polish or not is recursively
defined as follows:
We say (V1 , V2 , … , VM ) is Polish if there exist V1 Polish sequences W1 , W2 , … , WV1 such that the
Given a sequence of non-negative integers (A1 , A2 , … , AN ) of length N , find the number of Polish
sequences of length N that are lexicographically not greater than (A1 , A2 , … , AN ), modulo 998244353.
Constraints
1 ≤ N ≤ 3 × 105
0 ≤ Ai < N
Input
The input is given from Standard Input in the following format:
N
A1 A2 … AN
Output
Print the number of sequences satisfying the conditions, modulo 998244353.
Sample Input 1
6
1 1 1 2 0 0
Sample Output 1
2
Sample Input 2
11
3 3 4 4 5 5 6 6 7 7 8
Sample Output 2
13002
Sample Input 3
19
18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18
Sample Output 3
477638700
Sample Input 4
4
1 1 0 0
Sample Output 4
0
E - Missing Subsequence
Problem Statement
You are given a sequence of integers (X1 , … , XM ) of length M consisting of 1, … , K .
Find the number of sequences (A1 , … , AN ) of length N consisting of 1, … , K that satisfy the following
Among all sequences of length M consisting of 1, … , K , the only sequence that cannot be obtained
as a (not necessarily contiguous) subsequence of (A1 , … , AN ) is (X1 , … , XM ).
Constraints
2 ≤ M , K ≤ N ≤ 400
1 ≤ Xi ≤ K
Input
The input is given from Standard Input in the following format:
N M K
X1 X2 … XM
Output
Print the number of sequences satisfying the condition, modulo 998244353.
Sample Input 1
5 2 3
1 1
Sample Output 1
4
(2, 3, 1, 2, 3)
(2, 3, 1, 3, 2)
(3, 2, 1, 2, 3)
(3, 2, 1, 3, 2)
Sample Input 2
400 3 9
1 8 6
Sample Output 2
417833302
Sample Input 3
29 3 10
3 3 3
Sample Output 3
495293602
Sample Input 4
29 3 10
3 3 4
Sample Output 4
0