A - Repression

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 100

問題文

机の上に、正整数が書かれた 3 枚のカードがあります。 3 枚のカードにはそれぞれ整数 A,B,C が書き込まれています。

いま、この中からちょうど 2 枚のカードを選んで手に持ちました。

手に持ったカードに書き込まれた整数の和として考えられる最大値を求めてください。

制約

  • 1 \leq A,B,C \leq 100
  • 入力は全て整数

入力

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

A B C

出力

答えを整数として出力せよ。


入力例 1

3 4 5

出力例 1

9

4,5 の書き込まれた 2 枚のカードを手に持つと、そこに書き込まれた整数の和が 4+5=9 となります。

これより和が大きくなるカードの選び方は存在しないので、9 を出力します。


入力例 2

6 6 6

出力例 2

12

どのように手に持つカードを選んでも、そこに書き込まれた整数の和は 12 になります。


入力例 3

99 99 98

出力例 3

198

Score : 100 points

Problem Statement

There are three cards on the desk, each with a positive integer written on it. The integers on the cards are A, B, and C.

You have chosen two cards and picked them up.

Find the maximum possible sum of the integers written on the picked cards.

Constraints

  • 1 \leq A,B,C \leq 100
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

A B C

Output

Print the answer as an integer.


Sample Input 1

3 4 5

Sample Output 1

9

If you pick up two cards with 4 and 5, the sum of the integers will be 4+5=9.

There is no way to pick up cards with a greater sum, so we should print 9.


Sample Input 2

6 6 6

Sample Output 2

12

Whichever two cards you choose, the sum of the integers will be 12.


Sample Input 3

99 99 98

Sample Output 3

198
B - Hydrate

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 200

問題文

水色のボールが A 個容器に入っています。高橋くんはこの容器に対し、以下の操作を 0 回以上好きなだけ繰り返します。

  • 水色のボール B 個と赤色のボール C 個を容器に追加する。

高橋くんの目標は、容器に入っている水色のボールの個数が赤色のボールの個数の D 倍以下になるようにすることです。

目標が達成可能かを判定し、可能なら必要な操作回数の最小値を求めてください。

制約

  • 1 \leq A,B,C,D \leq 10^5
  • 入力は全て整数である。

入力

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

A B C D

出力

高橋くんの目標が達成可能なら、操作回数の最小値を出力せよ。そうでなければ、-1 を出力せよ。


入力例 1

5 2 3 2

出力例 1

2

0 回目の操作を行った直後の (= 1 度も操作をしていない状態での) 容器には、水色のボールが 5 個と赤色のボールが 0 個入っています。水色のボールの個数は赤色のボールの個数の D=2 倍よりも大きいので、この時点ではまだ高橋くんの目標は達成されていません。

1 回目の操作を行った直後の容器には、水色のボールが 7 個と赤色のボールが 3 個入っています。水色のボールの個数は赤色のボールの個数の 2 倍よりも大きいので、この時点でもまだ高橋くんの目標は達成されていません。

2 回目の操作を行った直後の容器には、水色のボールが 9 個と赤色のボールが 6 個入っています。水色のボールの個数は赤色のボールの個数の 2 倍以下であるため、高橋くんの目標は達成されています。

よって答えは 2 となります。


入力例 2

6 9 2 3

出力例 2

-1

高橋くんが何回操作を繰り返しても、彼の目標が達成されることはありません。

Score : 200 points

Problem Statement

There is a container with A cyan balls. Takahashi will do the following operation as many times as he likes (possibly zero times):

  • add B cyan balls and C red balls into the container.

Takahashi's objective is to reach a situation where the number of cyan balls in the container is at most D times the number of red balls in it.

Determine whether the objective is achievable. If it is achievable, find the minimum number of operations needed to achieve it.

Constraints

  • 1 \leq A,B,C,D \leq 10^5
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

A B C D

Output

If Takahashi's objective is achievable, print the minimum number of operations needed to achieve it. Otherwise, print -1.


Sample Input 1

5 2 3 2

Sample Output 1

2

Before the first operation, the container has 5 cyan balls and 0 red balls. Since 5 is greater than 0 multiplied by D=2, Takahashi's objective is not yet achieved.

