A - Watching the Fireworks Festival

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 266

問題文

高橋君は花火大会の会場にいます。 2 次元平面上に N 個の花火の打ち上げ地点があり、 i 番目の花火は座標 (X_i, Y_i) から打ち上げられます。 i 番目の花火を観覧できた場合、満足度が P_i 得られます。

高橋君は座標 (X_A, Y_A) の地点に立っています。高橋君は、自分の立っている地点からのユークリッド距離が R 以下であるような打ち上げ地点の花火をすべて観覧することができます。

高橋君が観覧できる花火の満足度の合計を求めてください。

制約

  • 1 \leq N \leq 2 \times 10^5
  • -10^9 \leq X_A, Y_A \leq 10^9
  • 0 \leq R \leq 10^9
  • -10^9 \leq X_i, Y_i \leq 10^9 (1 \leq i \leq N)
  • 1 \leq P_i \leq 10^4 (1 \leq i \leq N)
  • 入力はすべて整数

入力

N X_A Y_A R
X_1 Y_1 P_1
X_2 Y_2 P_2
:
X_N Y_N P_N
  • 1 行目には、花火の個数を表す N 、高橋君の位置の X 座標を表す X_AY 座標を表す Y_A 、および観覧可能な範囲の半径を表す R がスペース区切りで与えられる。
  • 2 行目から N 行では、各花火の情報が与えられる。
  • 1 + i 行目では、 i 番目の花火の打ち上げ地点の X 座標を表す X_iY 座標を表す Y_i 、およびその花火の満足度を表す P_i がスペース区切りで与えられる。

出力

高橋君が得られる満足度の合計を 1 行に出力してください。


入力例 1

4 0 0 5
3 4 10
5 0 20
6 0 30
-1 -1 5

出力例 1

35

入力例 2

3 10 10 2
0 0 100
13 10 200
10 13 300

出力例 2

0

入力例 3

10 -2 3 10
-2 3 50
8 3 70
-12 3 80
-2 14 90
4 9 30
-9 -1 40
20 20 100
-5 -6 60
6 -3 25
-11 10 35

出力例 3

355

入力例 4

30 100000000 -100000000 500000000
100000000 -100000000 100
600000000 -100000000 200
-400000000 -100000000 300
100000000 400000000 400
100000000 -600000000 500
450000000 250000000 600
500000000 200000000 700
700000000 -100000000 800
100000000 500000000 900
-100000000 -300000000 1000
300000000 -500000000 1100
-200000000 200000000 1200
400000000 -400000000 1300
-300000000 100000000 1400
200000000 100000000 1500
-350000000 -250000000 1600
550000000 -250000000 1700
250000000 -550000000 1800
-100000000 -550000000 1900
-450000000 -100000000 2000
1000000000 1000000000 2100
-1000000000 -1000000000 2200
999999999 -999999999 2300
-999999999 999999999 2400
123456789 -123456789 2500
-123456789 123456789 2600
400000000 300000000 2700
-250000000 -450000000 2800
550000000 150000000 2900
-300000000 -400000000 3000

出力例 4

30900

入力例 5

1 1000000000 -1000000000 0
1000000000 -1000000000 10000

出力例 5

10000

Score : 266 pts

Problem Statement

Takahashi is at a fireworks festival venue. There are N firework launch points on a 2-dimensional plane, and the i-th firework is launched from coordinates (X_i, Y_i). If Takahashi can watch the i-th firework, he gains a satisfaction of P_i.

Takahashi is standing at the point with coordinates (X_A, Y_A). Takahashi can watch all fireworks whose launch points have a Euclidean distance of R or less from the point where he is standing.

Find the total satisfaction of the fireworks that Takahashi can watch.

Constraints

  • 1 \leq N \leq 2 \times 10^5
  • -10^9 \leq X_A, Y_A \leq 10^9
  • 0 \leq R \leq 10^9
  • -10^9 \leq X_i, Y_i \leq 10^9 (1 \leq i \leq N)
  • 1 \leq P_i \leq 10^4 (1 \leq i \leq N)
  • All inputs are integers

