E - Gap Existence

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

配点 : 300

問題文

長さ N の数列 A=(A_1,\ldots,A_N) が与えられます。

1\leq i,j \leq N である組 (i,j) であって、A_i-A_j=X となるものが存在するかどうか判定してください。

制約

  • 2 \leq N \leq 2\times 10^5
  • -10^9 \leq A_i \leq 10^9
  • -10^9 \leq X \leq 10^9
  • 入力は全て整数である

入力

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

N X
A_1 \ldots A_N

出力

1\leq i,j \leq N である組 (i,j) であって、A_i-A_j=X となるものが存在するとき Yes、存在しないとき No と出力せよ。


入力例 1

6 5
3 1 4 1 5 9

出力例 1

Yes

A_6-A_3=9-4=5 です。


入力例 2

6 -4
-2 -7 -1 -8 -2 -8

出力例 2

No

A_i-A_j=-4 となる組 (i,j) は存在しません。


入力例 3

2 0
141421356 17320508

出力例 3

Yes

A_1-A_1=0 です。

Score : 300 points

Problem Statement

You are given a sequence of N numbers: A=(A_1,\ldots,A_N).

Determine whether there is a pair (i,j) with 1\leq i,j \leq N such that A_i-A_j=X.

Constraints

  • 2 \leq N \leq 2\times 10^5
  • -10^9 \leq A_i \leq 10^9
  • -10^9 \leq X \leq 10^9
  • All values in the input are integers.

Input

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

N X
A_1 \ldots A_N

Output

Print Yes if there is a pair (i,j) with 1\leq i,j \leq N such that A_i-A_j=X, and No otherwise.


Sample Input 1

6 5
3 1 4 1 5 9

Sample Output 1

Yes

We have A_6-A_3=9-4=5.


Sample Input 2

6 -4
-2 -7 -1 -8 -2 -8

Sample Output 2

No

There is no pair (i,j) such that A_i-A_j=-4.


Sample Input 3

2 0
141421356 17320508

Sample Output 3

Yes

We have A_1-A_1=0.

F - kasaka

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

配点 : 300

問題文

英小文字からなる文字列 S が与えられます。 S の先頭に a をいくつか( 0 個でも良い)つけ加えて回文にすることができるか判定してください。

ただし、長さ N の文字列 A=A_1A_2\ldots A_N が回文であるとは、すべての 1\leq i\leq N について A_i=A_{N+1-i} が成り立っていることをいいます。

制約

  • 1 \leq \lvert S \rvert \leq 10^6
  • S は英小文字のみからなる。

入力

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

S

出力

S の先頭に a をいくつかつけ加えて回文にすることができるならば Yes を、そうでないならば No を出力せよ。


入力例 1

kasaka

出力例 1

Yes

kasaka の先頭に a1 つ付け加えることによって、akasaka となり回文となるため Yes を出力します。


入力例 2

atcoder

出力例 2

No

atcoder の先頭に a をいくつ付け加えても回文となる事はありません。


入力例 3

php

出力例 3

Yes

php はそれ自体回文です。S の先頭に付け加える a0 個でも許されるため、Yes を出力します。

Score : 300 points

Problem Statement

Given is a string S consisting of lowercase English letters. Determine whether adding some number of a's (possibly zero) at the beginning of S can make it a palindrome.

Here, a string of length N, A=A_1A_2\ldots A_N, is said to be a palindrome when A_i=A_{N+1-i} for every 1\leq i\leq N.

Constraints

  • 1 \leq \lvert S \rvert \leq 10^6
  • S consists of lowercase English letters.

Input

Input is given from Standard Input in the following format:

S

Output

If adding some number of a's (possibly zero) at the beginning of S can make it a palindrome, print Yes; otherwise, print No.


Sample Input 1

kasaka

Sample Output 1

Yes

By adding one a at the beginning of kasaka, we have akasaka, which is a palindrome, so Yes should be printed.


Sample Input 2

atcoder

Sample Output 2

No

Adding any number of a's at the beginning of atcoder does not make it a palindrome.


Sample Input 3

php

Sample Output 3

Yes

php itself is a palindrome. Adding zero a's at the beginning of S is allowed, so Yes should be printed.

G - Destroyer Takahashi

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

配点 : 400

問題文

N10^9 列の格子状の区画に区切られた街に N 枚の壁があり、1 から N までの番号が割り振られています。
i は上から i 行目、左から L_i 列目から R_i 列目の範囲にあります。(入出力例 1 の図も参考にしてください。)

