A - Circle

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 100

問題文

整数 r が与えられます。

半径 r の円の面積が半径 1 の円の面積の何倍になるかを求めてください。

なお答えは制約の下では必ず整数になることが示せます。

制約

  • 1 \leq r \leq 100
  • 入力中のすべての値は整数である。

入力

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

r

出力

半径 r の円の面積が半径 1 の円の面積の何倍になるかを整数で出力せよ。


入力例 1

2

出力例 1

4

半径 2 の円の面積は半径 1 の円の面積の 4 倍です。

4.0 などの形式で出力すると不正解になることに注意してください。


入力例 2

100

出力例 2

10000

Score : 100 points

Problem Statement

Given is an integer r.

How many times is the area of a circle of radius r larger than the area of a circle of radius 1?

It can be proved that the answer is always an integer under the constraints given.

Constraints

  • 1 \leq r \leq 100
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

r

Output

Print the area of a circle of radius r, divided by the area of a circle of radius 1, as an integer.


Sample Input 1

2

Sample Output 1

4

The area of a circle of radius 2 is 4 times larger than the area of a circle of radius 1.

Note that output must be an integer - for example, 4.0 will not be accepted.


Sample Input 2

100

Sample Output 2

10000
B - Echo

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 200

問題文

正整数 N 及び、長さ N の英小文字から成る文字列 S が与えられます。

この文字列が、ある文字列を二度繰り返したものであるかを判定してください。 則ち、文字列 T であって、 S = T + T となるものが存在するかを判定してください。

制約

  • 1 ≤ N ≤ 100
  • S は英小文字から成る
  • |S| = N

入力

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

N
S

出力

S が文字列を二度繰り返したものであるならば Yes と、そうでないならば No と出力せよ。


入力例 1

6
abcabc

出力例 1

Yes

T = abc とおくと、 S = T + T となります。


入力例 2

6
abcadc

出力例 2

No

入力例 3

1
z

出力例 3

No

Score : 200 points

Problem Statement

Given are a positive integer N and a string S of length N consisting of lowercase English letters.

Determine whether the string is a concatenation of two copies of some string. That is, determine whether there is a string T such that S = T + T.

Constraints

  • 1 \leq N \leq 100
  • S consists of lowercase English letters.
  • |S| = N

Input

Input is given from Standard Input in the following format:

N
S

Output

If S is a concatenation of two copies of some string, print Yes; otherwise, print No.


Sample Input 1

6
abcabc

Sample Output 1

Yes

Let T = abc, and S = T + T.


Sample Input 2

6
abcadc

Sample Output 2

No

Sample Input 3

1
z

Sample Output 3

No
C - Average Length

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 300

問題文

座標平面上に N 個の町があります。町 i は、座標 ( x_i , y_i ) に位置しています。町 i と町 j の間の距離は \sqrt{\left(x_i-x_j\right)^2+\left(y_i-y_j\right)^2} です。

これらの町を全て 1 回ずつ訪れるとき、町を訪れる経路は全部で N! 通りあります。1 番目に訪れる町から出発し、2 番目に訪れる町、3 番目に訪れる町、\ldots、を経由し、N 番目に訪れる町に到着するまでの移動距離 (町から町への移動は直線移動とします) を、その経路の長さとします。これらの N! 通りの経路の長さの平均値を計算してください。

制約

  • 2 ≤ N ≤ 8
  • -1000 ≤ x_i ≤ 1000
  • -1000 ≤ y_i ≤ 1000
  • \left(x_i, y_i\right) \neq \left(x_j, y_j\right) ( i \neq j のとき)
  • (21:12 追記) 入力中の値はすべて整数である。

入力

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

N
x_1 y_1
:
x_N y_N

出力

経路の長さの平均値を出力せよ。 出力は、ジャッジの出力との絶対誤差または相対誤差が 10^{-6} 以下のとき正解と判定される。


入力例 1

3
0 0
1 0
0 1

