A - Dodecagon

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 500

問題文

すぬけ君は、正方形のタイルと正三角形のタイルを無限枚持っています。タイルの辺の長さは全て 1 です。 これらを使って、辺の長さが d の正 12 角形を作る方法は何通りあるでしょうか。 この答えを 998,244,353 で割った余りを計算してください。

厳密に述べると、

  • タイルを使う枚数に制限はありません。
  • 使ったタイルのうち、どの 2 枚も重なっていてはいけません。
  • 使ったタイルが覆う領域の和集合は、穴のない正 12 角形でなければなりません。
  • 二つの作り方について、一方に回転と平行移動を施す (鏡映は不可) ことでもう一方を得られる、すなわち一方における各タイルがもう一方における同種のタイルと完全に一致するとき、これらの作り方を同一とみなします。

制約

  • 1 \leq d \leq 10^6
  • 入力中の全ての値は整数である。

入力

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

d

出力

答えを出力せよ。


入力例 1

1

出力例 1

1

唯一の作り方を以下の図に示します。

Score : 500 points

Problem Statement

Snuke has infinite number of square tiles and regular triangular tiles with side lengths 1. How many ways are there to form a regular dodecagon (12-sided polygon) with side lengths d using the tiles? Compute the answer modulo 998,244,353.

Formally speaking,

  • He can use an arbitrary number of tiles.
  • No two tiles may overlap.
  • The union of the regions filled by the tiles must be a regular dodecagon without holes.
  • We consider two ways to be the same if we can change one way to the other way by rotations and translations (but not reflections), such that each tile perfectly matches with a tile of the same type.

Constraints

  • 1 \leq d \leq 10^6
  • All values in the input are integers.

Input

Input is given from Standard Input in the following format:

d

Output

Print the answer.


Sample Input 1

1

Sample Output 1

1

The following picture shows the only way.

B - Bowling

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 800

問題文

平面上にボウリングのピンが何本か立っており、それを 4 人の人が異なる角度から眺めています。 1 人にだけ他の人より遥かに多くのピンが見えることはあるでしょうか。

ピンを単純に xy 平面上の点集合とみなしましょう。 4 人の位置を以下の図に示します。 厳密には、

  • A さんから見ると、y 座標が等しい 2 本のピンは重なって見えます。
  • B さんから見ると、(x 座標 - y 座標) が等しい 2 本のピンは重なって見えます。
  • C さんから見ると、x 座標が等しい 2 本のピンは重なって見えます。
  • D さんから見ると、(x 座標 + y 座標) が等しい 2 本のピンは重なって見えます。

A, B, C, D さんに見えるピンの数をそれぞれ a, b, c, d とします。

以下の条件を全て満たすような何らかのピンの配置を構成してください。

  • d \geq 10 \cdot \max \{ a, b, c \}
  • ピンの本数は 1 本以上 10^5 本以下である。
  • ピンの座標は全て 0 以上 10^9 以下の整数である。
  • 2 本のピンが同じ位置にあることはない。

入力

入力はない。

出力

答えを以下の形式で出力せよ。ここで、N はピンの本数、(x_i, y_i)i 本目のピンの座標である。

N
x_1 y_1
:
x_N y_N

出力は、問題文中の条件を満たすものでなければならない。


入力例 1


出力例 1

9
1 1
1 5
2 7
4 4
5 3
6 8
7 5
8 2
8 7

この出力例は出力形式を例示するものであり、正解ではありません。

この出力は問題文中の図に対応し、d = 8, a = b = c = 7 です。頑張りましたが、AC には届きません。

Score : 800 points

Problem Statement

There are some number of bowling pins on a plane. Four people are observing the pins from different angles. Is it possible that one of the observers sees much more pins than the others?

Let's model the pins as a set of points on an xy-plane. The image below shows the positions of the four observers. Formally,

  • For observer A, two pins overlap if their y-coordinates are the same.
  • For observer B, two pins overlap if their values of (x-coordinate minus y-coordinate) are the same.
  • For observer C, two pins overlap if their x-coordinates are the same.
  • For observer D, two pins overlap if their values of (x-coordinate plus y-coordinate) are the same.

Let a, b, c, d be the number of pins the observers A, B, C, D see, respectively.

Construct any arrangement of bowling pins that satisfies the following constraints:

  • d \geq 10 \cdot \max \{ a, b, c \}
  • The number of pins is between 1 and 10^5, inclusive.
  • The coordinates are integers between 0 and 10^9, inclusive.
  • No two pins are placed at exactly the same place.

Input

There is no input.

Output

Print the answer in the following format, where N is the number of pins and (x_i, y_i) are the coordinates of the i-th pin:

N
x_1 y_1
:
x_N y_N

It must satisfy the conditions in the statement.


Sample Input 1


Sample Output 1

