A - Rounding

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 100

問題文

X, A0 以上 9 以下の整数です。

XA 未満の時 0A 以上の時 10 を出力してください。

制約

  • 0 \leq X, A \leq 9
  • 入力は全て整数である

入力

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

X A

出力

XA 未満の時 0A 以上の時 10 を出力せよ。


入力例 1

3 5

出力例 1

0

35 未満であるので、0 を出力してください。


入力例 2

7 5

出力例 2

10

75 以上であるので、10 を出力してください。


入力例 3

6 6

出力例 3

10

66 以上であるので、10 を出力してください。

Score : 100 points

Problem Statement

X and A are integers between 0 and 9 (inclusive).

If X is less than A, print 0; if X is not less than A, print 10.

Constraints

  • 0 \leq X, A \leq 9
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

X A

Output

If X is less than A, print 0; if X is not less than A, print 10.


Sample Input 1

3 5

Sample Output 1

0

3 is less than 5, so we should print 0.


Sample Input 2

7 5

Sample Output 2

10

7 is not less than 5, so we should print 10.


Sample Input 3

6 6

Sample Output 3

10

6 is not less than 6, so we should print 10.

B - Bounding

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 200

問題文

数直線上を N + 1 回跳ねるボールがあり、1 回目は 座標 D_1 = 0, i 回目は 座標 D_i = D_{i-1} + L_{i-1} (2 \leq i \leq N+1) で跳ねます。

数直線の座標が X 以下の領域でボールが跳ねる回数は何回でしょうか。

制約

  • 1 \leq N \leq 100
  • 1 \leq L_i \leq 100
  • 1 \leq X \leq 10000
  • 入力は全て整数である

入力

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

N X
L_1 L_2 ... L_{N-1} L_N

出力

数直線の座標が X 以下の領域でボールが跳ねる回数を出力せよ。


入力例 1

3 6
3 4 5

出力例 1

2

ボールは順に座標 0, 3, 7, 12 で跳ねるので、座標 6 以下の領域で跳ねる回数は 2 回です。


入力例 2

4 9
3 3 3 3

出力例 2

4

ボールは順に座標 0, 3, 6, 9, 12 で跳ねるので、座標 9 以下の領域で跳ねる回数は 4 回です。

Score : 200 points

Problem Statement

A ball will bounce along a number line, making N + 1 bounces. It will make the first bounce at coordinate D_1 = 0, and the i-th bounce (2 \leq i \leq N+1) at coordinate D_i = D_{i-1} + L_{i-1}.

How many times will the ball make a bounce where the coordinate is at most X?

Constraints

  • 1 \leq N \leq 100
  • 1 \leq L_i \leq 100
  • 1 \leq X \leq 10000
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N X
L_1 L_2 ... L_{N-1} L_N

Output

Print the number of times the ball will make a bounce where the coordinate is at most X.


Sample Input 1

3 6
3 4 5

Sample Output 1

2

The ball will make a bounce at the coordinates 0, 3, 7 and 12, among which two are less than or equal to 6.


Sample Input 2

4 9
3 3 3 3

Sample Output 2

4

The ball will make a bounce at the coordinates 0, 3, 6, 9 and 12, among which four are less than or equal to 9.

C - Rectangle Cutting

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 300

問題文

平面上に長方形があり、4 つの頂点の座標は (0,0),(W,0),(W,H),(0,H) です。 この長方形の内部または周上の点 (x,y) が与えられます。(x,y) を通る直線で長方形を 2 つの部分に分割するとき、 面積の大きくない方の面積の最大値を求めてください。また、その最大値を達成する分割の方法が複数あるかも判定してください。

制約

  • 1 \leq W,H \leq 10^9
  • 0\leq x\leq W
  • 0\leq y\leq H
  • 入力はすべて整数である

入力

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

W H x y

出力

はじめに、面積の大きくない方の面積の最大値を出力せよ。つづいて、その最大値を達成する分割の方法が複数あるなら 1 を、そうでないなら 0 を出力せよ。 出力された面積は、絶対誤差あるいは相対誤差が 10^{-9} 以下の時正答と判定される。


入力例 1

2 3 1 2

出力例 1

3.000000 0

直線 x=1 で分割するのが最適です。また、最適な分割方法はこれ以外には存在しません。


入力例 2

2 2 1 1

出力例 2

