A - Appraiser

実行時間制限: 2 sec / メモリ制限: 1024 MiB

配点 : 600

問題文

この問題は インタラクティブ な問題であり、 ジャッジは適応的(adaptive) です。詳しくは注意点を参照してください。
また、問題文中のパラメータは N=1000,M=10,Q=950 で固定されています。

硬貨が N 枚あり、 1,2,\dots,N の番号が付けられています。
これらの硬貨のうち、丁度 M 枚が偽物です。

鑑定士は 1 度の鑑定で 2 つの硬貨が同種か異種かを判定できます。厳密には、

  • 2 つの硬貨が「双方とも本物」「双方とも偽物」のどちらかであれば、同種と判定する。
  • そうでないとき、異種と判定する。

Q 回以下の鑑定で、全ての偽物の硬貨を特定してください。

制約

  • \color{red}{N = 1000}
  • \color{red}{M = 10}
  • \color{red}{Q = 950}

入出力

この問題はインタラクティブな問題です。
最初に、 N,M,Q を標準入力から受け取ってください。

N M Q


次に、以下の流れで鑑定を 0 回以上 Q 回以下行ってください。

まず、次の形式で標準出力に出力することで、硬貨 x,y を鑑定することを表します。 (末尾に改行を入れること。)

? x y

ここで、 x,y1 以上 N 以下の相異なる整数である必要があります。

これに対するジャッジシステムの応答は、以下の 3 通りです。

0

応答が 0 であるとき、硬貨 x,y が同種であることを表します。

1

応答が 1 であるとき、硬貨 x,y が異種であることを表します。

-1

応答が -1 であるとき、不当な鑑定であることを表します。具体的には

  • 出力した x,y が制約を満たさなかった
  • Q 回を超えて鑑定が行われた

の少なくともひとつが満たされた際にこの応答を行います。
この応答を受け取った場合、プログラムはすでに不正解とみなされています。直ちにプログラムを終了してください。


最後に、次の形式で標準出力に出力することで、硬貨 A_1,A_2,\dots,A_{M} が偽物であると解答します。 (末尾に改行を入れること。)

! A_1 A_2 \dots A_{M}

ここで、 A_i1 以上 N 以下の相異なる整数である必要があります。
この出力の後、直ちにプログラムを終了してください。

なお、全ての出力について、出力が指定された形式を満たさなかった場合もプログラムが不正解とみなされます。 その後 -1 が返答されるので、その場合も直ちにプログラムを終了してください。

注意点

  • 出力を行うたびに、末尾に改行を入れて標準出力を flush してください。 そうしなかった場合、ジャッジ結果が TLEWA となる可能性があります。
  • 解答を出力したら (または -1 を受け取ったら) ただちにプログラムを終了してください。そうしない場合、ジャッジ結果は不定です。
  • 余計な改行は不正なフォーマットの出力とみなされることに注意してください。
  • この問題のジャッジシステムは、適応的(adaptive)です。 つまり、ジャッジシステムは、任意のタイミングにおいて、整合性がとれる限り、偽物の硬貨として想定しているものを変更する可能性があります。詳しくは入出力例も参照してください。

入出力例

この入力では N=5,M=2,Q=10 であり、ジャッジシステムは最初硬貨 1,2 が偽物であると想定しています。

なお、この例は制約を満たさないので、ジャッジには含まれないことに注意してください。

入力 出力 説明
5 2 10 N,M,Q が与えられます。
? 1 2 硬貨 1,2 について鑑定を行います。
0 硬貨 1,2 は同種だと判定します。
? 1 3 硬貨 1,3 について鑑定を行います。
1 硬貨 1,3 は異種だと判定します。
? 1 4 硬貨 1,4 について鑑定を行います。
1 硬貨 1,4 は異種だと判定します。
! 1 2 硬貨 1,2 が偽物だと解答します。
確かに硬貨 1,2 は偽物だと想定されていますが、硬貨 3,4 を偽物であると想定しても整合性が取れます。
よって、ジャッジシステムは偽物の硬貨として想定しているものを硬貨 3,4 に変更できます。
これにより、ジャッジシステムは不正解の判定を下すこともあります。