9
1 1
1 5
2 7
4 4
5 3
6 8
7 5
8 2
8 7

This sample output is provided for the sake of showing the output format and is not correct.

It matches the picture in the statement.

Here, d = 8 and a = b = c = 7. Nice try, but not enough to get AC.

C - Flipper

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 1300

問題文

10^9 \times 10^9 個のマスが正方形状に並んでおり、(1, 1) から (10^9, 10^9) までの番号が振られています。 マス (i, j) は上から i 列目、左から j 列目のマスです。 はじめ、N マス (x_1, y_1), \ldots, (x_N, y_N) が黒で、他の全てのマスは白です。

すぬけ君は、以下の操作を何度でも行うことができます。

  • 整数 x (1 \leq x \leq 10^9 - 1) と整数 y (1 \leq y \leq 10^9 - 2) を選び、6 マス (x, y), (x, y+1), (x, y+2), (x+1, y), (x+1, y+1), (x+1, y+2) の色を反転させる (黒は白に、白は黒になる)

操作を済ませた後の黒マスの数として考えられる最小のものを計算してください。

制約

  • 1 \leq N \leq 10^5
  • 1 \leq x_i, y_i \leq 10^9
  • (x_i, y_i) は互いに異なる。
  • 入力中の全ての値は整数である。

入力

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

N
x_1 \ y_1
:
x_N \ y_N

出力

答えを出力せよ。


入力例 1

9
1 2
1 3
2 1
2 3
2 4
3 2
3 3
3 4
4 2

出力例 1

3

以下の図で、上から i 個目の文字列の j 文字目がマス (i, j) を表します。# が黒、. が白です。

.##.
#.##
.###
.#..

->

#...
.#.#
.###
.#..

->

#...
..#.
....
.#..

Score : 1300 points

Problem Statement

There is a square grid of dimensions 10^9 \times 10^9. The cells are numbered (1, 1) through (10^9, 10^9). Cell (i, j) is in the i-th row from the top, and the j-th column from the left. Initially, N cells (x_1, y_1), \ldots, (x_N, y_N) are black, and all other cells are white.

Snuke can perform the following operation an arbitrary number of times:

  • Choose an integer x (1 \leq x \leq 10^9 - 1) and an integer y (1 \leq y \leq 10^9 - 2), and flip (black to white, white to black) the colors of the following six cells: (x, y), (x, y+1), (x, y+2), (x+1, y), (x+1, y+1), (x+1, y+2)

Compute the minimum possible number of black cells after the operations.

Constraints

  • 1 \leq N \leq 10^5
  • 1 \leq x_i, y_i \leq 10^9
  • (x_i, y_i) are pairwise distinct.
  • All values in the input are integers.

Input

Input is given from Standard Input in the following format:

N
x_1 \ y_1
:
x_N \ y_N

Output

Print the answer.


Sample Input 1

9
1 2
1 3
2 1
2 3
2 4
3 2
3 3
3 4
4 2

Sample Output 1

3

In the diagram below, the j-th letter of the i-th string from the top represents the cell (i, j). # is black, . is white.

.##.
#.##
.###
.#..

->

#...
.#.#
.###
.#..

->

#...
..#.
....
.#..
D - C4

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 1800

問題文

以下の無向グラフにおいて、S から S へのウォークであって辺 ST, TU, UV, VS をそれぞれ a, b, c, d 回通るもの (向きは不問) の数を 998,244,353 で割った余りを求めてください。

注記

S から S へのウォークとは、頂点の列 v_0 = S, v_1, \ldots, v_k = S であって、各 i (0 \leq i < k) について v_iv_{i+1} を結ぶ辺があるものをいいます。 2 つのウォークは、列として異なるときに異なるとみなされます。

制約

  • 1 \leq a, b, c, d \leq 500,000
  • 入力中の全ての値は整数である。

入力

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

a b c d

出力

答えを出力せよ。


入力例 1

2 2 2 2

出力例 1

10

条件を満たすウォークは 10 個あり、その一例は S \rightarrow T \rightarrow U \rightarrow V \rightarrow U \rightarrow T \rightarrow S \rightarrow V \rightarrow S です。


入力例 2

1 2 3 4

出力例 2

0

入力例 3

470000 480000 490000 500000

出力例 3

712808431

Score : 1800 points

Problem Statement

In the following undirected graph, count the number of walks from S to S that pass through the edges ST, TU, UV, VS (in any direction) exactly a, b, c, d times, respectively, modulo 998,244,353.

Notes

A walk from S to S is a sequence of vertices v_0 = S, v_1, \ldots, v_k = S such that for each i (0 \leq i < k), there is an edge between v_i and v_{i+1}. Two walks are considered distinct if they are distinct as sequences.

Constraints

  • 1 \leq a, b, c, d \leq 500,000
  • All values in the input are integers.

Input