Input

N X_A Y_A R
X_1 Y_1 P_1
X_2 Y_2 P_2
:
X_N Y_N P_N
  • The first line contains N representing the number of fireworks, X_A representing the X coordinate of Takahashi's position, Y_A representing the Y coordinate, and R representing the radius of the viewable range, separated by spaces.
  • From the 2nd line to the next N lines, the information for each firework is given.
  • The (1 + i)-th line contains X_i representing the X coordinate of the i-th firework's launch point, Y_i representing the Y coordinate, and P_i representing the satisfaction of that firework, separated by spaces.

Output

Output the total satisfaction that Takahashi can obtain in a single line.


Sample Input 1

4 0 0 5
3 4 10
5 0 20
6 0 30
-1 -1 5

Sample Output 1

35

Sample Input 2

3 10 10 2
0 0 100
13 10 200
10 13 300

Sample Output 2

0

Sample Input 3

10 -2 3 10
-2 3 50
8 3 70
-12 3 80
-2 14 90
4 9 30
-9 -1 40
20 20 100
-5 -6 60
6 -3 25
-11 10 35

Sample Output 3

355

Sample Input 4

30 100000000 -100000000 500000000
100000000 -100000000 100
600000000 -100000000 200
-400000000 -100000000 300
100000000 400000000 400
100000000 -600000000 500
450000000 250000000 600
500000000 200000000 700
700000000 -100000000 800
100000000 500000000 900
-100000000 -300000000 1000
300000000 -500000000 1100
-200000000 200000000 1200
400000000 -400000000 1300
-300000000 100000000 1400
200000000 100000000 1500
-350000000 -250000000 1600
550000000 -250000000 1700
250000000 -550000000 1800
-100000000 -550000000 1900
-450000000 -100000000 2000
1000000000 1000000000 2100
-1000000000 -1000000000 2200
999999999 -999999999 2300
-999999999 999999999 2400
123456789 -123456789 2500
-123456789 123456789 2600
400000000 300000000 2700
-250000000 -450000000 2800
550000000 150000000 2900
-300000000 -400000000 3000

Sample Output 4

30900

Sample Input 5

1 1000000000 -1000000000 0
1000000000 -1000000000 10000

Sample Output 5

10000
B - Training Without Consecutive Repetitions

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 300

問題文

高橋君はジムでトレーニングを行います。このジムには N 種類のトレーニングマシンがあり、i 番目のマシンを 1 回使うと A_i の運動効果を得られます。この運動効果はマシンごとに固定されており、同じマシンを使うたびに同じ値が加算されます。

高橋君はちょうど K 回マシンを使う予定です。各回では N 種類のマシンの中から 1 つを選んで使いますが、直前に使ったマシンと同じものを続けて選ぶことはできません。この条件さえ満たせば、過去に使ったことのあるマシンを再び選ぶことは自由にできます。また、1 回目はどのマシンから始めても構いません。

高橋君が K 回のトレーニングで得られる運動効果の合計の最大値を求めてください。

制約

  • 2 \leq N \leq 10^5
  • 1 \leq K \leq 10^9
  • 1 \leq A_i \leq 10^9
  • 入力はすべて整数

入力

N K
A_1 A_2 \ldots A_N
  • 1 行目には、マシンの種類数を表す整数 N と、マシンを使う回数を表す整数 K が、スペース区切りで与えられる。
  • 2 行目には、各マシンを 1 回使うことで得られる運動効果を表す整数 A_1, A_2, \ldots, A_N が、スペース区切りで与えられる。

出力

高橋君が得られる運動効果の合計の最大値を 1 行で出力してください。


入力例 1

3 4
5 3 2

出力例 1

16

入力例 2

4 7
10 8 6 4

出力例 2

64

入力例 3

5 1000000000
1000000000 999999999 500000000 100 1

出力例 3

999999999500000000

Score : 300 pts

