A - 9x9

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 100

問題文

高橋君は九九を覚えたので、1 以上 9 以下の 2 つの整数の積を計算することができます。それ以外の計算はできません。

2 つの整数 A, B が与えられます。

高橋君が A \times B を計算できるならその結果を、できないなら代わりに -1 を出力してください。

制約

  • 1 \leq A \leq 20
  • 1 \leq B \leq 20
  • 入力中のすべての値は整数である。

入力

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

A B

出力

高橋君が A \times B を計算できるならその結果を、できないなら -1 を出力せよ。


入力例 1

2 5

出力例 1

10

2 \times 510 です。


入力例 2

5 10

出力例 2

-1

5\times 1050 ですが、高橋君には計算できないので、かわりに -1 を出力します。


入力例 3

9 9

出力例 3

81

Score : 100 points

Problem Statement

Having learned the multiplication table, Takahashi can multiply two integers between 1 and 9 (inclusive) together. He cannot do any other calculation.

Given are two integers A and B.

If Takahashi can calculate A \times B, print the result; if he cannot, print -1 instead.

Constraints

  • 1 \leq A \leq 20
  • 1 \leq B \leq 20
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

A B

Output

If Takahashi can calculate A \times B, print the result; if he cannot, print -1.


Sample Input 1

2 5

Sample Output 1

10

2 \times 5 = 10.


Sample Input 2

5 10

Sample Output 2

-1

5\times 10 = 50, but Takahashi cannot do this calculation, so print -1 instead.


Sample Input 3

9 9

Sample Output 3

81
B - 81

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 200

問題文

高橋君は九九を覚えたので、1 以上 9 以下の 2 つの整数の積を計算することができます。

整数 N が与えられるので、N1 以上 9 以下の 2 つの整数の積として表すことができるか判定し、できるなら Yes を、できないなら No を出力して下さい。

制約

  • 1 \leq N \leq 100
  • N は整数である。

入力

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

N

出力

N1 以上 9 以下の 2 つの整数の積として表すことができるなら Yes を、できないなら No を出力せよ。


入力例 1

10

出力例 1

Yes

例えば 2 \times 5 と表すことができます。


入力例 2

50

出力例 2

No

501 以上 9 以下の 2 つの整数の積として表すことはできません。


入力例 3

81

出力例 3

Yes

Score : 200 points

Problem Statement

Having learned the multiplication table, Takahashi can multiply two integers between 1 and 9 (inclusive) together.

Given an integer N, determine whether N can be represented as the product of two integers between 1 and 9. If it can, print Yes; if it cannot, print No.

Constraints

  • 1 \leq N \leq 100
  • N is an integer.

Input

Input is given from Standard Input in the following format:

N

Output

If N can be represented as the product of two integers between 1 and 9 (inclusive), print Yes; if it cannot, print No.


Sample Input 1

10

Sample Output 1

Yes

10 can be represented as, for example, 2 \times 5.


Sample Input 2

50

Sample Output 2

No

50 cannot be represented as the product of two integers between 1 and 9.


Sample Input 3

81

Sample Output 3

Yes
C - Walk on Multiplication Table

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 300

問題文

高橋君は無限に広い掛け算表の上にいます。

掛け算表のマス (i,j) には整数 i \times j が書かれており、高橋君は最初 (1,1) にいます。

高橋君は 1 回の移動で (i,j) から (i+1,j)(i,j+1) のどちらかにのみ移ることができます。

整数 N が与えられるので、N が書かれているマスに到達するまでに必要な移動回数の最小値を求めてください。

制約

  • 2 \leq N \leq 10^{12}
  • N は整数である。

入力

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

N

出力

整数 N が書かれているマスに到達するまでに必要な移動回数の最小値を出力せよ。


入力例 1

10

出力例 1

5

5 回の移動で (2,5) に到達することができます。5 回未満の移動では 10 が書かれたマスに到達することは出来ません。


入力例 2

50

出力例 2

13

13 回の移動で (5,10) に到達できます。


入力例 3

10000000019

出力例 3

10000000018

入出力とも非常に大きな値になる可能性があります。

Score : 300 points

Problem Statement

Takahashi is standing on a multiplication table with infinitely many rows and columns.