出力例 1

2.2761423749

町を訪れる経路は 123 , 132 , 213 , 231 , 312 , 3216 通りです。

このうち、経路 123 の長さは、\sqrt{\left(0-1\right)^2+\left(0-0\right)^2} + \sqrt{\left(1-0\right)^2+\left(0-1\right)^2} = 1+\sqrt{2} となります。

同様に他の経路についても長さを計算すると、経路の長さの平均値は、

\frac{\left(1+\sqrt{2}\right)+\left(1+\sqrt{2}\right)+\left(2\right)+\left(1+\sqrt{2}\right)+\left(2\right)+\left(1+\sqrt{2}\right)}{6} = 2.276142...

であると分かります。


入力例 2

2
-879 981
-866 890

出力例 2

91.9238815543

町を訪れる経路は 12 , 212 通りありますが、これらの経路の長さは一致します。


入力例 3

8
-406 10
512 859
494 362
-955 -475
128 553
-986 -885
763 77
449 310

出力例 3

7641.9817824387

Score : 300 points

Problem Statement

There are N towns in a coordinate plane. Town i is located at coordinates (x_i, y_i). The distance between Town i and Town j is \sqrt{\left(x_i-x_j\right)^2+\left(y_i-y_j\right)^2}.

There are N! possible paths to visit all of these towns once. Let the length of a path be the distance covered when we start at the first town in the path, visit the second, third, \dots, towns, and arrive at the last town (assume that we travel in a straight line from a town to another). Compute the average length of these N! paths.

Constraints

  • 2 \leq N \leq 8
  • -1000 \leq x_i \leq 1000
  • -1000 \leq y_i \leq 1000
  • \left(x_i, y_i\right) \neq \left(x_j, y_j\right) (if i \neq j)
  • (Added 21:12 JST) All values in 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 average length of the paths. Your output will be judges as correct when the absolute difference from the judge's output is at most 10^{-6}.


Sample Input 1

3
0 0
1 0
0 1

Sample Output 1

2.2761423749

There are six paths to visit the towns: 123, 132, 213, 231, 312, and 321.

The length of the path 123 is \sqrt{\left(0-1\right)^2+\left(0-0\right)^2} + \sqrt{\left(1-0\right)^2+\left(0-1\right)^2} = 1+\sqrt{2}.

By calculating the lengths of the other paths in this way, we see that the average length of all routes is:

\frac{\left(1+\sqrt{2}\right)+\left(1+\sqrt{2}\right)+\left(2\right)+\left(1+\sqrt{2}\right)+\left(2\right)+\left(1+\sqrt{2}\right)}{6} = 2.276142...


Sample Input 2

2
-879 981
-866 890

Sample Output 2

91.9238815543

There are two paths to visit the towns: 12 and 21. These paths have the same length.


Sample Input 3

8
-406 10
512 859
494 362
-955 -475
128 553
-986 -885
763 77
449 310

Sample Output 3

7641.9817824387
D - Knight

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 400

問題文

二次元グリッドの原点 (0,0) にチェスのナイトの駒があります。

ナイトの駒はマス (i,j) にあるとき (i+1,j+2)(i+2, j+1) のどちらかのマスにのみ動かすことができます。

ナイトの駒をマス (X,Y) まで移動させる方法は何通りありますか?

10^9+7 で割った余りを求めてください。

制約

  • 1 \leq X \leq 10^6
  • 1 \leq Y \leq 10^6
  • 入力中のすべての値は整数である。

入力

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

X Y

出力

ナイトの駒を (0,0) から (X,Y) まで移動させる方法の数を、10^9+7 で割った余りを出力せよ。


入力例 1

3 3

出力例 1

2

(0,0) \to (1,2) \to (3,3)(0,0) \to (2,1) \to (3,3)2 通りが考えられます。


入力例 2

2 2

出力例 2

0

(2,2) にナイトの駒を移動させることはできません。


入力例 3