Problem Statement

Takahashi will train at a gym. The gym has N types of training machines, and using the i-th machine once provides an exercise effect of A_i. This exercise effect is fixed for each machine, and the same value is added each time the same machine is used.

Takahashi plans to use machines exactly K times. Each time, he chooses one of the N types of machines to use, but he cannot choose the same machine that was used immediately before. As long as this condition is satisfied, he is free to choose a machine that has been used in the past. Also, he may start with any machine on the first use.

Find the maximum total exercise effect that Takahashi can obtain from K training sessions.

Constraints

  • 2 \leq N \leq 10^5
  • 1 \leq K \leq 10^9
  • 1 \leq A_i \leq 10^9
  • All inputs are integers

Input

N K
A_1 A_2 \ldots A_N
  • The first line contains an integer N representing the number of types of machines and an integer K representing the number of times machines are used, separated by a space.
  • The second line contains integers A_1, A_2, \ldots, A_N representing the exercise effect obtained by using each machine once, separated by spaces.

Output

Print the maximum total exercise effect that Takahashi can obtain, in one line.


Sample Input 1

3 4
5 3 2

Sample Output 1

16

Sample Input 2

4 7
10 8 6 4

Sample Output 2

64

Sample Input 3

5 1000000000
1000000000 999999999 500000000 100 1

Sample Output 3

999999999500000000
C - Switching the Lights

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 366

問題文

高橋君は、大きなビルの照明管理システムを担当しています。このビルには N 個の部屋があり、各部屋には 1 から N までの番号が割り振られています。

各部屋の照明には「消灯」と「点灯」の 2 つの状態があります。初期状態では、すべての部屋の照明は消灯になっています。

高橋君は Q 回の操作を行います。i 回目 (1 \leq i \leq Q) の操作では、部屋番号が L_i 以上 R_i 以下であるすべての部屋に対して、照明の状態を反転させます。つまり、消灯ならば点灯に、点灯ならば消灯に切り替えます。

このビルには M 個の「会議室」があり、会議室の部屋番号は B_1, B_2, \ldots, B_M として与えられます(昇順とは限りません)。

すべての Q 回の操作が完了した後、会議室として指定された M 個の部屋のうち、照明が点灯している部屋の個数を求めてください。

制約

  • 1 \leq N \leq 10^9
  • 1 \leq M \leq 2 \times 10^5
  • 1 \leq Q \leq 2 \times 10^5
  • 1 \leq B_i \leq N (1 \leq i \leq M)
  • B_i はすべて異なる
  • 1 \leq L_i \leq R_i \leq N (1 \leq i \leq Q)
  • 入力はすべて整数

入力

N M Q
B_1 B_2 \ldots B_M
L_1 R_1
L_2 R_2
\vdots
L_Q R_Q
  • 1 行目には、部屋の総数を表す整数 N、会議室の個数を表す整数 M、操作の回数を表す整数 Q が、スペース区切りで与えられる。
  • 2 行目には、会議室の部屋番号を表す M 個の整数 B_1, B_2, \ldots, B_M が、スペース区切りで与えられる。
  • 3 行目以降の Q 行にわたって、各操作の情報が与えられる。
  • 2 + i 行目 (1 \leq i \leq Q) には、i 回目の操作で反転対象となる区間の始点 L_i と終点 R_i が、スペース区切りで与えられる。

出力

すべての操作が完了した後、会議室として指定された部屋のうち照明が点灯している部屋の個数を 1 行で出力してください。


入力例 1

10 3 2
2 5 8
1 6
4 9

出力例 1

2

入力例 2

20 5 4
3 7 12 15 18
1 10
5 15
8 12
3 7

出力例 2

2

入力例 3

1000000000 10 8
1 100 999999999 500000000 250000000 750000000 123456789 987654321 42 1000000000
1 500000000
250000000 750000000
100 123456789
42 42
500000000 1000000000
1 100
987654321 999999999
42 100

出力例 3

2

Score : 366 pts