2.000000 1

Score : 300 points

Problem Statement

There is a rectangle in a coordinate plane. The coordinates of the four vertices are (0,0), (W,0), (W,H), and (0,H). You are given a point (x,y) which is within the rectangle or on its border. We will draw a straight line passing through (x,y) to cut the rectangle into two parts. Find the maximum possible area of the part whose area is not larger than that of the other. Additionally, determine if there are multiple ways to cut the rectangle and achieve that maximum.

Constraints

  • 1 \leq W,H \leq 10^9
  • 0\leq x\leq W
  • 0\leq y\leq H
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

W H x y

Output

Print the maximum possible area of the part whose area is not larger than that of the other, followed by 1 if there are multiple ways to cut the rectangle and achieve that maximum, and 0 otherwise.

The area printed will be judged correct when its absolute or relative error is at most 10^{-9}.


Sample Input 1

2 3 1 2

Sample Output 1

3.000000 0

The line x=1 gives the optimal cut, and no other line does.


Sample Input 2

2 2 1 1

Sample Output 2

2.000000 1
D - Enough Array

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 400

問題文

長さ N の正整数列 A=a_1,a_2,…,a_{N} と整数 K が与えられます。A の連続する部分列であって、以下の条件を満たすようなものは何個あるでしょうか。

  • (条件) 連続部分列に含まれる全ての要素の値の和は、K 以上である。

ただし、ある二つの連続部分列が列として同じでも、取り出された位置が異なるならそれらは別々に数えるものとします。

出力が 32bit 整数型に収まらない場合があることに注意してください。

制約

  • 1 \leqq a_i \leqq 10^5
  • 1 \leqq N \leqq 10^5
  • 1 \leqq K \leqq 10^{10}

入力

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

N K
a_1 a_2 ... a_N

出力

条件を満たすような連続部分列の個数を出力してください。


入力例 1

4 10
6 1 2 7

出力例 1

2
  • A[1..4]=a_1,a_2,a_3,a_4 (要素の値の和は 16)
  • A[2..4]=a_2,a_3,a_4 (要素の値の和は 10)

の二通りです。


入力例 2

3 5
3 3 3

出力例 2

3

ある二つの連続部分列が列として同じでも、取り出された位置が異なるならそれらは別々に数えることに注意してください。


入力例 3

10 53462
103 35322 232 342 21099 90000 18843 9010 35221 19352

出力例 3

36

Score : 400 points

Problem Statement

You are given a sequence of positive integers of length N, A=a_1,a_2,…,a_{N}, and an integer K. How many contiguous subsequences of A satisfy the following condition?

  • (Condition) The sum of the elements in the contiguous subsequence is at least K.

We consider two contiguous subsequences different if they derive from different positions in A, even if they are the same in content.

Note that the answer may not fit into a 32-bit integer type.

Constraints

  • 1 \leq a_i \leq 10^5
  • 1 \leq N \leq 10^5
  • 1 \leq K \leq 10^{10}

Input

Input is given from Standard Input in the following format:

N K
a_1 a_2 ... a_N

Output

Print the number of contiguous subsequences of A that satisfy the condition.


Sample Input 1

4 10
6 1 2 7

Sample Output 1

2

The following two contiguous subsequences satisfy the condition:

  • A[1..4]=a_1,a_2,a_3,a_4, with the sum of 16
  • A[2..4]=a_2,a_3,a_4, with the sum of 10

Sample Input 2

3 5
3 3 3

Sample Output 2

3

Note again that we consider two contiguous subsequences different if they derive from different positions, even if they are the same in content.


Sample Input 3

10 53462
103 35322 232 342 21099 90000 18843 9010 35221 19352

Sample Output 3

36
E - Common Subsequence

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 500

問題文

1 以上 10^5 以下の整数から成る、長さ N の整数列 S と 長さ M の整数列 T が与えられます。

S の部分列と T の部分列の組であって、整数列として等しいような組は何通りあるでしょうか。

ただし、整数列 A の部分列とは、A の要素を 0 個以上いくつか選んで削除し、残ったものを元の順序を保って並べた整数列を表します。

また、S, T それぞれの部分列は、整数列として等しい場合でも、削除した要素の添字の集合が異なる場合には異なる部分列として区別してください。

答えは非常に大きくなることがあるので、10^9+7 で割った余りを出力してください。