高橋君は N 枚の壁をすべて破壊することにしました。
超人的な腕力を持つ高橋君は、1 回のパンチで連続する D 列にまとめてダメージを与えることができます。

  • より厳密に言い換えると、1 以上 10^9 - D + 1 以下の 整数 x を選んで、x 列目から x + D - 1 列目に (一部でも) 存在するすべての破壊されていない壁にパンチによるダメージを与えることができます。

壁は一部分でもダメージを受けると、パンチの衝撃波により全体が木っ端みじんに破壊されてしまいます。
(入出力例 1 の説明も参考にしてください。)

高橋君がすべての壁を破壊するには、少なくとも何回のパンチを放つ必要がありますか?

制約

  • 1 \leq N \leq 2 \times 10^5
  • 1 \leq D \leq 10^9
  • 1 \leq L_i \leq R_i \leq 10^9
  • 入力はすべて整数である。

入力

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

N D
L_1 R_1
L_2 R_2
\vdots
L_N R_N

出力

すべての壁を破壊するのに必要なパンチの最少回数を出力せよ。


入力例 1

3 3
1 2
4 7
5 9

出力例 1

2

入力例 1 に対応する壁の配置を図示したものが下図です。

image

たとえば次のようにパンチを放つことで、 2 回のパンチですべての壁を破壊することができます。(以下の説明では、a 列目から b 列目までの範囲を \lbrack a, b \rbrack と表記します。)

  • まず、 \lbrack 2, 4 \rbrack にパンチを放つ。 \lbrack 2, 4 \rbrack に存在する壁である壁 1 と壁 2 はダメージを受け、破壊される。
  • 次に \lbrack 5, 7\rbrack にパンチを放つ。\lbrack 5, 7\rbrack に存在する壁 3 はダメージを受け、破壊される。

また、次の方法でもすべての壁を 2 回のパンチで破壊することができます。

  • まず、\lbrack 7, 9 \rbrack にパンチを放ち、壁 2 と壁 3 を破壊する。
  • 次に、\lbrack 1, 3 \rbrack にパンチを放ち、壁 1 を破壊する。

入力例 2

3 3
1 2
4 7
4 9

出力例 2

1

入出力例 1 と比べると、壁 3 の範囲が \lbrack 5, 9 \rbrack から \lbrack 4, 9 \rbrack に変わりました。
この場合は \lbrack 2, 4 \rbrack にパンチを放つことで 1 回ですべての壁を破壊できます。


入力例 3

5 2
1 100
1 1000000000
101 1000
9982 44353
1000000000 1000000000

出力例 3

3

Score : 400 points

Problem Statement

In a town divided into a grid with N rows and 10^9 columns, there are N walls, numbered 1 to N.
Wall i ranges from the L_i-th column to the R_i-th column from the left in the i-th row from the top. (See also the figure at Sample Input and Output 1.)

Takahashi has decided to destroy all N walls.
With his superhuman strength, his one punch can damage consecutive D columns at once.

  • More formally, he can choose an integer x between 1 and 10^9 - D + 1 (inclusive) to damage all walls that exist (or partly exist) in the x-th through (x + D - 1)-th columns and are not yet destroyed.

When a part of a wall is damaged, that whole wall will be destroyed by the impact of the punch.
(See also the figure at Sample Input and Output 1.)

At least how many times does Takahashi need to punch to destroy all walls?

Constraints

  • 1 \leq N \leq 2 \times 10^5
  • 1 \leq D \leq 10^9
  • 1 \leq L_i \leq R_i \leq 10^9
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N D
L_1 R_1
L_2 R_2
\vdots
L_N R_N

Output

Print the minimum number of punches needed to destroy all walls.


Sample Input 1

3 3
1 2
4 7
5 9

Sample Output 1

2

The figure below describes the arrangements of walls in Sample Input 1.

image

He can destroy all walls with two punches, such as the following. (Below, \lbrack a, b \rbrack denotes the range from the a-th through b-th columns.)

  • First, punch \lbrack 2, 4 \rbrack. The walls existing in \lbrack 2, 4 \rbrack ― Walls 1 and 2 ― are damaged and destroyed.
  • Second, punch \lbrack 5, 7 \rbrack. The wall existing in \lbrack 5, 7 \rbrack ― Wall 3 ― is damaged and destroyed.

It is also possible to destroy all walls with two punches in this way:

  • First, punch \lbrack 7, 9 \rbrack to destroy Walls 2 and 3.
  • Second, punch \lbrack 1, 3 \rbrack to destroy Wall 1.