Problem Statement

Takahashi is in charge of the lighting management system for a large building. The building has N rooms, and each room is assigned a number from 1 to N.

The lighting in each room has two states: "off" and "on". Initially, the lights in all rooms are off.

Takahashi performs Q operations. In the i-th operation (1 \leq i \leq Q), he toggles the lighting state of all rooms whose room numbers are between L_i and R_i, inclusive. That is, if a light is off, it is switched on, and if it is on, it is switched off.

The building has M "meeting rooms," and their room numbers are given as B_1, B_2, \ldots, B_M (not necessarily in ascending order).

After all Q operations have been completed, find the number of rooms among the M designated meeting rooms whose lights are on.

Constraints

  • 1 \leq N \leq 10^9
  • 1 \leq M \leq 2 \times 10^5
  • 1 \leq Q \leq 2 \times 10^5
  • 1 \leq B_i \leq N (1 \leq i \leq M)
  • All B_i are distinct
  • 1 \leq L_i \leq R_i \leq N (1 \leq i \leq Q)
  • All input values are integers

Input

N M Q
B_1 B_2 \ldots B_M
L_1 R_1
L_2 R_2
\vdots
L_Q R_Q
  • The first line contains three space-separated integers: N representing the total number of rooms, M representing the number of meeting rooms, and Q representing the number of operations.
  • The second line contains M space-separated integers B_1, B_2, \ldots, B_M representing the room numbers of the meeting rooms.
  • The following Q lines provide the information for each operation.
  • The (2 + i)-th line (1 \leq i \leq Q) contains two space-separated integers: the start L_i and end R_i of the interval to be toggled in the i-th operation.

Output

Print on a single line the number of meeting rooms whose lights are on after all operations have been completed.


Sample Input 1

10 3 2
2 5 8
1 6
4 9

Sample Output 1

2

Sample Input 2

20 5 4
3 7 12 15 18
1 10
5 15
8 12
3 7

Sample Output 2

2

Sample Input 3

1000000000 10 8
1 100 999999999 500000000 250000000 750000000 123456789 987654321 42 1000000000
1 500000000
250000000 750000000
100 123456789
42 42
500000000 1000000000
1 100
987654321 999999999
42 100

Sample Output 3

2
D - Shortest Delivery Route

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 400

問題文

高橋君は、ある都市で配達員として働いています。この都市には N 個の地点があり、各地点には 1 から N までの番号が付けられています。

都市には M 本の道路があり、各道路は2つの地点を双方向に結んでいます。i 番目の道路 (1 \leq i \leq M) は地点 A_i と地点 B_i を結んでおり、この道路を通るのに C_i 分かかります。同じ2地点間を結ぶ道路が複数存在することもあります。

高橋君は、配達センターがある地点 1 から出発し、道路を通って届け先である地点 N まで荷物を届けます。地点 1 から地点 N へ至る経路とは、地点の列 v_0 = 1, v_1, v_2, \ldots, v_k = N (k \geq 1) であって、各 j (0 \leq j \leq k-1) について地点 v_{j} と地点 v_{j+1} を結ぶ道路が少なくとも1本存在するようなものを指します。同じ地点を複数回通ってもかまいません。

経路の所要時間は次のように定まります。各 j (0 \leq j \leq k-1) について、地点 v_j と地点 v_{j+1} を結ぶ道路の中から通る道路を1本選び、選んだ道路の所要時間の合計を経路の所要時間とします。

地点 1 から地点 N へ至る経路が存在する場合は、経路の所要時間(分)の最小値を出力してください。経路が存在しない場合は -1 を出力してください。

制約

  • 2 \leq N \leq 10^5
  • 0 \leq M \leq 2 \times 10^5
  • 1 \leq A_i \leq N
  • 1 \leq B_i \leq N
  • A_i \neq B_i(自己ループはない)
  • 1 \leq C_i \leq 10^9
  • 入力はすべて整数

入力