制約

  • 1 \leq N, M \leq 2 \times 10^3
  • S の長さは N である
  • T の長さは M である
  • 1 \leq S_i, T_i \leq 10^5
  • 入力は全て整数である

入力

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

N M
S_1 S_2 ... S_{N-1} S_{N}
T_1 T_2 ... T_{M-1} T_{M}

出力

整数列として等しいような、S, T の部分列の組の個数を 10^9+7 で割った余りを出力せよ。


入力例 1

2 2
1 3
3 1

出力例 1

3

S の部分列としては (), (1), (3), (1, 3) が考えられます。

T の部分列としては (), (3), (1), (3, 1) が考えられます。

共に部分列が () である組は 1 \times 1 通り、共に部分列が (1) である組は 1 \times 1 通り、共に部分列が (3) である組は 1 \times 1 通り考えられるので、合計 3 通りの組が存在します。


入力例 2

2 2
1 1
1 1

出力例 2

6

S の部分列としては (), (1), (1), (1, 1) が考えられます。

T の部分列としては (), (1), (1), (1, 1) が考えられます。

共に部分列が () である組は 1 \times 1 通り、共に部分列が (1) である組は 2 \times 2 通り、共に部分列が (1, 1) である組は 1 \times 1 通り考えられるので、合計 6 通りの組が存在します。 部分列において削除する要素の添字の集合が異なるものを区別することに注意してください。


入力例 3

4 4
3 4 5 6
3 4 5 6

出力例 3

16

入力例 4

10 9
9 6 5 7 5 9 8 5 6 7
8 6 8 5 5 7 9 9 7

出力例 4

191

入力例 5

20 20
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

出力例 5

846527861

個数を 10^9+7 で割った余りを出力することに注意してください。

Score : 500 points

Problem Statement

You are given two integer sequences S and T of length N and M, respectively, both consisting of integers between 1 and 10^5 (inclusive).

In how many pairs of a subsequence of S and a subsequence of T do the two subsequences are the same in content?

Here the subsequence of A is a sequence obtained by removing zero or more elements from A and concatenating the remaining elements without changing the order.

For both S and T, we distinguish two subsequences if the sets of the indices of the removed elements are different, even if the subsequences are the same in content.

Since the answer can be tremendous, print the number modulo 10^9+7.

Constraints

  • 1 \leq N, M \leq 2 \times 10^3
  • The length of S is N.
  • The length of T is M.
  • 1 \leq S_i, T_i \leq 10^5
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N M
S_1 S_2 ... S_{N-1} S_{N}
T_1 T_2 ... T_{M-1} T_{M}

Output

Print the number of pairs of a subsequence of S and a subsequence of T such that the subsequences are the same in content, modulo 10^9+7.


Sample Input 1

2 2
1 3
3 1

Sample Output 1

3

S has four subsequences: (), (1), (3), (1, 3).

T has four subsequences: (), (3), (1), (3, 1).

There are 1 \times 1 pair of subsequences in which the subsequences are both (), 1 \times 1 pair of subsequences in which the subsequences are both (1), and 1 \times 1 pair of subsequences in which the subsequences are both (3), for a total of three pairs.


Sample Input 2

2 2
1 1
1 1

Sample Output 2

6

S has four subsequences: (), (1), (1), (1, 1).

T has four subsequences: (), (1), (1), (1, 1).

There are 1 \times 1 pair of subsequences in which the subsequences are both (), 2 \times 2 pairs of subsequences in which the subsequences are both (1), and 1 \times 1 pair of subsequences in which the subsequences are both (1,1), for a total of six pairs. Note again that we distinguish two subsequences if the sets of the indices of the removed elements are different, even if the subsequences are the same in content.


Sample Input 3

4 4
3 4 5 6
3 4 5 6

Sample Output 3

16

Sample Input 4

10 9
9 6 5 7 5 9 8 5 6 7
8 6 8 5 5 7 9 9 7

Sample Output 4

191

Sample Input 5

20 20
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

Sample Output 5

846527861

Be sure to print the number modulo 10^9+7.

F - Minimum Bounding Box

Time Limit: 5 sec / Memory Limit: 1024 MB

配点 : 600

問題文