Input is given from Standard Input in the following format:

a b c d

Output

Print the answer.


Sample Input 1

2 2 2 2

Sample Output 1

10

There are 10 walks that satisfy the condition. One example of such a walk is S \rightarrow T \rightarrow U \rightarrow V \rightarrow U \rightarrow T \rightarrow S \rightarrow V \rightarrow S.


Sample Input 2

1 2 3 4

Sample Output 2

0

Sample Input 3

470000 480000 490000 500000

Sample Output 3

712808431
E - Middle Point

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 2000

問題文

平面上に、はじめ N(x_1, y_1), \ldots, (x_N, y_N) が打たれています。 すぬけ君は、以下の操作を任意の有限回行うことができます。

  • すでに打たれている 2 点を選び、その中点を打つ (その点がまだ打たれていない場合に限る)。中点が格子点である必要はない。

操作を済ませたら、打たれている格子点の数 (はじめの N 点を含む) がすぬけ君の得点となります。 獲得可能な最高得点を計算してください。

制約

  • 3 \leq N \leq 100
  • 0 \leq x_i, y_i \leq 10^9
  • どの 3 点も同一直線上にない。
  • 入力中の全ての値は整数である。

入力

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

N
x_1 y_1
:
x_N y_N

出力

答えを出力せよ。


入力例 1

4
0 0
0 2
2 0
2 2

出力例 1

9

最高得点を得る方法の一例は以下の通りです。

  • はじめ、4(0, 0), (0, 2), (2, 0), (2, 2) が打たれている。
  • (0, 0)(0, 2) の中点 (0, 1) を打つ。
  • (0, 0)(0, 1) の中点 (0, 0.5) を打つ。
  • (0, 0)(2, 0) の中点 (1, 0) を打つ。
  • (0, 0)(2, 2) の中点 (1, 1) を打つ。
  • (0, 2)(2, 2) の中点 (1, 2) を打つ。
  • (2, 0)(2, 2) の中点 (2, 1) を打つ。
  • 以上で 10(0, 0), (0, 0.5), (0, 1), (0, 2), (1, 0), (1, 1), (1, 2), (2, 0), (2, 1), (2, 2) が打たれた。そのうち 9 点が格子点であるため、9 点を得る。

入力例 2

4
0 0
0 3
3 0
3 3

出力例 2

4

はじめの N 点の他に格子点を打てないことが証明できます。

Score : 2000 points

Problem Statement