Sample Input 2

3 3
1 2
4 7
4 9

Sample Output 2

1

The difference from Sample Input/Output 1 is that Wall 3 now covers \lbrack 4, 9 \rbrack, not \lbrack 5, 9 \rbrack.
In this case, he can punch \lbrack 2, 4 \rbrack to destroy all walls with one punch.


Sample Input 3

5 2
1 100
1 1000000000
101 1000
9982 44353
1000000000 1000000000

Sample Output 3

3
H - K-colinear Line

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

配点 : 500

問題文

座標平面上の N 個の点が与えられます。 1\leq i\leq N について、i 番目の点の座標は (X_i, Y_i) です。

座標平面上の直線であって、N 個の点のうち K 個以上の点を通るものの個数を求めてください。
ただし、そのようなものが無数に存在する場合は Infinity を出力してください。

制約

  • 1 \leq K \leq N \leq 300
  • \lvert X_i \rvert, \lvert Y_i \rvert \leq 10^9
  • i\neq j ならば X_i\neq X_j または Y_i\neq Y_j
  • 入力はすべて整数

入力

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

N K
X_1 Y_1
X_2 Y_2
\vdots
X_N Y_N

出力

与えられた N 個の点のうち K 個以上の点を通る直線の数を出力せよ。ただし、そのようなものが無数に存在する場合は Infinity を出力せよ。


入力例 1

5 2
0 0
1 0
0 1
-1 0
0 -1

出力例 1

6

x=0, y=0, y=x\pm 1, y=-x\pm 16 本の直線が条件をみたします。
例えば、x=0 は、1, 3, 5 番目の 3 個の点を通ります。

よって、6 を出力します。


入力例 2

1 1
0 0

出力例 2

Infinity

原点を通る直線は無数に存在します。 よって、Infinity を出力します。

Score : 500 points

Problem Statement

You are given N points in the coordinate plane. For each 1\leq i\leq N, the i-th point is at the coordinates (X_i, Y_i).

Find the number of lines in the plane that pass K or more of the N points.
If there are infinitely many such lines, print Infinity.

Constraints

  • 1 \leq K \leq N \leq 300
  • \lvert X_i \rvert, \lvert Y_i \rvert \leq 10^9
  • X_i\neq X_j or Y_i\neq Y_j, if i\neq j.
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N K
X_1 Y_1
X_2 Y_2
\vdots
X_N Y_N

Output

Print the number of lines in the plane that pass K or more of the N points, or Infinity if there are infinitely many such lines.


Sample Input 1

5 2
0 0
1 0
0 1
-1 0
0 -1

Sample Output 1

6

The six lines x=0, y=0, y=x\pm 1, and y=-x\pm 1 satisfy the requirement.
For example, x=0 passes the first, third, and fifth points.

Thus, 6 should be printed.


Sample Input 2

1 1
0 0

Sample Output 2

Infinity

Infinitely many lines pass the origin.

Thus, Infinity should be printed.

I - Regular Triangle Inside a Rectangle

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

配点 : 500

問題文

縦の長さが A、横の長さが B の長方形の内部に描ける正三角形の一辺の長さの最大値を求めてください。

制約

  • 1 \leq A,B \leq 1000
  • A,B は整数

入力

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

A B

出力

答えを出力せよ。
なお、真の値との絶対誤差または相対誤差が 10^{-9} 以下であれば正解として扱われる。


入力例 1

1 1

出力例 1

1.03527618041008295791

下図のように描くのが最適で、一辺の長さが \sqrt{6} - \sqrt{2} になります。

image

なお、この出力例の値は \sqrt{6}- \sqrt{2} と厳密には一致しませんが、誤差が 10^{-9} 以下なので正解として扱われます。

Score : 500 points

Problem Statement

Find the maximum side length of a regular triangle that can be drawn within a rectangle whose side lengths are A and B.

Constraints

  • 1 \leq A,B \leq 1000
  • A and B are integers.

Input

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

A B

Output

Print the answer.
Your output is considered correct if the absolute or relative error from the true answer is at most 10^{-9}.


Sample Input 1

1 1

Sample Output 1

1.03527618041008295791

The following figure shows an optimal drawing, with the side length of \sqrt{6} - \sqrt{2}.

image

Note that the sample output does not strictly match \sqrt{6}- \sqrt{2}, but the error is within 10^{-9}, so it is considered correct.