Just after the first operation, the container has 7 cyan balls and 3 red balls. Since 7 is greater than 3 multiplied by 2, the objective is still not achieved.

Just after the second operation, the container has 9 cyan balls and 6 red balls. Since 9 is not greater than 6 multiplied by 2, the objective is achieved.

Thus, the answer is 2.


Sample Input 2

6 9 2 3

Sample Output 2

-1

No matter how many times Takahashi repeats the operation, his objective will never be achieved.

C - Many Segments

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 300

問題文

1 から N までの番号が付いた N 個の区間が与えられます。区間 i は、

  • t_i=1 なら [l_i,r_i]
  • t_i=2 なら [l_i,r_i)
  • t_i=3 なら (l_i,r_i]
  • t_i=4 なら (l_i,r_i)

です。

1 \leq i \lt j \leq N を満たす整数の組 (i,j) のうち、区間 i と区間 j が共通部分を持つようなものは幾つありますか?

区間 [X,Y],[X,Y),(X,Y],(X,Y) とは?
  • 閉区間 [X,Y] は、 X 以上 Y 以下の全ての実数からなる区間
  • 半開区間 [X,Y) は、 X 以上 Y 未満の全ての実数からなる区間
  • 半開区間 (X,Y] は、 X より大きく Y 以下の全ての実数からなる区間
  • 開区間 (X,Y) は、 X より大きく Y 未満の全ての実数からなる区間
を表します。一言で言うと、角括弧 [] を使っている側は端点を含み、丸括弧 () を使っている側は端点を含みません。

制約

  • 2 \leq N \leq 2000
  • 1 \leq t_i \leq 4
  • 1 \leq l_i \lt r_i \leq 10^9
  • 入力は全て整数

入力

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

N
t_1 l_1 r_1
t_2 l_2 r_2
\hspace{1cm}\vdots
t_N l_N r_N

出力

区間 i と区間 j が共通部分を持つような整数の組 (i,j) の個数を出力せよ。


入力例 1

3
1 1 2
2 2 3
3 2 4

出力例 1

2

問題文中の定義より、区間 1[1,2], 区間 2[2,3), 区間 3(2,4] です。

区間 i と区間 j が共通部分を持つような整数の組 (i,j) は、(1,2)(2,3)2 つとなります。それぞれ、[2,2](2,3) を共通部分として持っています。


入力例 2

19
4 210068409 221208102
4 16698200 910945203
4 76268400 259148323
4 370943597 566244098
1 428897569 509621647
4 250946752 823720939
1 642505376 868415584
2 619091266 868230936
2 306543999 654038915
4 486033777 715789416
1 527225177 583184546
2 885292456 900938599
3 264004185 486613484
2 345310564 818091848
1 152544274 521564293
4 13819154 555218434
3 507364086 545932412
4 797872271 935850549
2 415488246 685203817

出力例 2

102

Score : 300 points

Problem Statement

You are given N intervals numbered 1 through N, that are as follows:

  • if t_i=1, Interval i is [l_i,r_i];
  • if t_i=2, Interval i is [l_i,r_i);
  • if t_i=3, Interval i is (l_i,r_i];
  • if t_i=4, Interval i is (l_i,r_i).

How many pairs of integers (i,j) satisfying 1 \leq i \lt j \leq N are there such that Interval i and Interval j intersect?

What are [X,Y],[X,Y),(X,Y],(X,Y)?
  • A closed interval [X,Y] is an interval consisting of all real numbers x such that X \leq x \leq Y.
  • A half-open interval [X,Y) is an interval consisting of all real numbers x such that X \leq x < Y.
  • A half-open interval (X,Y] is an interval consisting of all real numbers x such that X < x \leq Y.
  • A open interval (X,Y) is an interval consisting of all real numbers x such that X < x < Y.
Roughly speaking, square brackets [] mean the endpoint is included, and curly brackets () mean the endpoint is excluded.

Constraints

  • 2 \leq N \leq 2000
  • 1 \leq t_i \leq 4
  • 1 \leq l_i \lt r_i \leq 10^9
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
t_1 l_1 r_1
t_2 l_2 r_2
\hspace{1cm}\vdots
t_N l_N r_N