999999 999999

出力例 3

151840682

方法の数を 10^9+7 で割った余りを出力してください。

Score : 400 points

Problem Statement

There is a knight - the chess piece - at the origin (0, 0) of a two-dimensional grid.

When the knight is at the square (i, j), it can be moved to either (i+1,j+2) or (i+2, j+1).

In how many ways can the knight reach the square (X, Y)?

Find the number of ways modulo 10^9 + 7.

Constraints

  • 1 \leq X \leq 10^6
  • 1 \leq Y \leq 10^6
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

X Y

Output

Print the number of ways for the knight to reach (X, Y) from (0, 0), modulo 10^9 + 7.


Sample Input 1

3 3

Sample Output 1

2

There are two ways: (0,0) \to (1,2) \to (3,3) and (0,0) \to (2,1) \to (3,3).


Sample Input 2

2 2

Sample Output 2

0

The knight cannot reach (2,2).


Sample Input 3

999999 999999

Sample Output 3

151840682

Print the number of ways modulo 10^9 + 7.

E - All-you-can-eat

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 500

問題文

高橋君は食べ放題のお店に来ました。

N 種類の料理があり、i 番目の料理は、食べるために A_i 分必要で、美味しさは B_i です。

この店のルールは以下の通りです。

  • 1 度に 1 つの料理のみを注文することができます。注文した料理は即座に提供され、食べ始めることができます。

  • 同じ種類の料理を 2 度以上注文することはできません。

  • 提供済みの料理を食べ終わるまで次の料理を注文することはできません。

  • 最初の注文から T-0.5 分後以降に注文することはできませんが、提供済みの料理を食べることはできます。

高橋君の満足度を、この来店で高橋君が食べる料理の美味しさの合計とします。

高橋君が適切に行動したとき、満足度は最大でいくらになるでしょうか。

制約

  • 2 \leq N \leq 3000
  • 1 \leq T \leq 3000
  • 1 \leq A_i \leq 3000
  • 1 \leq B_i \leq 3000
  • 入力中のすべての値は整数である。

入力

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

N T
A_1 B_1
:
A_N B_N

出力

高橋君が適切に行動したときの、満足度の最大値を出力せよ。


入力例 1

2 60
10 10
100 100

出力例 1

110

1 番目、2 番目の順に料理を注文することで、満足度は 110 になります。

注文が時間内に間に合えば、食べるのにどれだけ時間がかかっても良いことに注意してください。


入力例 2

3 60
10 10
10 20
10 30

出力例 2

60

60 分以内に全ての料理を食べることができます。


入力例 3

3 60
30 10
30 20
30 30

出力例 3

50

2 番目、3 番目の順に料理に注文することで、満足度を 50 にできます。

どのような順に料理を注文しても、料理を 3 つ注文することはできません。


入力例 4

10 100
15 23
20 18
13 17
24 12
18 29
19 27
23 21
18 20
27 15
22 25

出力例 4

145

Score : 500 points

Problem Statement

Takahashi is at an all-you-can-eat restaurant.

The restaurant offers N kinds of dishes. It takes A_i minutes to eat the i-th dish, whose deliciousness is B_i.

The restaurant has the following rules:

  • You can only order one dish at a time. The dish ordered will be immediately served and ready to eat.
  • You cannot order the same kind of dish more than once.
  • Until you finish eating the dish already served, you cannot order a new dish.
  • After T-0.5 minutes from the first order, you can no longer place a new order, but you can continue eating the dish already served.

Let Takahashi's happiness be the sum of the deliciousness of the dishes he eats in this restaurant.

What is the maximum possible happiness achieved by making optimal choices?

Constraints

  • 2 \leq N \leq 3000
  • 1 \leq T \leq 3000
  • 1 \leq A_i \leq 3000
  • 1 \leq B_i \leq 3000
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N T
A_1 B_1
:
A_N B_N

Output

Print the maximum possible happiness Takahashi can achieve.


