A - Vanishing Pitch

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 100

問題文

高橋君と青木君が野球をしています。高橋君はピッチャー、青木君はバッターです。
高橋君は消える魔球を投げることができます。高橋君が投げる消える魔球は、速さ V \, \mathrm{m / s} で等速直線運動をし、投げた瞬間から T 秒後から S 秒後まで (両端を含む) 消えています。消えている間もボールは移動を続けます。
ボールが高橋君のもとからちょうど D \, \mathrm{m} 離れたときにボールが消えていないならば、青木君はボールを打つことができます。消えているなら打つことはできません。
青木君は高橋君のボールを打つことができますか ?

制約

  • 1 \le V \le 1000
  • 1 \le T \lt S \le 1000
  • 1 \le D \le 1000
  • 入力は全て整数

入力

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

V T S D

出力

青木君がボールを打つことができるなら Yes を、できないなら No を出力せよ。


入力例 1

10 3 5 20

出力例 1

Yes

ボールが高橋君からちょうど 20 \, \mathrm{m} 離れるのは、高橋君がボールを投げてから 2 秒後です。
一方でボールが消えるのは、高橋君がボールを投げてから 3 秒後から 5 秒後まで (両端含む) なので、青木君はボールを打つことができます。


入力例 2

10 3 5 30

出力例 2

No

投げてからちょうど T 秒後やちょうど S 秒後もボールは消えていることに注意してください。
この場合、ボールが D \, \mathrm{m} 離れるのは高橋君が投げてからちょうど T 秒後なので、ボールは消えており、青木君はボールを打つことができません。

Score : 100 points

Problem Statement

Takahashi and Aoki are playing baseball. Takahashi is the pitcher, and Aoki is the batter.
Takahashi can throw an invisible pitch. When he throws it, the ball moves linearly at a constant speed V \, \mathrm{m / s}, and it becomes invisible between the moment T seconds after throwing and the moment S seconds after throwing (inclusive). The ball keeps moving when it is invisible.
If the ball is not invisible at the moment the ball is exactly D \, \mathrm{m} away from Takahashi, Aoki can hit the ball. Otherwise, he cannot hit it. Can Aoki hit the ball?

Constraints

  • 1 \le V \le 1000
  • 1 \le T \lt S \le 1000
  • 1 \le D \le 1000
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

V T S D

Output

If Aoki can hit the ball, print Yes; otherwise, print No.


Sample Input 1

10 3 5 20

Sample Output 1

Yes

The ball is exactly 20 \, \mathrm{m} away from Takahashi at 2 seconds after throwing.
On the other hand, the ball becomes invisible between 3 and 5 seconds (inclusive) after throwing, so Aoki can hit the ball.


Sample Input 2

10 3 5 30

Sample Output 2

No

Note that the ball is also invisible at T seconds and S seconds after throwing.
Here, the ball is exactly D \, \mathrm{m} away from Takahashi at T seconds after throwing, so the ball is invisible and cannot be hit by Aoki.

B - Remove It

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 200

問題文

長さ N の整数列 A と整数 X が与えられます。
A から X と等しい要素を全て取り除き、残った要素をそのままの順序で並べた数列 A' を出力してください。

制約

  • 1 \le N \le 10^5
  • 1 \le X \le 10^9
  • 1 \le A_i \le 10^9
  • 入力は全て整数

入力

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

N X
A_1 A_2 A_3 \dots A_N

出力

A' の要素を空白区切りで順に出力せよ。


入力例 1

5 5
3 5 6 5 4

出力例 1

3 6 4

[3, 5, 6, 5, 4] から 5 を取り除くと、[3, 6, 4] になります。


入力例 2

3 3
3 3 3

出力例 2


A' が要素数 0 の数列となる場合があります。この場合、空行を出力するだけで構いません。

Score : 200 points

Problem Statement

Given are an integer sequence A of length N, and an integer X.
Remove all elements that are equal to X from A, and arrange the remaining elements without changing the order to obtain the sequence A'. Print A'.

Constraints

  • 1 \le N \le 10^5
  • 1 \le X \le 10^9
  • 1 \le A_i \le 10^9
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N X
A_1 A_2 A_3 \dots A_N

Output

Print the elements of A' in order, with space in between.


Sample Input 1

5 5
3 5 6 5 4

Sample Output 1

3 6 4

Removing 5s from [3, 5, 6, 5, 4] results in [3, 6, 4].


Sample Input 2

3 3
3 3 3

Sample Output 2