Score : 600 points

Problem Statement

This problem is interactive, and the judge is adaptive. See the notes for details.
Also, the parameters in the problem statement are fixed at N=1000, M=10, Q=950.

There are N coins numbered 1, 2, \dots, N.
Exactly M of these coins are counterfeit.

An appraiser can, in one appraisal, determine whether two coins are of the same type or different types. Specifically:

  • If the two coins are both genuine or both counterfeit, they are judged to be of the same type.
  • Otherwise, they are judged to be of different types.

Identify all the counterfeit coins using at most Q appraisals.

Constraints

  • \color{red}{N = 1000}
  • \color{red}{M = 10}
  • \color{red}{Q = 950}

Interaction

This is an interactive problem.
Initially, receive N, M, and Q from Standard Input:

N M Q


Next, you can perform appraisals between 0 and Q times, inclusive, as follows.

First, by outputting to Standard Output in the following format, you indicate that you are appraising coins x and y. (Include a newline at the end.)

? x y

Here, x and y must be distinct integers between 1 and N, inclusive.

In response, the judge system will reply with one of the following three responses.

0

If the response is 0, it means that coins x and y are of the same type.

1

If the response is 1, it means that coins x and y are of different types.

-1

If the response is -1, it means that the appraisal is invalid. Specifically, this response is given when at least one of the following conditions is met:

  • The outputted x and y does not satisfy the constraints.
  • The number of appraisals exceeds Q.

If you receive this response, your program is considered incorrect. Terminate your program immediately.


Finally, by outputting to Standard Output in the following format, you answer that coins A_1, A_2, \dots, A_{M} are counterfeit. (Include a newline at the end.)

! A_1 A_2 \dots A_{M}

Here, A_i must be distinct integers between 1 and N, inclusive.
After this output, terminate your program immediately.

If any of your outputs do not meet the specified format, your program will be considered incorrect. The judge will then respond with -1, so in that case, terminate your program immediately.

Notes

  • Every time you output, include a newline at the end and flush Standard Output. Failure to do so may result in a verdict of TLE or WA.
  • After outputting your answer (or receiving -1), terminate your program immediately. Otherwise, the verdict is indeterminate.
  • Beware that unnecessary newlines are considered as malformed.
  • The judge for this problem is adaptive. That is, at any point, as long as consistency can be maintained, the judge may change which coins are counterfeit. See the sample interaction for details.

Sample Interaction

In this interaction, N=5, M=2, Q=10, and the judge initially considers coins 1 and 2 to be counterfeit.

Note that this example does not meet the constraints and is not included in the judge.

Input  Output Explanation
5 2 10 N, M, and Q are given.
? 1 2 You appraise coins 1 and 2.
0 Coins 1 and 2 are judged to be of the same type.
? 1 3 You appraise coins 1 and 3.
1 Coins 1 and 3 are judged to be of different types.
? 1 4 You appraise coins 1 and 4.
1 Coins 1 and 4 are judged to be of different types.
! 1 2 You answer that coins 1 and 2 are counterfeit.
Indeed, coins 1 and 2 are considered counterfeit, but it is also possible to consider coins 3 and 4 as counterfeit while maintaining consistency.
Therefore, the judge may change the counterfeit coins to 3 and 4.
As a result, the judge may judge this answer as incorrect.
B - 123 Set

実行時間制限: 8 sec / メモリ制限: 1024 MiB

配点 : 700

問題文

正整数 N が与えられます。空集合 S があり、あなたは以下の操作を何回でも行うことができます。

  • 正整数 x を自由に選ぶ。x, 2x, 3x それぞれについて、もし S に含まれなければ追加する。