Sample Input 1

2 60
10 10
100 100

Sample Output 1

110

By ordering the first and second dishes in this order, Takahashi's happiness will be 110.

Note that, if we manage to order a dish in time, we can spend any amount of time to eat it.


Sample Input 2

3 60
10 10
10 20
10 30

Sample Output 2

60

Takahashi can eat all the dishes within 60 minutes.


Sample Input 3

3 60
30 10
30 20
30 30

Sample Output 3

50

By ordering the second and third dishes in this order, Takahashi's happiness will be 50.

We cannot order three dishes, in whatever order we place them.


Sample Input 4

10 100
15 23
20 18
13 17
24 12
18 29
19 27
23 21
18 20
27 15
22 25

Sample Output 4

145
F - Laminate

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 600

問題文

10^9N 列の白色グリッドのいくつかのマスを黒く塗って、アートを製作します。
現時点では、左から i 列目については下から H_i 個のマスを黒く塗り、その列の残りのマスは塗らない予定です。
アートの製作を開始する前に、あなたは K 個以下の列 (0 個でもよい) を選び、それらの列に対する H_i の値を 0 以上 10^9 以下の好きな整数に変更できます。
変更後の値は列ごとに個別に選べます。

その後、あなたは次の操作を繰り返すことで変更後のアートを製作します。

  • ある行の連続する 1 マス以上のマスを選んで黒く塗る。(すでに黒く塗られたマスを再び塗ってもよいが、塗らないことにしたマスを塗ってはならない。)

この操作を最小で何回行う必要があるか求めてください。

制約

  • 1 \leq N \leq 300
  • 0 \leq K \leq N
  • 1 \leq H_i \leq 10^9
  • 入力はすべて整数である。

入力

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

N K
H_1 H_2 ... H_N

出力

必要な最小の操作回数を出力せよ。


入力例 1

4 1
2 3 4 1

出力例 1

3

例えば、H_3 の値を 2 に変更した上で以下のような操作を行うと、3 回の操作で変更後のアートを製作することができます。

  • 下から 1 行目の左から 1 列目から 4 列目までのマスを黒く塗る。
  • 下から 2 行目の左から 1 列目から 3 列目までのマスを黒く塗る。
  • 下から 3 行目の左から 2 列目のマスを黒く塗る。

入力例 2

6 2
8 6 9 1 2 1

出力例 2

7

入力例 3

10 0
1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000

出力例 3

4999999996

Score : 600 points

Problem Statement

We will create an artwork by painting black some squares in a white square grid with 10^9 rows and N columns.
The current plan is as follows: for the i-th column from the left, we will paint the H_i bottommost squares and will not paint the other squares in that column.
Before starting to work, you can choose at most K columns (possibly zero) and change the values of H_i for these columns to any integers of your choice between 0 and 10^9 (inclusive).
Different values can be chosen for different columns.

Then, you will create the modified artwork by repeating the following operation:

  • Choose one or more consecutive squares in one row and paint them black. (Squares already painted black can be painted again, but squares not to be painted according to the modified plan should not be painted.)

Find the minimum number of times you need to perform this operation.

Constraints

  • 1 \leq N \leq 300
  • 0 \leq K \leq N
  • 0 \leq H_i \leq 10^9
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N K
H_1 H_2 ... H_N

Output

Print the minimum number of operations required.


Sample Input 1

4 1
2 3 4 1

Sample Output 1

3

For example, by changing the value of H_3 to 2, you can create the modified artwork by the following three operations:

  • Paint black the 1-st through 4-th squares from the left in the 1-st row from the bottom.
  • Paint black the 1-st through 3-rd squares from the left in the 2-nd row from the bottom.
  • Paint black the 2-nd square from the left in the 3-rd row from the bottom.

Sample Input 2

6 2
8 6 9 1 2 1

Sample Output 2

7

Sample Input 3

10 0
1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000

Sample Output 3

4999999996