二次元平面に N 個の点があります。i 番目の点の初期座標は (x_i, y_i) です。それぞれの点はこれから秒速 1 で同時に移動を始めます。点の移動方向は全て x 軸または y 軸に平行です。具体的には i 番目の点の移動方向は文字 d_i によって与えられ、

  • d_i = R のとき x 軸正方向
  • d_i = L のとき x 軸負方向
  • d_i = U のとき y 軸正方向
  • d_i = D のとき y 軸負方向

です。

あなたは点が移動を開始して以降、任意のタイミングで全ての点の動きを止めることができます (移動開始 0 秒後に止めることも可能です)。 動きを止めたあとの N 点の x 座標のうち最大のものを x_{max}、最小のものを x_{min}y 座標のうち最大のものを y_{max}、最小のものを y_{min} とします。

(x_{max} - x_{min}) \times (y_{max} - y_{min}) としてありうる値の最小値を求めて出力してください。

制約

  • 1 \leq N \leq 10^5
  • -10^8 \leq x_i,\ y_i \leq 10^8
  • x_i, \ y_i はともに整数である。
  • d_iR, L, U, D のいずれかである。

入力

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

N
x_1 y_1 d_1
x_2 y_2 d_2
.
.
.
x_N y_N d_N

出力

(x_{max} - x_{min}) \times (y_{max} - y_{min}) としてありうる値の最小値を出力せよ。

ジャッジプログラムの出力との絶対誤差または相対誤差が 10^{-9} 以下のとき正解とみなされる。


入力例 1

2
0 3 D
3 0 L

出力例 1

0

3 秒後に 2 つの点は原点で重なり、このとき題意の値は 0 になります。


入力例 2

5
-7 -10 U
7 -6 U
-8 7 D
-3 3 D
0 -6 R

出力例 2

97.5

出力が整数にならない場合もあります。


入力例 3

20
6 -10 R
-4 -9 U
9 6 D
-3 -2 R
0 7 D
4 5 D
10 -10 U
-1 -8 U
10 -6 D
8 -5 U
6 4 D
0 3 D
7 9 R
9 -4 R
3 10 D
1 9 U
1 -6 U
9 -8 R
6 7 D
7 -3 D

出力例 3

273

Score : 600 points

Problem Statement

There are N points in a two-dimensional plane. The initial coordinates of the i-th point are (x_i, y_i). Now, each point starts moving at a speed of 1 per second, in a direction parallel to the x- or y- axis. You are given a character d_i that represents the specific direction in which the i-th point moves, as follows:

  • If d_i = R, the i-th point moves in the positive x direction;
  • If d_i = L, the i-th point moves in the negative x direction;
  • If d_i = U, the i-th point moves in the positive y direction;
  • If d_i = D, the i-th point moves in the negative y direction.

You can stop all the points at some moment of your choice after they start moving (including the moment they start moving). Then, let x_{max} and x_{min} be the maximum and minimum among the x-coordinates of the N points, respectively. Similarly, let y_{max} and y_{min} be the maximum and minimum among the y-coordinates of the N points, respectively.

Find the minimum possible value of (x_{max} - x_{min}) \times (y_{max} - y_{min}) and print it.

Constraints

  • 1 \leq N \leq 10^5
  • -10^8 \leq x_i,\ y_i \leq 10^8
  • x_i and y_i are integers.
  • d_i is R, L, U, or D.

Input

Input is given from Standard Input in the following format:

N
x_1 y_1 d_1
x_2 y_2 d_2
.
.
.
x_N y_N d_N

Output

Print the minimum possible value of (x_{max} - x_{min}) \times (y_{max} - y_{min}).

The output will be considered correct when its absolute or relative error from the judge's output is at most 10^{-9}.


Sample Input 1

2
0 3 D
3 0 L

Sample Output 1

0

After three seconds, the two points will meet at the origin. The value in question will be 0 at that moment.


Sample Input 2

5
-7 -10 U
7 -6 U
-8 7 D
-3 3 D
0 -6 R

Sample Output 2

97.5

The answer may not be an integer.


Sample Input 3

20
6 -10 R
-4 -9 U
9 6 D
-3 -2 R
0 7 D
4 5 D
10 -10 U
-1 -8 U
10 -6 D
8 -5 U
6 4 D
0 3 D
7 9 R
9 -4 R
3 10 D
1 9 U
1 -6 U
9 -8 R
6 7 D
7 -3 D

Sample Output 3

273