The square (i,j) contains the integer i \times j. Initially, Takahashi is standing at (1,1).

In one move, he can move from (i,j) to either (i+1,j) or (i,j+1).

Given an integer N, find the minimum number of moves needed to reach a square that contains N.

Constraints

  • 2 \leq N \leq 10^{12}
  • N is an integer.

Input

Input is given from Standard Input in the following format:

N

Output

Print the minimum number of moves needed to reach a square that contains the integer N.


Sample Input 1

10

Sample Output 1

5

(2,5) can be reached in five moves. We cannot reach a square that contains 10 in less than five moves.


Sample Input 2

50

Sample Output 2

13

(5, 10) can be reached in 13 moves.


Sample Input 3

10000000019

Sample Output 3

10000000018

Both input and output may be enormous.

D - Water Bottle

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 400

問題文

高橋君は、底面が 1a~\mathrm{cm} の正方形であり、高さが b~\mathrm{cm} であるような直方体型の水筒を持っています。(水筒の厚みは無視できます。)

この水筒の中に体積 x~\mathrm{cm}^3 の水を入れ、底面の正方形の 1 辺を軸として、この水筒を徐々に傾けます。

水を溢れさせずに水筒を傾けることができる最大の角度を求めてください。

制約

  • 入力は全て整数
  • 1 ≤ a \leq 100
  • 1 ≤ b \leq 100
  • 1 ≤ x ≤ a^2b

入力

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

a b x

出力

水を溢れさせずに水筒を傾けることができる最大の角度を度数法で出力せよ。 出力は、ジャッジの出力との絶対誤差または相対誤差が 10^{-6} 以下のとき正解と判定される。


入力例 1

2 2 4

出力例 1

45.0000000000

水筒は立方体であり、水は半分まで入っています。この水筒を 45° より大きく傾けると水が溢れます。


入力例 2

12 21 10

出力例 2

89.7834636934

水筒はほぼ空であり、水が溢れるときにはほぼ水平になっています。


入力例 3

3 1 8

出力例 3

4.2363947991

水筒はほぼ満杯であり、ほぼ垂直の状態で水が溢れます。

Score : 400 points

Problem Statement

Takahashi has a water bottle with the shape of a rectangular prism whose base is a square of side a~\mathrm{cm} and whose height is b~\mathrm{cm}. (The thickness of the bottle can be ignored.)

We will pour x~\mathrm{cm}^3 of water into the bottle, and gradually tilt the bottle around one of the sides of the base.

When will the water be spilled? More formally, find the maximum angle in which we can tilt the bottle without spilling any water.

Constraints

  • All values in input are integers.
  • 1 \leq a \leq 100
  • 1 \leq b \leq 100
  • 1 \leq x \leq a^2b

Input

Input is given from Standard Input in the following format:

a b x

Output

Print the maximum angle in which we can tilt the bottle without spilling any water, in degrees. Your output will be judged as correct when the absolute or relative error from the judge's output is at most 10^{-6}.


Sample Input 1

2 2 4

Sample Output 1

45.0000000000

This bottle has a cubic shape, and it is half-full. The water gets spilled when we tilt the bottle more than 45 degrees.


Sample Input 2

12 21 10

Sample Output 2

89.7834636934

This bottle is almost empty. When the water gets spilled, the bottle is nearly horizontal.


Sample Input 3

3 1 8

Sample Output 3

4.2363947991

This bottle is almost full. When the water gets spilled, the bottle is still nearly vertical.

E - Gluttony

Time Limit: 2 sec / Memory Limit: 1024 MB

配点: 500

問題文

高橋君は早食い大会に出ることにしました。この大会は N 人でのチーム戦であり、高橋君のチームは年齢順に 1 から N までの番号がついた N 人のメンバーからなります。メンバー i消化コストA_i です。

大会では 1 から N までの番号がついた N 個の食べ物が用意されており、食べ物 i食べにくさF_i です。大会のルールは以下の通りです。

  • 1 個の食べ物につき 1 人のチームメンバーを割り当てる。同じメンバーを複数の食べ物に割り当てることはできない。
  • あるメンバーについて、そのメンバーの消化コストが x、担当する食べ物の食べにくさが y のとき、その食べ物の完食には x \times y 秒かかる。
  • N 人のメンバーそれぞれが完食にかかる時間のうち最大値が、チーム全体の成績となる。

