0% found this document useful (0 votes)
78 views13 pages

AtCoder Regular Contestd86

Uploaded by

niluhntr
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
78 views13 pages

AtCoder Regular Contestd86

Uploaded by

niluhntr
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

A - Underclued

Time Limit: 2 sec / Memory Limit: 1024 MB

Score : 900 points

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:

The sums of corresponding rows are equal. That is, Ai,1 ​


+ ⋯ + Ai,N = Bi,1 + ⋯ + Bi,N for any
​ ​

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.
​ ​

Answer the following Q queries:

The i-th query: If there exists an N × N matrix whose elements are 0 or 1 such that exactly Ki ​

elements are fixed, output Yes; otherwise, output No.

Constraints
2 ≤ N ≤ 30
1 ≤ Q ≤ N2 + 1
0 ≤ Ki ≤ N 2 ​

Ki 
= Kj (1 ≤ i < j ≤ Q)
​ ​

All inputs are integers

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.

Query 3: No matrix exists with exactly 7 fixed elements.


Sample Input 2
29 6
186
681
18
108
123
321

Sample Output 2
No
Yes
No
Yes
No
Yes
B - Typical Permutation Descriptor

Time Limit: 2 sec / Memory Limit: 1024 MB

Score : 900 points

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
​ ​

following conditions, modulo 998244353.

For each i = 1, … , N :
Pj > Pi for any integer j with Ai < j < i
​ ​ ​

PAi < Pi if Ai > 0



​ ​ ​

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.
​ ​

All input values are integers.

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

The answer is 353820794, which is 2350309500 modulo 998244353.


C - Ball and Box

Time Limit: 2 sec / Memory Limit: 1024 MB

Score : 900 points

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:

1. Mr. Ball chooses one ball and gives it to Mr. Box.


2. Mr. Box either accepts the ball or ends the game without accepting it.
3. If Mr. Box accepts the ball, he chooses one of his purchased boxes and puts the ball in it.
4. If the box with the ball satisfies the following conditions, Mr. Box receives 1 yen. Otherwise, the game
ends.
The number of balls in the box does not exceed its capacity.
All balls in the box are of the same type.

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.

Solve T test cases for each input file.

Constraints
1 ≤ T , N , M ≤ 3 × 105
1 ≤ Vi , Pi ≤ 109
​ ​

The sum of N over the T test cases is at most 3 × 105 .


All input values are integers.
Input
The input is given from Standard Input in the following format, where casei represents the i-th test case:

T
case1 ​

case2 ​


caseT ​

Each test case is given in the following format:

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.

1. Mr. Ball chooses and gives a white ball.


2. Mr. Box accepts the ball, buys box 2 for 1 yen, and puts the white ball in it.
Box 2 contains 1 white ball. This satisfies the conditions, so Mr. Box receives 1 yen.
3. Mr. Ball chooses and gives a white ball.
4. Mr. Box accepts the ball and puts it in box 2.
Box 2 contains 2 white balls. This satisfies the conditions, so Mr. Box receives 1 yen.
5. Mr. Ball chooses and gives a black ball.
6. Mr. Box accepts the ball, buys box 3 for 1 yen, and puts the black ball in it.
Box 3 contains 1 black ball. This satisfies the conditions, so Mr. Box receives 1 yen.
7. Mr. Ball chooses and gives a white ball.
8. Mr. Box accepts the ball and puts it in box 2.
Box 2 contains 3 white balls. This satisfies the conditions, so Mr. Box receives 1 yen.
9. Mr. Ball chooses and gives a white ball.
10. Mr. Box chooses to end the game without accepting it.

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

Time Limit: 2 sec / Memory Limit: 1024 MB

Score : 900 points

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
​ ​ ​ ​ ​ ​


concatenation of sequences (V1 ), W1 , W2 , … , WV1 in this order equals (V1 , V2 , … , VM ).


​ ​ ​


​ ​ ​ ​

In particular, the sequence (0) is Polish.

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.
​ ​ ​

What is lexicographical order on sequences?

Constraints
1 ≤ N ≤ 3 × 105
0 ≤ Ai < N

All input values are integers.

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

(1, 1, 1, 1, 1, 0) and (1, 1, 1, 2, 0, 0) satisfy the conditions.


We can verify that (1, 1, 1, 2, 0, 0) is Polish as follows.

As stated in the problem statement, (0) is Polish.


(2, 0, 0) is Polish because it equals the concatenation of (2) and two Polish sequences (0) and (0) in
this order.
(1, 2, 0, 0) is Polish because it equals the concatenation of (1) and one Polish sequence (2, 0, 0) in
this order.
(1, 1, 2, 0, 0) is Polish because it equals the concatenation of (1) and one Polish sequence (1, 2, 0, 0)
in this order.
(1, 1, 1, 2, 0, 0) is Polish because it equals the concatenation of (1) and one Polish sequence
(1, 1, 2, 0, 0) in this order.

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

Time Limit: 2 sec / Memory Limit: 1024 MB

Score : 1000 points

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
​ ​

condition, modulo 998244353:

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

All input values are integers.

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

The following four sequences satisfy the condition:

(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

You might also like