A' can be a sequence with zero elements, in which case we should just print an empty line.

C - Digital Graffiti

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 300

問題文

HW 列のマス目があります。このマス目の、上から i 番目、左から j 番目のマスを、マス (i, j) と呼ぶことにします。
各マスは黒または白に塗られています。S_{i, j}# ならばマス (i, j) は黒に塗られており、. ならば白に塗られています。
マス目の一番外側のマス、すなわち (1, j), (H, j), (i, 1), (i, W) のいずれかの形で表されるマスは白に塗られていることが保証されます。

黒に塗られた部分を多角形として見たとき、これが (最小で) 何角形になるかを求めてください。

ここで、黒に塗られた部分は一つの自己交叉のない多角形となることが保証されます。すなわち、以下のことが保証されます。

  • 黒に塗られたマスが少なくとも一つ存在する
  • 黒に塗られた任意の 2 マスは、辺を共有するマスへの移動を繰り返し、黒に塗られたマスのみを通って互いに到達可能である
  • 白に塗られた任意の 2 マスは、辺を共有するマスへの移動を繰り返し、白に塗られたマスのみを通って互いに到達可能である(マス目の一番外側のマスは全て白に塗られていることに注意してください)

制約

  • 3 \le H \le 10
  • 3 \le W \le 10
  • S_{i, j}# または .
  • S_{1, j}, S_{H, j}.
  • S_{i, 1}, S_{i, W}.
  • 黒に塗られた部分は一つの自己交叉のない多角形となる

入力

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

H W
S_{1, 1} S_{1, 2} S_{1, 3} \dots S_{1, W}
S_{2, 1} S_{2, 2} S_{2, 3} \dots S_{2, W}
S_{3, 1} S_{3, 2} S_{3, 3} \dots S_{3, W}
\hspace{40pt} \vdots
S_{H, 1} S_{H, 2} S_{H, 3} \dots S_{H, W}

出力

黒に塗られた部分を n 角形として見ることができるような最小の n を出力せよ。


入力例 1

5 5
.....
.###.
.###.
.###.
.....

出力例 1

4

マス目の左上、左下、右上、右下の隅をそれぞれ (0, 0), (H, 0), (0, W), (H, W) とする座標系で表すと、与えられる図形は (1, 1), (4, 1), (4, 4), (1, 4) を頂点とする 4 角形です。

Score : 300 points

Problem Statement

We have a grid with H rows and W columns. Let (i, j) be the square at the i-th row from the top and j-th column from the left.
Each square is painted black or white. If S_{i, j} is #, (i, j) is painted black; if S_{i, j} is ., (i, j) is painted white.
It is guaranteed that the outermost squares are white. That is, the squares that can be represented as (1, j), (H, j), (i, 1), or (i, W) are white.

Consider the part of the grid that is painted black as a polygon. How many sides does it have (at least)?

Here, it is guaranteed that the part painted black forms a polygon without self-intersection, that is, the following holds:

  • at least one square is painted black;
  • we can travel between any two squares painted black by repeatedly moving up, down, left, or right while going through only black squares;
  • we can travel between any two squares painted white by repeatedly moving up, down, left, or right while going through only white squares. (Note that the outermost squares in the grid are all painted white.)

Constraints

  • 3 \le H \le 10
  • 3 \le W \le 10
  • S_{i, j} is # or ..
  • S_{1, j} and S_{H, j} are ..
  • S_{i, 1} and S_{i, W} are ..
  • The part painted black forms a polygon without self-intersection.

Input

Input is given from Standard Input in the following format:

H W
S_{1, 1} S_{1, 2} S_{1, 3} \dots S_{1, W}
S_{2, 1} S_{2, 2} S_{2, 3} \dots S_{2, W}
S_{3, 1} S_{3, 2} S_{3, 3} \dots S_{3, W}
\hspace{40pt} \vdots
S_{H, 1} S_{H, 2} S_{H, 3} \dots S_{H, W}

Output

Print the minimum number n such that the part painted black can be seen as an n-gon.


Sample Input 1

5 5
.....
.###.
.###.
.###.
.....

Sample Output 1

4

If we use a coordinate system where the top-left, bottom-left, top-right, and bottom-right corners of the grid are (0, 0), (H, 0), (0, W), and (H, W), the given figure is a quadrilateral whose vertices are (1, 1), (4, 1), (4, 4), and (1, 4).

D - Circle Lattice Points

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 400

問題文