コンテストの前に、高橋君のチームは修行をすることにしました。各メンバーは、自分の消化コストが 0 より小さくならない限り、1 回修行するごとに自分の消化コストを 1 減らすことができます。ただし、修行には膨大な食費がかかるため、N 人合計で K 回までしか修行することができません。

各メンバーの修行回数と担当する食べ物を適切に選んだとき、チーム全体の成績は最小でいくらになるでしょうか。

制約

  • 入力はすべて整数
  • 1 \leq N \leq 2 \times 10^5
  • 0 \leq K \leq 10^{18}
  • 1 \leq A_i \leq 10^6\ (1 \leq i \leq N)
  • 1 \leq F_i \leq 10^6\ (1 \leq i \leq N)

入力

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

N K
A_1 A_2 ... A_N
F_1 F_2 ... F_N

出力

チーム全体の成績の最小値を出力してください。


入力例 1

3 5
4 2 1
2 3 1

出力例 1

2

下のようにすることで、チーム全体の成績は 2 になります。

  • メンバー 14 回修行させ、食べ物 2 を割り当てます。完食にかかる時間は (4-4) \times 3 = 0 秒です。
  • メンバー 21 回修行させ、食べ物 3 を割り当てます。完食にかかる時間は (2-1) \times 1 = 1 秒です。
  • メンバー 30 回修行させ、食べ物 1 を割り当てます。完食にかかる時間は (1-0) \times 2 = 2 秒です。

チーム全体の成績を 2 より小さくすることはできないので、答えは 2 です。


入力例 2

3 8
4 2 1
2 3 1

出力例 2

0

必ずしも K 回ちょうど修行する必要はありません。


入力例 3

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

出力例 3

12

Score: 500 points

Problem Statement

Takahashi will take part in an eating contest. Teams of N members will compete in this contest, and Takahashi's team consists of N players numbered 1 through N from youngest to oldest. The consumption coefficient of Member i is A_i.

In the contest, N foods numbered 1 through N will be presented, and the difficulty of Food i is F_i. The details of the contest are as follows:

  • A team should assign one member to each food, and should not assign the same member to multiple foods.
  • It will take x \times y seconds for a member to finish the food, where x is the consumption coefficient of the member and y is the difficulty of the dish.
  • The score of a team is the longest time it takes for an individual member to finish the food.

Before the contest, Takahashi's team decided to do some training. In one set of training, a member can reduce his/her consumption coefficient by 1, as long as it does not go below 0. However, for financial reasons, the N members can do at most K sets of training in total.

What is the minimum possible score of the team, achieved by choosing the amounts of members' training and allocating the dishes optimally?

Constraints

  • All values in input are integers.
  • 1 \leq N \leq 2 \times 10^5
  • 0 \leq K \leq 10^{18}
  • 1 \leq A_i \leq 10^6\ (1 \leq i \leq N)
  • 1 \leq F_i \leq 10^6\ (1 \leq i \leq N)

Input

Input is given from Standard Input in the following format:

N K
A_1 A_2 ... A_N
F_1 F_2 ... F_N

Output

Print the minimum possible score of the team.


Sample Input 1

3 5
4 2 1
2 3 1

Sample Output 1

2

They can achieve the score of 2, as follows:

  • Member 1 does 4 sets of training and eats Food 2 in (4-4) \times 3 = 0 seconds.
  • Member 2 does 1 set of training and eats Food 3 in (2-1) \times 1 = 1 second.
  • Member 3 does 0 sets of training and eats Food 1 in (1-0) \times 2 = 2 seconds.

They cannot achieve a score of less than 2, so the answer is 2.


Sample Input 2

3 8
4 2 1
2 3 1

Sample Output 2

0

They can choose not to do exactly K sets of training.


Sample Input 3

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

Sample Output 3

12
F - Fork in the Road

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 600

問題文

N 個の部屋と、M 本の一方向にのみ通れる通路から成る洞窟があります。部屋には 1 から N までの番号がついています。