Initially, N points (x_1, y_1), \ldots, (x_N, y_N) are plotted on a plane. Snuke is allowed to perform the following operation an arbitrary finite number of times:

  • Choose two points that are already plotted, and plot the middle point of the two chosen points (if the middle point hasn't been plotted yet). The coordinates of the middle point don't necessarily have to be integers.

After he finish performing operations, his score is the number of plotted points with integer coordinates (including the initial points). Compute the maximum score he can get.

Constraints

  • 3 \leq N \leq 100
  • 0 \leq x_i, y_i \leq 10^9
  • No three points are on the same line.
  • All values in the input are integers.

Input

Input is given from Standard Input in the following format:

N
x_1 y_1
:
x_N y_N

Output

Print the answer.


Sample Input 1

4
0 0
0 2
2 0
2 2

Sample Output 1

9

One possible way to achieve the maximum score is as follows:

  • Initially, four points (0, 0), (0, 2), (2, 0), (2, 2) are plotted.
  • Plot (0, 1): the middle point of (0, 0) and (0, 2).
  • Plot (0, 0.5): the middle point of (0, 0) and (0, 1).
  • Plot (1, 0): the middle point of (0, 0) and (2, 0).
  • Plot (1, 1): the middle point of (0, 0) and (2, 2).
  • Plot (1, 2): the middle point of (0, 2) and (2, 2).
  • Plot (2, 1): the middle point of (2, 0) and (2, 2).
  • Now we have 10 points: (0, 0), (0, 0.5), (0, 1), (0, 2), (1, 0), (1, 1), (1, 2), (2, 0), (2, 1), (2, 2). 9 of them have integer coordinates, so the score is 9.

Sample Input 2

4
0 0
0 3
3 0
3 3

Sample Output 2

4

We can prove that, besides the initial points, he can't plot any points with integer coordinates.

F - rng_58's Last Problem

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 2400

問題文

砂時計が 2 つあり、一方は 1 秒計、もう一方は \sqrt{2} 秒計です。 これで x + y \sqrt{2} 秒を測ることは可能でしょうか。

厳密に述べましょう。 2 つの砂時計 A, B があり、各砂時計には砂が入る 2 つの「球」があります。 各砂時計は、縦か横に置くことができます。 縦に置くと、上の球が砂を含む限り、砂が下の球に 1 秒あたり 1 グラムの速さで流れ続けます。 横に置くと、砂は流れません。 縦に置く方法はどちらの球が上になるかで 2 通りあるため、各砂時計は合計で 3 通りの状態のいずれかにあります。

砂時計 A に含まれる砂の量は 1 グラム、砂時計 B に含まれる砂の量は \sqrt{2} グラムです。したがって、砂時計 A が縦に置かれ、砂が全て上の球にあるとき、砂が下の球に落ち切るまでに 1 秒を要します。 同様に、砂時計 B はこれに \sqrt{2} 秒を要します。

はじめ、砂時計 A, B はともに縦に置かれており、砂は全て下の球にあります。 すぬけ君が叫ぶまでは、何にも触れてはいけません。 すぬけ君の叫びからちょうど t 秒後に 出来事 (後述) が起こったとき、t 秒を測れたといいます。

出来事 が起こったとは、以下のいずれかが起こったことをいいます。

  • すぬけ君が叫んだ。
  • 縦に置かれた砂時計の砂がちょうど落ち切った。

出来事 が起こったとき、次の操作を (何度でも) 無視できる時間で行えます。

  • 砂時計を 1 つ選び、それを別の状態にする。

例えば、以下のようにして -1 + 2 \sqrt{2} 秒を測れます。

  • 時刻 0 に、すぬけ君が叫ぶ。A, B をともにひっくり返す。
  • 時刻 1 に、A の砂が落ち切る、という出来事が起こる。A を再びひっくり返す (B はそのまま)。
  • 時刻 \sqrt{2} に、B の砂が落ち切る、という出来事が起こる。A を再びひっくり返し、B は横にしておく。
  • 時刻 -1 + 2 \sqrt{2} に、A の砂が落ち切る、という出来事が起こる。

x_i + y_i \sqrt{2} という形の数が Q 個与えられるので、それぞれについて上記の問題を解いてください。

制約

  • 1 \leq Q \leq 10^5
  • -10^9 \leq x_i, y_i \leq 10^9
  • x_i + y_i \sqrt{2} > 0
  • 入力中の全ての値は整数である。

入力

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

Q
x_1 y_1
:
x_Q y_Q

出力

Q 行出力せよ。 出力の i 行目は、x_i + y_i \sqrt{2} 秒を測ることが可能なら Yes、不可能なら No とすること。


入力例 1

3
-1 2
2020 1227
2 -1

出力例 1

Yes
Yes
No

Score : 2400 points

Problem Statement

You have two sandglasses: a sandglass that can measure 1 second, and a sandglass that can measure \sqrt{2} seconds. Is it possible to measure x + y \sqrt{2} seconds using them?

Let's formalize the statement. We have two sandglasses named A and B. Each sandglass has two bulbs, and the bulbs may contain sand. We can place each sandglass in one of the three states: two vertical states (one of the bulbs is placed on top of the other, and in case the top bulb contains sand, the sand in the top bulb keeps falling into the bottom bulb at the speed of one gram per second.) and one horizontal state (the sand does not move.)

The sandglass A contains 1 gram of sand and the sandglass B contains \sqrt{2} grams of sand. Thus, when sandglass A is vertically placed and all sand is in the top bulb, it takes 1 second until all sand falls into the bottom bulb. Similarly, this time is \sqrt{2} seconds for sandglass B.

Initially, both A and B are vertically placed, and all sand is in the bottom bulb. You are not allowed to touch anything before Snuke shouts. When an event (described below) happens exactly t seconds after Snuke shouts, we say that we can measure t seconds.

We say that an event happens when one of the following happens:

  • Snuke shouts.
  • The sand in a sandglass in a vertical state has just stopped falling down.

When an event happens, we can perform (an arbitrary number of) the following operation in negligible time:

  • Choose a sandglasses, and change its state.

For example, we can measure -1 + 2 \sqrt{2} seconds as follows:

  • At time 0, Snuke shouts. Turn both A and B upside down.
  • At time 1, an event happens: the sand in A stops falling down. Turn A upside down again (and leave B as it is).
  • At time \sqrt{2}, an event happens: the sand in B stops falling down. Turn A upside down again, and leave B in the horizontal state.
  • At time -1 + 2 \sqrt{2}, an event happens: the sand in A stops falling down.

You are given Q numbers of the form x_i + y_i \sqrt{2}. Solve the problem above for each given number.

Constraints

  • 1 \leq Q \leq 10^5
  • -10^9 \leq x_i, y_i \leq 10^9
  • x_i + y_i \sqrt{2} > 0
  • All values in the input are integers.

Input

Input is given from Standard Input in the following format:

Q
x_1 y_1
:
x_Q y_Q

Output

Print Q lines. On the i-th line, print Yes if it is possible to measure x_i + y_i \sqrt{2} seconds; otherwise print No.


Sample Input 1

3
-1 2
2020 1227
2 -1

Sample Output 1

Yes
Yes
No