\{1, 2, \dots ,N\} \subseteq S を満たすまでに必要な操作回数の最小値を求めてください。

制約

  • 1 \leq N \leq 10^{9}

入力

入力は以下の形式で標準入力から与えられる。

N

出力

答えを 1 行に出力せよ。


入力例 1

7

出力例 1

4

1, 2, 5, 7 を選ぶことで S = \{1, 2, 3, 4, 5, 6, 7, 10, 14, 15, 21\} となり条件を満たします。3 回以下の操作で条件を満たすことはできません。


入力例 2

25

出力例 2

14

Score : 700 points

Problem Statement

You are given a positive integer N. There is an empty set S, and you can perform the following operation any number of times:

  • Choose any positive integer x. For each of x, 2x, and 3x, add it to S if it is not already in S.

Find the minimum number of operations required to satisfy \{1, 2, \dots, N\} \subseteq S.

Constraints

  • 1 \leq N \leq 10^{9}

Input

The input is given from Standard Input in the following format:

N

Output

Print the answer in one line.


Sample Input 1

7

Sample Output 1

4

Choosing 1, 2, 5, and 7 yields S = \{1, 2, 3, 4, 5, 6, 7, 10, 14, 15, 21\}, which satisfies the condition. It is impossible to satisfy the condition with three or fewer operations.


Sample Input 2

25

Sample Output 2

14
C - Mountain and Valley Folds

実行時間制限: 2 sec / メモリ制限: 1024 MiB

配点 : 900

問題文

厚さを無視できる細長い紙があります。右端を持ち上げ、中央を折り目にして左端に合わせて折りたたむ操作を 100 回行い、もとに戻します。このとき紙には折り目が 2^{100} - 1 個あり、これらは山折り、谷折りの 2 種類に分類できます。下の図は 2 回操作を行った状態を表した図で、赤い実線は山折り、赤い点線は谷折りを表します。

山折り、谷折りとは
  • ある折り目が山折りであるとは、折り目が紙の裏面同士が重なる方向に折られたことをいいます。
  • ある折り目が谷折りであるとは、折り目が紙の表面同士が重なる方向に折られたことをいいます。

image of folds

長さ N の非負整数列 A = (A_1, A_2, \dots ,A_N) が与えられます。ここで 0 = A_1 < A_2 < \dots < A_N \leq 10^{18} です。

1 以上 2^{100} - A_N - 1 以下の整数 i に対し、 f(i) を以下のように定義します。

  • k = 1, 2, \dots ,N のうち、左から i + A_k 番目の折り目が山折りであるものの個数

f(1), f(2), \dots ,f(2^{100} - A_N - 1) の最大値を求めてください。

制約

  • 1 \leq N \leq 10^3
  • 0 = A_1 < A_2 < \dots < A_N \leq 10^{18}

入力

入力は以下の形式で標準入力から与えられる。

N
A_1 A_2 \cdots A_N

出力

答えを 1 行に出力せよ。


入力例 1

4
0 1 2 3

出力例 1

3

山折り、谷折りをそれぞれ M, V と表すことにすると、折り目には MMVM と連続する箇所が存在します。MMMM と連続する箇所は存在しないので、答えは 3 となります。


入力例 2

6
0 2 3 5 7 8

出力例 2

4

Score : 900 points

Problem Statement

We have a long, thin piece of paper whose thickness can be ignored. We perform the following operation 100 times: lift the right end, fold it so that it aligns with the left end using the center as a crease. After completing the 100 folds, we unfold the paper back to its original state. At this point, there are 2^{100} - 1 creases on the paper, and these creases can be classified into two types: mountain folds and valley folds. The figure below represents the state after performing the operation twice, where red solid lines represent mountain folds and red dashed lines represent valley folds.