Output

Print the number of pairs of integers (i,j) such that Interval i and Interval j intersect.


Sample Input 1

3
1 1 2
2 2 3
3 2 4

Sample Output 1

2

As defined in the Problem Statement, Interval 1 is [1,2], Interval 2 is [2,3), and Interval 3 is (2,4].

There are two pairs of integers (i,j) such that Interval i and Interval j intersect: (1,2) and (2,3). For the first pair, the intersection is [2,2], and for the second pair, the intersection is (2,3).


Sample Input 2

19
4 210068409 221208102
4 16698200 910945203
4 76268400 259148323
4 370943597 566244098
1 428897569 509621647
4 250946752 823720939
1 642505376 868415584
2 619091266 868230936
2 306543999 654038915
4 486033777 715789416
1 527225177 583184546
2 885292456 900938599
3 264004185 486613484
2 345310564 818091848
1 152544274 521564293
4 13819154 555218434
3 507364086 545932412
4 797872271 935850549
2 415488246 685203817

Sample Output 2

102
D - Congruence Points

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 400

問題文

要素数が共に N であるような二次元平面上の点の集合 S=\{(a_1,b_1),(a_2,b_2),\ldots,(a_N,b_N)\}T=\{(c_1,d_1),(c_2,d_2),\ldots,(c_N,d_N)\} が与えられます。

S に対して以下の操作を 0 回以上任意の順に好きなだけ繰り返すことで、ST を一致させられるかを判定してください。

  • 実数 p\ (0 \lt p \lt 360) を定め、 S に含まれる全ての点を、原点を中心に時計回りに p 度回転させる。
  • 実数 q,r を定める。S に含まれる全ての点を、x 軸方向に q, y 軸方向に r 移動させる。q, r の値域に制約はなく、特に正/負/零のいずれになってもよい。

制約

  • 1 \leq N \leq 100
  • -10 \leq a_i,b_i,c_i,d_i \leq 10
  • i \neq j なら (a_i,b_i) \neq (a_j,b_j)
  • i \neq j なら (c_i,d_i) \neq (c_j,d_j)
  • 入力は全て整数

入力

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

N
a_1 b_1
a_2 b_2
\hspace{0.6cm}\vdots
a_N b_N
c_1 d_1
c_2 d_2
\hspace{0.6cm}\vdots
c_N d_N

出力

問題文中の操作によって ST を一致させられるなら Yes を、一致させられないなら No を出力せよ。


入力例 1

3
0 0
0 1
1 0
2 0
3 0
3 1

出力例 1

Yes

S に含まれる点を赤で、T に含まれる点を緑で塗った場合、与えられる点集合は以下の図の通りになります。

この場合、以下の手順によって ST に一致させることができます。

  1. S に含まれる全ての点を、原点を中心に時計回りに 270 度回転させる。
  2. S に含まれる全ての点を、x 軸方向に 3, y 軸方向に 0 移動させる。

入力例 2

3
1 0
1 1
3 0
-1 0
-1 1
-3 0

出力例 2

No

入力に対応する図は以下の通りです。

STy 軸に対して線対称ですが、問題文中に書かれているような回転操作、移動操作によって ST を一致させることはできません。


入力例 3

4
0 0
2 9
10 -2
-6 -7
0 0
2 9
10 -2
-6 -7

出力例 3

Yes

入力例 4

6
10 5
-9 3
1 -5
-6 -5
6 9
-9 0
-7 -10
-10 -5
5 4
9 0
0 -10
-10 -2

出力例 4

Yes

Score : 400 points

Problem Statement

You are given two sets S=\{(a_1,b_1),(a_2,b_2),\ldots,(a_N,b_N)\} and T=\{(c_1,d_1),(c_2,d_2),\ldots,(c_N,d_N)\} of N points each on a two-dimensional plane.

Determine whether it is possible to do the following operations on S any number of times (possibly zero) in any order so that S matches T.

  • Choose a real number p\ (0 \lt p \lt 360) and rotate every point in S p degrees clockwise about the origin.
  • Choose real numbers q and r and move every point in S by q in the x-direction and by r in the y-direction. Here, q and r can be any real numbers, be it positive, negative, or zero.