高橋君はいま部屋 1 におり、部屋 N が出口へと繋がっています。i 番目の通路は部屋 s_i と部屋 t_i ( s_i < t_i ) を繋いでおり、部屋 s_i から部屋 t_i の方向にのみ通ることが出来ます。部屋 N 以外の各部屋について、その部屋から出る通路が少なくとも 1 つ存在することが分かっています。

高橋君はこの洞窟から脱出を試みます。部屋に到達するたびに (脱出開始時は部屋 1 に到達したとみなします)、高橋君はその部屋から出る通路のうち等確率でランダムに 1 つを選んで進みます。

高橋君の友達の青木君は、高橋君が部屋 1 から移動する前に 1 つだけ通路を塞ぐ (または何もしない) ことが出来ます。ただし、高橋君が部屋 N に到達できなくなる可能性が生じるような通路の塞ぎ方は出来ません。

高橋君が部屋 N に到達するまでに通る通路の数の期待値を E とします。青木君が E を最小化するような選択をしたときの E の値を求めてください。

制約

  • 2 ≤ N ≤ 600
  • N-1 ≤ M ≤ \frac{N(N-1)}{2}
  • s_i < t_i
  • i \neq j のとき、(s_i, t_i) \neq (s_j, t_j) (21:23 追記)
  • 任意の v = 1, 2, ..., N-1 に対し、ある i が存在して v = s_i

入力

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

N M
s_1 t_1
:
s_M t_M

出力

青木君が E を最小化するような選択をしたときの E の値を出力せよ。 出力は、ジャッジと出力との絶対誤差または相対誤差が 10^{-6} 以下のとき正解と判定される。


入力例 1

4 6
1 4
2 3
1 3
1 2
3 4
2 4

出力例 1

1.5000000000

青木君が部屋 1 から部屋 2 への通路を塞ぐと、高橋君は \frac{1}{2} の確率で 134 という経路を辿り、 \frac{1}{2} の確率で 14 という経路を辿ります。このとき E = 1.5 であり、これが E がとりうる最小の値です。


入力例 2

3 2
1 2
2 3

出力例 2

2.0000000000

どの通路を塞いでも部屋 N に到達出来なくなるため、青木君は通路を塞ぐことは出来ません。


入力例 3

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

出力例 3

3.0133333333

Score : 600 points

Problem Statement

There is a cave consisting of N rooms and M one-directional passages. The rooms are numbered 1 through N.

Takahashi is now in Room 1, and Room N has the exit. The i-th passage connects Room s_i and Room t_i (s_i < t_i) and can only be traversed in the direction from Room s_i to Room t_i. It is known that, for each room except Room N, there is at least one passage going from that room.

Takahashi will escape from the cave. Each time he reaches a room (assume that he has reached Room 1 at the beginning), he will choose a passage uniformly at random from the ones going from that room and take that passage.

Aoki, a friend of Takahashi's, can block one of the passages (or do nothing) before Takahashi leaves Room 1. However, it is not allowed to block a passage so that Takahashi is potentially unable to reach Room N.

Let E be the expected number of passages Takahashi takes before he reaches Room N. Find the value of E when Aoki makes a choice that minimizes E.

Constraints

  • 2 \leq N \leq 600
  • N-1 \leq M \leq \frac{N(N-1)}{2}
  • s_i < t_i
  • If i != j, (s_i, t_i) \neq (s_j, t_j). (Added 21:23 JST)
  • For every v = 1, 2, ..., N-1, there exists i such that v = s_i.

Input

Input is given from Standard Input in the following format:

N M
s_1 t_1
:
s_M t_M

Output

Print the value of E when Aoki makes a choice that minimizes E. Your output will be judged as correct when the absolute or relative error from the judge's output is at most 10^{-6}.


Sample Input 1

4 6
1 4
2 3
1 3
1 2
3 4
2 4

Sample Output 1

1.5000000000

If Aoki blocks the passage from Room 1 to Room 2, Takahashi will go along the path 134 with probability \frac{1}{2} and 14 with probability \frac{1}{2}. E = 1.5 here, and this is the minimum possible value of E.


Sample Input 2

3 2
1 2
2 3

Sample Output 2

2.0000000000

Blocking any one passage makes Takahashi unable to reach Room N, so Aoki cannot block a passage.


Sample Input 3

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

Sample Output 3

3.0133333333