Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
正整数 N が与えられます。1 以上 N 以下の正整数からなる集合 S であって、以下の条件を満たすものを良い集合といいます。
- 任意の S の要素 x,y に対して、x を y で割った余りは 1 ではない。
要素数が最大である良い集合を一つ構築してください。
制約
- 1 \le N \le 2 \times 10^5
入力
入力は以下の形式で標準入力から与えられる。
N
出力
あなたの構築した良い集合 S の要素数を k、要素を S = \lbrace S_1,S_2,\dots,S_k \rbrace としたとき、以下のように出力せよ。
k S_1\ S_2\ \dots\ S_k
答えが複数ある場合は、そのどれを出力しても正解になる。
入力例 1
5
出力例 1
2 3 5
例えば、\lbrace 3,5 \rbrace や \lbrace 2 \rbrace は良い集合です。逆に、\lbrace 2,3,5 \rbrace や \lbrace 1,2,3,4,5 \rbrace は良い集合ではありません。
要素数が 3 以上の良い集合は存在しないため、\lbrace 3,5 \rbrace は要素数が最大である良い集合の一つです。
入力例 2
2
出力例 2
1 2
Score : 300 points
Problem Statement
You are given a positive integer N. A set S of positive integers between 1 and N (inclusive) is called a good set if it satisfies the following condition:
- For every pair of elements x and y in S, the remainder when x is divided by y is not 1.
Construct one good set with the maximum possible number of elements.
Constraints
- 1 \le N \le 2 \times 10^{5}
Input
The input is given from Standard Input in the following format:
N
Output
Let k be the number of elements of the good set S you constructed, and let S = \lbrace S_1,S_2,\dots,S_k \rbrace be its elements. Output in the following format:
k S_1\ S_2\ \dots\ S_k
If multiple solutions exist, any of them will be accepted.
Sample Input 1
5
Sample Output 1
2 3 5
For example, \lbrace 3,5 \rbrace and \lbrace 2 \rbrace are good sets. On the other hand, \lbrace 2,3,5 \rbrace and \lbrace 1,2,3,4,5 \rbrace are not good sets.
No good set with three or more elements exists, so \lbrace 3,5 \rbrace is one of the good sets with the maximum number of elements.
Sample Input 2
2
Sample Output 2
1 2
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 500 点
問題文
X 個の 0、Y 個の 1、Z 個の 2 からなる長さ X+Y+Z の非負整数列 A=(A_1,A_2,\dots,A_{X+Y+Z}) であって、以下の条件を満たすものが存在するか判定してください。
- 全ての i(1 \le i \le X+Y+Z) に対して、A_{i-1},A_{i+1} のうち A_i 未満のものはちょうど A_i 個である。
ただし、A_0 = A_{X+Y+Z},A_{X+Y+Z+1} = A_1 とします。
T 個のテストケースが与えられるので、それぞれについて答えを求めてください。
制約
- 1 \le T \le 2 \times 10^5
- 0 \le X,Y,Z \le 10^9
- 3 \le X + Y + Z
入力
入力は以下の形式で標準入力から与えられる。
T
\mathrm{case}_1
\mathrm{case}_2
\vdots
\mathrm{case}_T
各ケースは以下の形式で与えられる。
X\ Y\ Z
出力
T 行出力せよ。i(1 \le i \le T) 行目には、i 個目のテストケースにおいて条件を満たすものが存在するなら Yes を、そうでないならば No を出力せよ。
入力例 1
4 2 1 1 3 4 5 1359 1998 1022 392848293 683919483 822948689
出力例 1
Yes No Yes No
1 個目のテストケースについて、A = (2,0,0,1) とすると条件を満たします。
2 個目のテストケースについて、条件を満たす数列は存在しません。
Score : 500 points
Problem Statement
Determine whether there exists a sequence A=(A_1,A_2,\dots,A_{X+Y+Z}) of length X+Y+Z that contains exactly X zeros, Y ones, and Z twos, and satisfies the following condition:
- For every i(1 \le i \le X+Y+Z), exactly A_i numbers among A_{i-1} and A_{i+1} are less than A_i.
Here, assume A_0 = A_{X+Y+Z} and A_{X+Y+Z+1} = A_1.
You are given T test cases. Solve each of them.
Constraints
- 1 \le T \le 2 \times 10^{5}
- 0 \le X,Y,Z \le 10^{9}
- 3 \le X + Y + Z
Input
The input is given from Standard Input in the following format:
T
\mathrm{case}_1
\mathrm{case}_2
\vdots
\mathrm{case}_T
Each test case is given in the following format:
X\ Y\ Z
Output
Output T lines. The i-th (1 \le i \le T) line should contain Yes if such a sequence exists, and No otherwise.
Sample Input 1
4 2 1 1 3 4 5 1359 1998 1022 392848293 683919483 822948689
Sample Output 1
Yes No Yes No
For the first test case, the sequence A = (2,0,0,1) satisfies the condition.
For the second test case, no sequence satisfies the condition.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 700 点
問題文
長さ N の整数列 A=(A_1,A_2,\dots,A_N) と B=(B_1,B_2,\dots,B_N) が与えられます。
あなたは以下の操作を 31000 回まで行うことができます。
- 1 \le i < j \le N を満たす整数の組 (i,j) を選び、A_i を A_j - 1 に、A_j を A_i + 1 に置き換える。
あなたの目標は A=B とすることです。目標が達成可能か判定し、可能な場合はそのような操作列を一つ出力してください。
制約
- 2 \le N \le 100
- 1 \le A_i,B_i \le 100
入力
入力は以下の形式で標準入力から与えられる。
N A_1\ A_2\ \dots\ A_N B_1\ B_2\ \dots\ B_N
出力
A = B とすることができるならば、Yes を、そうでないならば No を出力せよ。
更に、Yes の場合は以下の形式で操作列を出力せよ。
M i_1\ j_1 i_2\ j_2 \vdots i_M\ j_M
M は操作列の長さを表し、0 \le M \le 31000 を満たす必要がある。また、i_k,j_k は k 回目の操作で選ぶ i,j を表し、1 \le i_k < j_k \le N を満たす必要がある。
答えが複数ある場合は、そのどれを出力しても正解になる。
入力例 1
4 2 2 1 4 3 2 2 2
出力例 1
Yes 2 1 4 3 4
以下のように操作をすると A = B とすることができます。
- (i,j) = (1,4) を選ぶ。A = (3,2,1,3) となる。
- (i,j) = (3,4) を選ぶ。A = (3,2,2,2) となる。
操作回数を最小化する必要はないため、以下のような出力も正解です。
Yes 6 1 4 3 4 1 2 1 2 1 2 1 2
入力例 2
6 5 4 4 3 4 2 5 1 2 3 4 1
出力例 2
No
入力例 3
7 2 4 2 4 3 2 5 5 4 3 2 5 1 2
出力例 3
Yes 18 5 7 1 7 2 4 1 5 1 5 1 4 4 5 4 5 3 4 5 7 1 5 1 7 1 6 6 7 1 7 2 4 2 5 4 5
Score : 700 points
Problem Statement
You are given two integer sequences of length N: A=(A_1,A_2,\dots,A_N) and B=(B_1,B_2,\dots,B_N).
You may perform at most 31000 operations of the following kind:
- Choose a pair of integers (i,j) with 1 \le i < j \le N, then replace A_i with A_j - 1 and A_j with A_i + 1.
Your goal is to make A = B. Determine whether the goal is achievable, and if it is, output one sequence of operations that achieves it.
Constraints
- 2 \le N \le 100
- 1 \le A_i,B_i \le 100
Input
The input is given from Standard Input in the following format:
N A_1\ A_2\ \dots\ A_N B_1\ B_2\ \dots\ B_N
Output
If it is possible to make A = B, output Yes; otherwise, output No.
If you output Yes, also output an operation sequence in the following format:
M i_1\ j_1 i_2\ j_2 \vdots i_M\ j_M
M is the length of the operation sequence and must satisfy 0 \le M \le 31000. i_k, j_k are the indices i, j chosen in the k-th operation and must satisfy 1 \le i_k < j_k \le N.
If multiple solutions exist, any of them will be accepted.
Sample Input 1
4 2 2 1 4 3 2 2 2
Sample Output 1
Yes 2 1 4 3 4
The following operations make A = B:
- Choose (i,j) = (1,4). Then A = (3,2,1,3).
- Choose (i,j) = (3,4). Then A = (3,2,2,2).
Since minimizing the number of operations is not required, the following output is also accepted:
Yes 6 1 4 3 4 1 2 1 2 1 2 1 2
Sample Input 2
6 5 4 4 3 4 2 5 1 2 3 4 1
Sample Output 2
No
Sample Input 3
7 2 4 2 4 3 2 5 5 4 3 2 5 1 2
Sample Output 3
Yes 18 5 7 1 7 2 4 1 5 1 5 1 4 4 5 4 5 3 4 5 7 1 5 1 7 1 6 6 7 1 7 2 4 2 5 4 5
Time Limit: 5 sec / Memory Limit: 1024 MiB
配点 : 700 点
問題文
頂点に 1 から N の番号がついた N 頂点の木 T と N \times N 行列 A = (A_{i,j}) が与えられます。T の i 本目の辺は頂点 U_i と頂点 V_i を結ぶ辺です。また、A の成分は 0 または 1 です。
整数列 x=(x_1,x_2,\dots,x_N) のスコアを以下のように定義します。
- 頂点の組 (i,j)(1 \le i,j \le N) に対して、T における i から j への単純パスが通る頂点を v_1=i,v_2,\dots,v_n=j とする(T は木なので、単純パスが一意に定まる)。(i,j) が回文ペアであるとは、任意の k(1 \le k \le n) について、x_{v_k} = x_{v_{n+1-k}} が成り立つことと定義する。
- A_{i,j} = 1 かつ (i,j) が回文ペアでないような (i,j) が存在するとき、x のスコアは 10^{100} とする。
- そのような (i,j) が存在しないとき、x のスコアは 1 \le i,j \le N かつ (i,j) が回文ペアであるような (i,j) の個数とする。
全ての整数列 x に対する、スコアの最小値を求めてください。
制約
- 1 \le N \le 3000
- 1 \le U_i,V_i \le N
- T は木である。
- A_{i,j} \in \lbrace 0,1 \rbrace
- A_{i,i} = 1
- A_{i,j} = A_{j,i}
入力
入力は以下の形式で標準入力から与えられる。
N
U_1 V_1
U_2 V_2
\vdots
U_{N-1} V_{N-1}
A_{1,1}A_{1,2}\dots A_{1,N}
A_{2,1}A_{2,2}\dots A_{2,N}
\vdots
A_{N,1}A_{N,2}\dots A_{N,N}
出力
全ての整数列 x に対する、スコアの最小値を出力せよ。
入力例 1
4 1 2 1 3 1 4 1000 0101 0010 0101
出力例 1
6
例えば x = (1,2,4,2) のとき、A_{i,j} = 1 かつ (i,j) が回文ペアでないような (i,j) は存在しません。また、(i,j) が回文ペアであるようなものは (1,1),(2,2),(3,3),(4,4),(2,4),(4,2) の 6 個なので、スコアは 6 です。
他にも x = (1,2,3,4) のとき、(i,j) = (2,4) について A_{2,4} = 1 ですが、(2,4) が回文ペアでないためスコアは 10^{100} です。
入力例 2
7 7 2 4 1 6 5 1 6 3 4 2 3 1001000 0100000 0010000 1001001 0000100 0000010 0001001
出力例 2
13
入力例 3
10 7 5 10 3 7 6 6 10 8 3 9 3 5 4 1 5 2 10 1000000000 0100010000 0010010100 0001000000 0000100100 0110010000 0000001001 0010100110 0000000110 0000001001
出力例 3
66
Score : 700 points
Problem Statement
You are given a tree T with N vertices numbered 1 through N, and an N \times N matrix A = (A_{i,j}). The i-th edge of T connects vertices U_i and V_i. Each entry of A is 0 or 1.
Define the score of an integer sequence x=(x_1,x_2,\dots,x_N) as follows:
- For a vertex pair (i,j)(1 \le i,j \le N), let the simple path in T from i to j be v_1=i,v_2,\dots,v_n=j (this path is unique since T is a tree). The pair (i,j) is called a palindromic pair if x_{v_k} = x_{v_{n+1-k}} for every k(1 \le k \le n).
- If there exists a pair (i,j) such that A_{i,j} = 1 and (i,j) is not a palindromic pair, then the score of x is 10^{100}.
- Otherwise, the score of x is the number of pairs (i,j) such that 1 \le i,j \le N and (i,j) is a palindromic pair.
Find the minimum score over all integer sequences x.
Constraints
- 1 \le N \le 3000
- 1 \le U_i,V_i \le N
- T is a tree.
- A_{i,j} \in \lbrace 0,1 \rbrace
- A_{i,i} = 1
- A_{i,j} = A_{j,i}
Input
The input is given from Standard Input in the following format:
N
U_1 V_1
U_2 V_2
\vdots
U_{N-1} V_{N-1}
A_{1,1}A_{1,2}\dots A_{1,N}
A_{2,1}A_{2,2}\dots A_{2,N}
\vdots
A_{N,1}A_{N,2}\dots A_{N,N}
Output
Output the minimum score over all integer sequences x.
Sample Input 1
4 1 2 1 3 1 4 1000 0101 0010 0101
Sample Output 1
6
For example, when x = (1,2,4,2), there is no pair (i,j) such that A_{i,j}=1 and (i,j) is not a palindromic pair. The palindromic pairs are (1,1),(2,2),(3,3),(4,4),(2,4),(4,2), so the score is 6.
On the other hand, when x = (1,2,3,4), we have A_{2,4} = 1 while (2,4) is not a palindromic pair, so the score is 10^{100}.
Sample Input 2
7 7 2 4 1 6 5 1 6 3 4 2 3 1001000 0100000 0010000 1001001 0000100 0000010 0001001
Sample Output 2
13
Sample Input 3
10 7 5 10 3 7 6 6 10 8 3 9 3 5 4 1 5 2 10 1000000000 0100010000 0010010100 0001000000 0000100100 0110010000 0000001001 0010100110 0000000110 0000001001
Sample Output 3
66
Time Limit: 7 sec / Memory Limit: 1024 MiB
配点 : 900 点
問題文
0 以上 2^N 未満の非負整数からなる集合 S = \lbrace s_1,s_2,\dots,s_M \rbrace が与えられます。
あなたは非負整数 x = 0 を持っています。以下の操作を好きな回数行い、x = 2^N とする方法の個数を 998244353 で割った余りを求めてください。
- 1 \le i \le M を満たす整数 i を選び、x を (x\ \mathrm{OR}\ s_i) + 1 で置き換える。
ただし、\mathrm{OR} はビットごとの論理和を表します。
制約
- 1 \le N \le 24
- 1 \le M \le \min(2^N,2 \times 10^5)
- 0 \le s_1 < s_2 < \dots < s_M < 2^N
入力
入力は以下の形式で標準入力から与えられる。
N M s_1\ s_2\ \dots\ s_M
出力
操作方法の個数を 998244353 で割った余りを出力せよ。
入力例 1
2 2 1 2
出力例 1
5
i を選んで操作を行い、x = k となった場合、その遷移を (i, k) と表記します。条件を満たす方法は以下の 5 通りです。
- (1,2) \rightarrow (1,4)
- (1,2) \rightarrow (2,3) \rightarrow (1,4)
- (1,2) \rightarrow (2,3) \rightarrow (2,4)
- (2,3) \rightarrow (1,4)
- (2,3) \rightarrow (2,4)
x の遷移が完全に一致していても、i の選び方が異なる方法は区別して数え上げることに注意してください。
入力例 2
5 10 3 5 8 9 11 16 17 23 27 28
出力例 2
242816764
入力例 3
24 32 673802 709603 941436 987977 1288854 1448514 1890649 2031791 2194398 3531579 3540682 4352378 4676427 5094869 5243789 6064976 6412917 7164733 8403938 9123034 10396333 10558625 10726446 12263566 12421464 12503511 12676340 14032527 14268967 14669703 15823827 16285412
出力例 3
508425421
Score : 900 points
Problem Statement
You are given a set S = \lbrace s_1,s_2,\dots,s_M \rbrace of non-negative integers between 0 and 2^N - 1 (inclusive).
You start with a non-negative integer x = 0. Find the number, modulo 998244353, of ways to reach x = 2^N by performing the following operation any number of times:
- Choose an integer i with 1 \le i \le M, and replace x with (x\ \mathrm{OR}\ s_i) + 1.
Here, \mathrm{OR} denotes the bitwise logical OR.
Constraints
- 1 \le N \le 24
- 1 \le M \le \min(2^N,2 \times 10^{5})
- 0 \le s_1 < s_2 < \dots < s_M < 2^N
Input
The input is given from Standard Input in the following format:
N M s_1\ s_2\ \dots\ s_M
Output
Output the number of ways, modulo 998244353.
Sample Input 1
2 2 1 2
Sample Output 1
5
Let (i, k) denote the transition when an operation chooses i and results in x = k. There are five ways that satisfy the conditions:
- (1,2) \rightarrow (1,4)
- (1,2) \rightarrow (2,3) \rightarrow (1,4)
- (1,2) \rightarrow (2,3) \rightarrow (2,4)
- (2,3) \rightarrow (1,4)
- (2,3) \rightarrow (2,4)
Even if the sequence of values of x is identical, ways that differ in the choices of i are counted separately.
Sample Input 2
5 10 3 5 8 9 11 16 17 23 27 28
Sample Output 2
242816764
Sample Input 3
24 32 673802 709603 941436 987977 1288854 1448514 1890649 2031791 2194398 3531579 3540682 4352378 4676427 5094869 5243789 6064976 6412917 7164733 8403938 9123034 10396333 10558625 10726446 12263566 12421464 12503511 12676340 14032527 14268967 14669703 15823827 16285412
Sample Output 3
508425421