2 次元平面上に中心 (X, Y) 、半径 R の円があります。
この円の内部または周上にある格子点 (x, y 座標がともに整数である点) の個数を求めてください。

制約

  • |X| \le 10^5
  • |Y| \le 10^5
  • 0 \lt R \le 10^5
  • X, Y, R は高々小数第 4 位まで与えられる

入力

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

X Y R

出力

答えを出力せよ。


入力例 1

0.2 0.8 1.1

出力例 1

3

以下のような円になります。赤く印の付いた点が、この円の内部または周上にある格子点です。
グラフ


入力例 2

100 100 1

出力例 2

5

X, Y, R には小数点が含まれないかもしれません。
円周上の格子点も数える対象に含むことに注意してください。


入力例 3

42782.4720 31949.0192 99999.99

出力例 3

31415920098

Score : 400 points

Problem Statement

We have a circle of radius R centered at (X, Y).
Find the number of grid points (points whose x- and y-coordinates are both integers) within or on the circle.

Constraints

  • |X| \le 10^5
  • |Y| \le 10^5
  • 0 \lt R \le 10^5
  • Each of X, Y, and R has at most four digits after the decimal point.

Input

Input is given from Standard Input in the following format:

X Y R

Output

Print the answer.


Sample Input 1

0.2 0.8 1.1

Sample Output 1

3

The circle is shown below. The grid points within or on the circle are marked red.

Figure


Sample Input 2

100 100 1

Sample Output 2

5

X, Y, and R may not have decimal points. Note that we also count the grid points on the circle.


Sample Input 3

42782.4720 31949.0192 99999.99

Sample Output 3

31415920098
E - Come Back Quickly

Time Limit: 3 sec / Memory Limit: 1024 MB

配点 : 500

問題文

AtCoder 国には、町 1 から町 N までの N 個の町と、道路 1 から道路 M までの M 本の道路があります。
道路 i は町 A_i から町 B_i への一方通行で、通るのに C_i 分かかります。A_i = B_i かもしれませんし、同じ町の組を結ぶ道路が複数あるかもしれません。
高橋君はこの国で散歩をしようと考えました。ある町から出発し、1 本以上の道路を通り、出発した町に帰ってくるような経路を正しい散歩経路と呼ぶことにします。
各町について、その町から出発する正しい散歩経路が存在するかを判定してください。また、存在するなら、そのような経路を通るのにかかる時間の最小値を求めてください。

制約

  • 1 \le N \le 2000
  • 1 \le M \le 2000
  • 1 \le A_i \le N
  • 1 \le B_i \le N
  • 1 \le C_i \le 10^5
  • 入力は全て整数

入力

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

N M
A_1 B_1 C_1
A_2 B_2 C_2
A_3 B_3 C_3
\hspace{25pt} \vdots
A_M B_M C_M

出力

N 行に渡って出力せよ。 i(1 \le i \le N) 行目には以下を出力せよ。

  • i から出発する正しい散歩経路が存在するなら、そのような経路を通るのにかかる時間の最小値
  • 存在しないなら -1

入力例 1

4 4
1 2 5
2 3 10
3 1 15
4 3 20

出力例 1

30
30
30
-1

道路 1, 2, 3 によって、町 1, 2, 3 は一周に 30 分かかる一つの輪のように繋がっています。
4 から町 1, 2, 3 に行くことはできますが、町 4 に帰ってくることはできません。


入力例 2

4 6
1 2 5
1 3 10
2 4 5
3 4 10
4 1 10
1 1 10

出力例 2

10
20
30
20

A_i = B_i であるような道路が存在するかもしれません。
この場合、町 1 からは、道路 6 だけを使って 10 分で町 1 に帰ってくることができます。


入力例 3

4 7
1 2 10
2 3 30
1 4 15
3 4 25
3 4 20
4 3 20
4 3 30

出力例 3

-1
-1
40
40

同じ町の組を結ぶ道路が複数あるかもしれないことに注意してください。

Score : 500 points

Problem Statement

In the Republic of AtCoder, there are N towns numbered 1 through N and M roads numbered 1 through M.
Road i is a one-way road from Town A_i to Town B_i, and it takes C_i minutes to go through. It is possible that A_i = B_i, and there may be multiple roads connecting the same pair of towns.
Takahashi is thinking about taking a walk in the country. We will call a walk valid when it goes through one or more roads and returns to the town it starts at.
For each town, determine whether there is a valid walk that starts at that town. Additionally, if the answer is yes, find the minimum time such a walk requires.