About mountain and valley folds
  • A crease is a mountain fold if it is folded so that the back sides of the paper come together at the crease.
  • A crease is a valley fold if it is folded so that the front sides of the paper come together at the crease.

image of folds

You are given a sequence A = (A_1, A_2, \dots, A_N) of N non-negative integers. Here, 0 = A_1 < A_2 < \dots < A_N \leq 10^{18}.

For each integer i from 1 through 2^{100} - A_N - 1, define f(i) as follows:

  • The number of k = 1, 2, \dots, N such that the (i + A_k)-th crease from the left is a mountain fold.

Find the maximum value among f(1), f(2), \dots, f(2^{100} - A_N - 1).

Constraints

  • 1 \leq N \leq 10^3
  • 0 = A_1 < A_2 < \dots < A_N \leq 10^{18}

Input

The input is given from Standard Input in the following format:

N
A_1 A_2 \cdots A_N

Output

Print the answer in one line.


Sample Input 1

4
0 1 2 3

Sample Output 1

3

If mountain and valley folds are represented by M and V, respectively, there is a contiguous subsequence of creases like MMVM. There is no contiguous subsequence like MMMM, so the answer is 3.


Sample Input 2

6
0 2 3 5 7 8

Sample Output 2

4
D - Erase Balls 2D

実行時間制限: 2 sec / メモリ制限: 1024 MiB

配点 : 1000

問題文

2 次元平面上に 1 から N までの番号のついた N 個のボールがあり、ボール i は点 (X_i, Y_i) にあります。ここで、 X = (X_1, X_2, \dots ,X_N), Y = (Y_1, Y_2, \dots ,Y_N) はそれぞれ (1, 2, \dots ,N) の順列です。

あなたは以下の操作を好きなだけ行うことができます。

  • 残っているボールを 1 つ選ぶ。選んだボールを k とする。今残っている全てのボール i について、「X_i < X_k かつ Y_i < Y_k」もしくは「X_i > X_k かつ Y_i > Y_k」を満たすならばボール i を取り除く。

操作をした後に残っているボールの集合としてあり得るものの個数を \text{mod } 998244353 で出力してください。

制約

  • 1 \leq N \leq 300
  • X, Y はそれぞれ (1, 2, \dots ,N) の順列

入力

入力は以下の形式で標準入力から与えられる。

N
X_1 Y_1
X_2 Y_2
\vdots
X_N Y_N

出力

答えを 1 行に出力せよ。


入力例 1

3
1 3
2 1
3 2

出力例 1

3

操作後に残っているボールの集合として、 \{1, 2, 3\}, \{1, 3\}, \{1, 2\} があり得ます。


入力例 2

4
4 2
2 1
3 3
1 4

出力例 2

3

Score : 1000 points

Problem Statement

There are N balls on a two-dimensional plane, numbered from 1 to N. Ball i is at point (X_i, Y_i). Here, X = (X_1, X_2, \dots, X_N) and Y = (Y_1, Y_2, \dots, Y_N) are permutations of (1, 2, \dots, N).

You can perform the following operation any number of times:

  • Choose one of the remaining balls, say ball k. Then, for each remaining ball i, if either "X_i < X_k and Y_i < Y_k" or "X_i > X_k and Y_i > Y_k" holds, remove ball i.

Find the number of possible sets of balls remaining after performing operations, modulo 998244353.

Constraints

  • 1 \leq N \leq 300
  • X and Y are permutations of (1, 2, \dots, N).

Input

The input is given from Standard Input in the following format:

N
X_1 Y_1
X_2 Y_2
\vdots
X_N Y_N

Output

Print the answer in one line.


Sample Input 1

3
1 3
2 1
3 2

Sample Output 1

3

The possible sets of balls remaining after operations are \{1, 2, 3\}, \{1, 3\}, and \{1, 2\}.


Sample Input 2

4
4 2
2 1
3 3
1 4

Sample Output 2

3
E - Accumulating Many Times