Constraints

  • 1 \leq N \leq 100
  • -10 \leq a_i,b_i,c_i,d_i \leq 10
  • (a_i,b_i) \neq (a_j,b_j) if i \neq j.
  • (c_i,d_i) \neq (c_j,d_j) if i \neq j.
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
a_1 b_1
a_2 b_2
\hspace{0.6cm}\vdots
a_N b_N
c_1 d_1
c_2 d_2
\hspace{0.6cm}\vdots
c_N d_N

Output

If we can match S with T, print Yes; otherwise, print No.


Sample Input 1

3
0 0
0 1
1 0
2 0
3 0
3 1

Sample Output 1

Yes

The figure below shows the given sets of points, where the points in S and T are painted red and green, respectively:

In this case, we can match S with T as follows:

  1. Rotate every point in S 270 degrees clockwise about the origin.
  2. Move every point in S by 3 in the x-direction and by 0 in the y-direction.

Sample Input 2

3
1 0
1 1
3 0
-1 0
-1 1
-3 0

Sample Output 2

No

The figure below shows the given sets of points:

Although S and T are symmetric about the y-axis, we cannot match S with T by rotations and translations as stated in Problem Statement.


Sample Input 3

4
0 0
2 9
10 -2
-6 -7
0 0
2 9
10 -2
-6 -7

Sample Output 3

Yes

Sample Input 4

6
10 5
-9 3
1 -5
-6 -5
6 9
-9 0
-7 -10
-10 -5
5 4
9 0
0 -10
-10 -2

Sample Output 4

Yes
E - Mod i

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 500

問題文

長さ N の数列 A が与えられます。A をいくつかの連続した空でない部分列 B_1,B_2,\ldots,B_k に切り分ける方法であって、以下の条件を満たすものの個数を求めてください。

  • 全ての i\ (1 \leq i \leq k) について、B_i に含まれる要素の総和が i で割り切れる。

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

制約

  • 1 \leq N \leq 3000
  • 1 \leq A_i \leq 10^{15}
  • 入力は全て整数

入力

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

N
A_1 A_2 \ldots A_N

出力

問題文中の条件を満たすような切り分け方の個数を (10^9+7) で割ったあまりを出力せよ。


入力例 1

4
1 2 3 4

出力例 1

3

以下の 3 通りの切り分け方があります。

  • (1),(2),(3),(4)
  • (1,2,3),(4)
  • (1,2,3,4)

入力例 2

5
8 6 3 3 3

出力例 2

5

入力例 3

10
791754273866483 706434917156797 714489398264550 918142301070506 559125109706263 694445720452148 648739025948445 869006293795825 718343486637033 934236559762733

出力例 3

15

入力が 32 bit 整数型に収まりきらない場合があります。

Score : 500 points

Problem Statement

Given is a sequence A of N numbers. Find the number of ways to separate A into some number of non-empty contiguous subsequence B_1, B_2, \ldots, B_k so that the following condition is satisfied:

  • For every i\ (1 \leq i \leq k), the sum of elements in B_i is divisible by i.

Since the count can be enormous, print it modulo (10^9+7).

Constraints

  • 1 \leq N \leq 3000
  • 1 \leq A_i \leq 10^{15}
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 \ldots A_N

Output

Print the number of ways to separate the sequence so that the condition in the Problem Statement is satisfied, modulo (10^9+7).


Sample Input 1

4
1 2 3 4

Sample Output 1

3

We have three ways to separate the sequence, as follows:

  • (1),(2),(3),(4)
  • (1,2,3),(4)
  • (1,2,3,4)

Sample Input 2

5
8 6 3 3 3

Sample Output 2

5

Sample Input 3

10
791754273866483 706434917156797 714489398264550 918142301070506 559125109706263 694445720452148 648739025948445 869006293795825 718343486637033 934236559762733

Sample Output 3

15

The values in input may not fit into a 32-bit integer type.

F - Tree Patrolling

Time Limit: 3 sec / Memory Limit: 1024 MB

配点 : 600

問題文