Constraints

  • 1 \le N \le 2000
  • 1 \le M \le 2000
  • 1 \le A_i \le N
  • 1 \le B_i \le N
  • 1 \le C_i \le 10^5
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N M
A_1 B_1 C_1
A_2 B_2 C_2
A_3 B_3 C_3
\hspace{25pt} \vdots
A_M B_M C_M

Output

Print N lines. The i-th line (1 \le i \le N) should contain the following:

  • if there is a valid walk that starts at Town i, the minimum time required by such a walk;
  • otherwise, -1.

Sample Input 1

4 4
1 2 5
2 3 10
3 1 15
4 3 20

Sample Output 1

30
30
30
-1

By Roads 1, 2, 3, Towns 1, 2, 3 forms a ring that takes 30 minutes to go around.
From Town 4, we can go to Towns 1, 2, 3, but then we cannot return to Town 4.


Sample Input 2

4 6
1 2 5
1 3 10
2 4 5
3 4 10
4 1 10
1 1 10

Sample Output 2

10
20
30
20

There may be a road such that A_i = B_i.
Here, we can use just Road 6 to depart from Town 1 and return to that town.


Sample Input 3

4 7
1 2 10
2 3 30
1 4 15
3 4 25
3 4 20
4 3 20
4 3 30

Sample Output 3

-1
-1
40
40

Note that there may be multiple roads connecting the same pair of towns.

F - GCD or MIN

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 600

問題文

黒板に N 個の整数 A_1, A_2, A_3, \dots, A_N が書かれています。
あなたは次の操作を N - 1 回行います。

  • 黒板に書かれている数を 2 つ選んで消す。消した数を xy として、\gcd(x, y)\min(x, y) のどちらか一方を黒板に書く

N - 1 回の操作を終えた後、黒板にはただ一つの整数が残りますが、この整数として考えられるものはいくつありますか ?

制約

  • 2 \le N \le 2000
  • 1 \le A_i \le 10^9
  • 入力は全て整数

入力

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

N
A_1 A_2 A_3 \dots A_N

出力

黒板に残る整数として考えられるものの個数を出力せよ。


入力例 1

3
6 9 12

出力例 1

2

36 が、最後に黒板に残る整数として考えられるものです。
例えば以下のような操作をすることで 3 が残ります。

  • 912 を選んで黒板から消し、\gcd(9, 12) = 3 を黒板に書く
  • 63 を選んで黒板から消し、\min(6, 3) = 3 を黒板に書く

また、以下のような操作をすることで 6 が残ります。

  • 612 を選んで黒板から消し、\gcd(6, 12) = 6 を黒板に書く
  • 69 を選んで黒板から消し、\min(6, 9) = 6 を黒板に書く

入力例 2

4
8 2 12 6

出力例 2

1

2 が、黒板に残る数として考えられる唯一の数です。


入力例 3

7
30 28 33 49 27 37 48

出力例 3

7

1, 2, 3, 4, 6, 7, 27 が最後に黒板に残る整数として考えられるものです。

Score : 600 points

Problem Statement

There are N integers A_1, A_2, A_3, \dots, A_N written on a blackboard.
You will do the following operation N - 1 times:

  • Choose two numbers written on the blackboard and erase them. Let x and y be the erased numbers. Then, write \gcd(x, y) or \min(x, y) on the blackboard.

After N - 1 operations, just one integer will remain on the blackboard. How many possible values of this number are there?

Constraints

  • 2 \le N \le 2000
  • 1 \le A_i \le 10^9
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 A_3 \dots A_N

Output

Print the number of possible values of the last remaining number on the blackboard.


Sample Input 1

3
6 9 12

Sample Output 1

2

The possible values of the last remaining number are 3 and 6.
We will have 3 in the end if, for example, we do as follows:

  • choose 9, 12 and erase them from the blackboard, then write \gcd(9, 12) = 3;
  • choose 6, 3 and erase them from the blackboard, then write \min(6, 3) = 3.

Also, we will have 6 in the end if, for example, we do as follows:

  • choose 6, 12 and erase them from the blackboard, then write \gcd(6, 12) = 6;
  • choose 6, 9 and erase them from the blackboard, then write \min(6, 9) = 6.

Sample Input 2

4
8 2 12 6

Sample Output 2

1

2 is the only number that can remain on the blackboard.


Sample Input 3

7
30 28 33 49 27 37 48

Sample Output 3

7

1, 2, 3, 4, 6, 7, and 27 can remain on the blackboard.