N M
A_1 B_1 C_1
A_2 B_2 C_2
\vdots
A_M B_M C_M
  • 1 行目には、地点の個数 N と道路の本数 M が、スペース区切りで与えられる。
  • 続く M 行の i 番目 (1 \leq i \leq M) には、i 番目の道路が結ぶ2つの地点の番号 A_i, B_i と、その道路の所要時間(分) C_i が、スペース区切りで与えられる。

出力

地点 1 から地点 N へ至る経路の所要時間の最小値を1行に出力してください。経路が存在しない場合は -1 を出力してください。


入力例 1

4 4
1 2 3
2 4 5
1 3 2
3 4 7

出力例 1

8

入力例 2

3 1
1 2 10

出力例 2

-1

入力例 3

6 9
1 2 7
1 3 9
1 5 14
2 3 10
2 4 15
3 4 11
3 5 2
4 6 6
5 6 9

出力例 3

20

Score : 400 pts

Problem Statement

Takahashi works as a delivery person in a city. The city has N locations, each numbered from 1 to N.

The city has M roads, each connecting two locations bidirectionally. The i-th road (1 \leq i \leq M) connects location A_i and location B_i, and it takes C_i minutes to travel along this road. There may be multiple roads connecting the same pair of locations.

Takahashi starts from location 1, where the delivery center is, and delivers a package to location N by traveling along roads. A path from location 1 to location N is a sequence of locations v_0 = 1, v_1, v_2, \ldots, v_k = N (k \geq 1) such that for each j (0 \leq j \leq k-1), there exists at least one road connecting location v_{j} and location v_{j+1}. The same location may be visited multiple times.

The travel time of a path is determined as follows. For each j (0 \leq j \leq k-1), one road is chosen from among the roads connecting location v_j and location v_{j+1}, and the total of the travel times of the chosen roads is the travel time of the path.

If a path from location 1 to location N exists, output the minimum travel time (in minutes). If no path exists, output -1.

Constraints

  • 2 \leq N \leq 10^5
  • 0 \leq M \leq 2 \times 10^5
  • 1 \leq A_i \leq N
  • 1 \leq B_i \leq N
  • A_i \neq B_i (no self-loops)
  • 1 \leq C_i \leq 10^9
  • All inputs are integers

Input

N M
A_1 B_1 C_1
A_2 B_2 C_2
\vdots
A_M B_M C_M
  • The first line contains the number of locations N and the number of roads M, separated by a space.
  • The i-th (1 \leq i \leq M) of the following M lines contains the numbers of the two locations A_i, B_i connected by the i-th road and the travel time (in minutes) C_i of that road, separated by spaces.

Output

Output the minimum travel time of a path from location 1 to location N on a single line. If no path exists, output -1.


Sample Input 1

4 4
1 2 3
2 4 5
1 3 2
3 4 7

Sample Output 1

8

Sample Input 2

3 1
1 2 10

Sample Output 2

-1

Sample Input 3

6 9
1 2 7
1 3 9
1 5 14
2 3 10
2 4 15
3 4 11
3 5 2
4 6 6
5 6 9

Sample Output 3

20
E - Dance Synchronization

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 433

問題文

高橋君と青木君は、それぞれ左右のステップからなるダンスの振り付けを持っています。高橋君の振り付けは文字列 s 、青木君の振り付けは文字列 t で表され、各文字は 0(左ステップ)または 1(右ステップ)です。どちらの振り付けにも、同じステップが 3 回連続する箇所はありません。

本番前のリハーサルで、高橋君は高々 K 回、次の修正を行うことができます。

  • s または t のある位置を 1 つ選び、そのステップを逆のステップに変更する。
  • ただし、変更後、その位置のステップは、同じ振り付け内で隣り合うすべてのステップと異なっていなければならない。