実行時間制限: 2 sec / メモリ制限: 1024 MiB

配点 : 1000

問題文

各要素が 0, 1 の長さ M の整数列が N 個与えられます。i 番目の整数列は A_i = (A_{i, 1}, A_{i, 2}, \dots ,A_{i, M}) です。

整数 i, j \ (1 \leq i, j \leq N) に対して f(i, j) を以下のように定義します。

  • f(i, j) := 非負整数 x であって、以下の操作を x 回行うと A_iA_j が一致する最小のもの。ただしそのような x が存在しない場合は 0 とする。
    • 全ての整数 k \ (1 \leq k \leq M) について同時に、 A_{i, k}\displaystyle \left (\sum_{l=1}^{k} A_{i, l} \right ) \bmod 2 に置き換える。

\displaystyle \sum_{i=1}^{N} \sum_{j=i}^{N} f(i, j)\text{mod } 998244353 で求めてください。

制約

  • 1 \leq N \times M \leq 10^6
  • A_{i, j} \in \{0, 1\}

入力

入力は以下の形式で標準入力から与えられる。

N M
A_{1, 1} A_{1, 2} \cdots A_{1, M}
A_{2, 1} A_{2, 2} \cdots A_{2, M}
\vdots
A_{N, 1} A_{N, 2} \cdots A_{N, M}

出力

答えを 1 行に出力せよ。


入力例 1

4 3
1 0 0
1 1 0
1 0 1
0 1 1

出力例 1

8

f(1, 1) = 0, f(1, 2) = 3, f(1, 3) = 2, f(1, 4) = 0, f(2, 2) = 0, f(2, 3) = 3, f(2, 4) = 0, f(3, 3) = 0, f(3, 4) = 0, f(4, 4) = 0 なので、総和の 8 を出力します。


入力例 2

7 6
1 0 0 0 0 0
1 1 1 0 0 0
1 0 1 1 0 0
1 0 0 0 1 1
1 0 0 0 0 1
1 0 0 0 0 0
1 1 1 1 1 1

出力例 2

6

Score : 1000 points

Problem Statement

You are given N length-M sequences, where each element is 0 or 1. The i-th sequence is A_i = (A_{i, 1}, A_{i, 2}, \dots, A_{i, M}).

For integers i, j \ (1 \leq i, j \leq N), define f(i, j) as follows:

  • f(i, j) := The smallest non-negative integer x such that A_i and A_j become identical after performing the following operation x times, or 0 if such x does not exist.
    • For all integers k \ (1 \leq k \leq M) simultaneously, replace A_{i, k} with \displaystyle \left (\sum_{l=1}^{k} A_{i, l} \right ) \bmod 2.

Find \displaystyle \sum_{i=1}^{N} \sum_{j=i}^{N} f(i, j), modulo 998244353.

Constraints

  • 1 \leq N \times M \leq 10^6
  • A_{i, j} \in \{0, 1\}

Input

The input is given from Standard Input in the following format:

N M
A_{1, 1} A_{1, 2} \cdots A_{1, M}
A_{2, 1} A_{2, 2} \cdots A_{2, M}
\vdots
A_{N, 1} A_{N, 2} \cdots A_{N, M}

Output

Print the answer in one line.


Sample Input 1

4 3
1 0 0
1 1 0
1 0 1
0 1 1

Sample Output 1

8

f(1, 1) = 0, f(1, 2) = 3, f(1, 3) = 2, f(1, 4) = 0, f(2, 2) = 0, f(2, 3) = 3, f(2, 4) = 0, f(3, 3) = 0, f(3, 4) = 0, f(4, 4) = 0, so print their sum, 8.


Sample Input 2

7 6
1 0 0 0 0 0
1 1 1 0 0 0
1 0 1 1 0 0
1 0 0 0 1 1
1 0 0 0 0 1
1 0 0 0 0 0
1 1 1 1 1 1

Sample Output 2

6