N 頂点の木があり、各頂点には 1 から N までの番号が振られています。また、i 本目の辺は頂点 u_i と頂点 v_i を双方向に結んでいます。

この木の持ち主であるあなたは、いくつかの頂点 (0 個でもよい) を選んで高橋くんを配置し、木の警備をさせることにしました。頂点 x に配置された高橋くんは、x と直接辺で結ばれた頂点、及び x 自身を警備します。

高橋くんを配置する頂点の選び方は 2^N 通りありますが、そのうち 1 人以上の高橋くんに警備された頂点の個数がちょうど K 個となるような選び方はいくつありますか?

K=0,1,\ldots,N について答えを求め、(10^9+7) で割ったあまりを出力してください。

制約

  • 1 \leq N \leq 2000
  • 1 \leq u_i \lt v_i \leq N
  • 与えられるグラフは木
  • 入力は全て整数

入力

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

N
u_1 v_1
u_2 v_2
\hspace{0.6cm}\vdots
u_{N-1} v_{N-1}

出力

N+1 行に渡って出力せよ。i 行目には、K=i-1 とした場合の答えを出力すること。


入力例 1

3
1 3
1 2

出力例 1

1
0
2
5

高橋くんを配置する頂点の選び方は、以下の 8 通りです。

  • どの頂点にも高橋くんを配置しない。いずれの頂点も高橋くんに警備されていない状態となる。
  • 頂点 1 に高橋くんを配置する。全ての頂点が高橋くんに警備された状態となる。
  • 頂点 2 に高橋くんを配置する。頂点 1, 22 つが高橋くんに警備された状態となる。
  • 頂点 3 に高橋くんを配置する。頂点 1, 32 つが高橋くんに警備された状態となる。
  • 頂点 1 と頂点 2 に高橋くんを配置する。全ての頂点が高橋くんに警備された状態となる。
  • 頂点 1 と頂点 3 に高橋くんを配置する。全ての頂点が高橋くんに警備された状態となる。
  • 頂点 2 と頂点 3 に高橋くんを配置する。全ての頂点が高橋くんに警備された状態となる。
  • 全ての頂点に高橋くんを配置する。全ての頂点が高橋くんに警備された状態となる。

入力例 2

5
1 3
4 5
1 5
2 3

出力例 2

1
0
2
5
7
17

入力例 3

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

出力例 3

1
0
3
8
15
32
68
110
196
266
325

Score : 600 points

Problem Statement

You have a tree with N vertices, numbered 1 through N. The i-th edge connects Vertex u_i and Vertex v_i.

You will choose some vertices (possibly none) and place a takahashi in each of them to guard the tree. A takahashi placed at Vertex x will guard x itself and the vertices directly connected to x by an edge.

There are 2^N ways to choose vertices for placing takahashi. In how many of them will there be exactly K vertices guarded by one or more takahashi?

Find this count and print it modulo (10^9+7) for each K=0,1,\ldots,N.

Constraints

  • 1 \leq N \leq 2000
  • 1 \leq u_i \lt v_i \leq N
  • The given graph is a tree.
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
u_1 v_1
u_2 v_2
\hspace{0.6cm}\vdots
u_{N-1} v_{N-1}

Output

Print N+1 lines. The i-th line should contain the answer for K=i-1.


Sample Input 1

3
1 3
1 2

Sample Output 1

1
0
2
5

There are eight ways to choose vertices for placing takahashi, as follows:

  • Place a takahashi at no vertices, guarding no vertices.
  • Place a takahashi at Vertex 1, guarding all vertices.
  • Place a takahashi at Vertex 2, guarding Vertices 1 and 2.
  • Place a takahashi at Vertex 3, guarding Vertices 1 and 3.
  • Place a takahashi at Vertices 1 and 2, guarding all vertices.
  • Place a takahashi at Vertices 1 and 3, guarding all vertices.
  • Place a takahashi at Vertices 2 and 3, guarding all vertices.
  • Place a takahashi at all vertices, guarding all vertices.

Sample Input 2

5
1 3
4 5
1 5
2 3

Sample Output 2

1
0
2
5
7
17

Sample Input 3

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

Sample Output 3

1
0
3
8
15
32
68
110
196
266
325