リハーサル後、高橋君は s のステップと t のステップをいくつかペアにして「シンクロポイント」を作ります。ペアリングは次の条件をすべて満たす必要があります。

  • 各ペアは、 s のある位置 it のある位置 j からなる。
  • ペアにできるのは、 s_i = t_j である位置同士だけである。
  • s の各位置、 t の各位置は、それぞれ高々 1 つのペアにしか使えない。
  • ペア同士は交差してはならない。すなわち、ペア (i, j)(i', j') について、 i < i' ならば j < j' でなければならない。

修正とペアリングを適切に行ったとき、作ることができるペアの個数の最大値を求めてください。

制約

  • 1 \leq |s| \leq 2 \times 10^5
  • 1 \leq |t| \leq 2 \times 10^5
  • |s| \times |t| \leq 2 \times 10^6
  • s01 のみからなる文字列である。
  • t01 のみからなる文字列である。
  • s には同じ文字が 3 回以上連続する箇所がない。
  • t には同じ文字が 3 回以上連続する箇所がない。
  • 0 \leq K \leq |s| + |t|
  • K は整数である。

入力

s
t
K
  • 1 行目には、 01 からなる文字列 s が与えられる。
  • 2 行目には、 01 からなる文字列 t が与えられる。
  • 3 行目には、修正を行える回数の上限を表す整数 K が与えられる。

出力

作ることができるペアの個数の最大値を整数で出力せよ。


入力例 1

0101
0011
1

出力例 1

3

入力例 2

01
10
0

出力例 2

1

入力例 3

010110100110110010101101001011
1010010110100110101100101101
5

出力例 3

24

入力例 4

001011001011001011001011001011001011001011001011001011001011001011001011001011001011001011001011001011001011001011001011
110100110100110100110100110100110100110100110100110100110100110100110100110100110100110100110100110100110100110100110100
40

出力例 4

100

入力例 5

0
1
2

出力例 5

1

Score : 433 pts

Problem Statement

Takahashi and Aoki each have a dance choreography consisting of left and right steps. Takahashi's choreography is represented by string s, and Aoki's choreography is represented by string t, where each character is 0 (left step) or 1 (right step). Neither choreography contains three consecutive occurrences of the same step.

During rehearsal before the performance, Takahashi can perform the following modification at most K times:

  • Choose one position in s or t, and change that step to the opposite step.
  • However, after the change, the step at that position must differ from all adjacent steps within the same choreography.

After rehearsal, Takahashi pairs up some steps from s and t to create "synchro points." The pairing must satisfy all of the following conditions:

  • Each pair consists of a position i in s and a position j in t.
  • Only positions where s_i = t_j can be paired.
  • Each position in s and each position in t can be used in at most one pair.
  • Pairs must not cross each other. That is, for pairs (i, j) and (i', j'), if i < i' then j < j' must hold.

Determine the maximum number of pairs that can be made by performing modifications and pairing optimally.

Constraints

  • 1 \leq |s| \leq 2 \times 10^5
  • 1 \leq |t| \leq 2 \times 10^5
  • |s| \times |t| \leq 2 \times 10^6
  • s is a string consisting only of 0 and 1.
  • t is a string consisting only of 0 and 1.
  • s does not contain three or more consecutive occurrences of the same character.
  • t does not contain three or more consecutive occurrences of the same character.
  • 0 \leq K \leq |s| + |t|
  • K is an integer.

Input

s
t
K
  • The first line contains the string s consisting of 0 and 1.
  • The second line contains the string t consisting of 0 and 1.
  • The third line contains an integer K, representing the upper limit on the number of modifications that can be made.

Output

Output the maximum number of pairs that can be made, as an integer.


Sample Input 1

0101
0011
1

Sample Output 1

3

Sample Input 2

01
10
0

Sample Output 2

1

Sample Input 3

010110100110110010101101001011
1010010110100110101100101101
5

Sample Output 3

24

Sample Input 4

001011001011001011001011001011001011001011001011001011001011001011001011001011001011001011001011001011001011001011001011
110100110100110100110100110100110100110100110100110100110100110100110100110100110100110100110100110100110100110100110100
40

Sample Output 4

100

Sample Input 5

0
1
2

Sample Output 5

1