A - POSTal Code

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 9

注意

この問題に対する言及は、2021/4/24 18:00 JST まで禁止されています。言及がなされた場合、賠償が請求される可能性があります。 試験後に総合得点や認定級を公表するのは構いませんが、どの問題が解けたかなどの情報は発信しないようにお願いします。

問題文

数字と - のみからなる 8 文字の文字列 S が与えられます。

文字列 S が以下の条件を満たすかどうか判定して下さい。

  • 4 文字目は - である。
  • 4 文字目以外の全ての文字は数字である。

制約

  • S は(半角)数字と - のみからなる 8 文字の文字列

入力

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

S

出力

文字列 S が問題文の条件を満たすならば Yes を、満たさないならば No を出力せよ。


入力例 1

160-0022

出力例 1

Yes

入力例 2

1600022-

出力例 2

No

Score : 9 points

Warning

Do not make any mention of this problem until April 24, 2021, 6:00 p.m. JST. In case of violation, compensation may be demanded. After the examination, you can reveal your total score and grade to others, but nothing more (for example, which problems you solved).

Problem Statement

Given is a string S of length 8 consisting of digits and -s (hyphens).

Determine whether S satisfies the following conditions:

  • the fourth character is -;
  • the other characters are all digits.

Constraints

  • S is a string of length 8 consisting of digits and -s.

Input

Input is given from Standard Input in the following format:

S

Output

Print Yes if S satisfies the conditions in Problem Statement; print No otherwise.


Sample Input 1

160-0022

Sample Output 1

Yes

Sample Input 2

1600022-

Sample Output 2

No
B - PASTal Code

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 8

注意

この問題に対する言及は、2021/4/24 18:00 JST まで禁止されています。言及がなされた場合、賠償が請求される可能性があります。 試験後に総合得点や認定級を公表するのは構いませんが、どの問題が解けたかなどの情報は発信しないようにお願いします。

問題文

高橋くんは、以下の条件を満たす文字列 S を入力しました。

  • Spast または post を合計 1 つ以上連結した文字列
  • 連結された文字列のうち、 post は高々 1

あなたへの課題は、連結された文字列のうち、何番目が post かを求めることです。

制約

  • |S| \le 1000
  • Spast または post を合計 1 つ以上連結した文字列
  • 連結された文字列のうち、 post は高々 1

入力

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

S

出力

もし post1 つ連結されていれば、それがはじめから何番目に連結された文字列かを 1 つの正整数として出力せよ。 post1 つも連結されていなければ、 none と出力せよ。


入力例 1

pastpastpostpast

出力例 1

3

S= pastpastpostpast です。 3 番目に連結された文字列が post です。


入力例 2

pastpastpast

出力例 2

none

S= pastpastpast です。 post1 つも連結されていません。

Score : 8 points

Warning

Do not make any mention of this problem until April 24, 2021, 6:00 p.m. JST. In case of violation, compensation may be demanded. After the examination, you can reveal your total score and grade to others, but nothing more (for example, which problems you solved).

Problem Statement

Takahashi typed a string S satisfying the following conditions:

  • S is a concatenation of one or more strings, each of which is past or post;
  • at most one of the concatenated strings is post.

Your task is to find out which of the concatenated strings is post.

Constraints

  • |S| \le 1000
  • S is a concatenation of one or more strings, each of which is past or post.
  • At most one of the concatenated strings is post.

Input

Input is given from Standard Input in the following format:

S

Output

If one of the strings concatenated is post, print a positive integer x such that post is the x-th string from the left. Otherwise, print none.


Sample Input 1

pastpastpostpast

Sample Output 1

3

We have S= pastpastpostpast, where the third string concatenated is post.


Sample Input 2

pastpastpast

Sample Output 2

none

We have S= pastpastpast, where none of the strings concatenated is post.

C - Buying a Cellphone

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 8

注意

この問題に対する言及は、2021/4/24 18:00 JST まで禁止されています。言及がなされた場合、賠償が請求される可能性があります。 試験後に総合得点や認定級を公表するのは構いませんが、どの問題が解けたかなどの情報は発信しないようにお願いします。

問題文

ある会社は N 種類の携帯電話を販売しています。これらの機種は機種 1 から機種 N まで番号づけられています。
また、携帯電話の周波数帯が M 個あり、周波数帯 1 から周波数帯 M まで番号づけられています。
機種 i の携帯電話は周波数帯 A_{i, 1}, A_{i, 2}, A_{i, 3}, \dots, A_{i, K_i}K_i 個の周波数帯のみに対応しています。
あなたはこの会社の携帯電話のうち以下の条件を満たすものから 1 つ選んで買うことに決めました。

  • 周波数帯 B_1, B_2, B_3, \dots, B_PP 個の周波数帯のうち Q 個以上に対応している

あなたの買う携帯電話の候補となる機種の数を出力してください。

制約

  • 1 \le N \le 50
  • 1 \le M \le 50
  • 1 \le K_i \le M
  • 1 \le A_{i, j} \le M
  • j \neq k ならば A_{i, j} \neq A_{i, k}
  • 1 \le Q \le P \le M
  • 1 \le B_i \le M
  • i \neq j ならば B_i \neq B_j
  • 入力は全て整数

入力

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

N M
K_1 A_{1, 1} A_{1, 2} A_{1, 3} \dots A_{1, K_1}
K_2 A_{2, 1} A_{2, 2} A_{2, 3} \dots A_{2, K_2}
K_3 A_{3, 1} A_{3, 2} A_{3, 3} \dots A_{3, K_3}
\hspace{67pt} \vdots
K_N A_{N, 1} A_{N, 2} A_{N, 3} \dots A_{N, K_N}
P Q
B_1 B_2 B_3 \dots B_P

出力

答えを出力せよ。


入力例 1

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

出力例 1

3

それぞれの機種が対応している周波数は以下の通りです。

  • 機種 1 : 周波数帯 4
  • 機種 2 : 周波数帯 1, 3
  • 機種 3 : 周波数帯 1, 2, 3
  • 機種 4 : 周波数帯 2, 4

周波数帯 2, 4 のうち 1 個以上に対応している機種は、機種 1, 3, 4 です。


入力例 2

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

出力例 2

3

機種 1, 3, 4 が条件を満たします。


入力例 3

1 2
1 1
1 1
2

出力例 3

0

1 つも条件を満たす機種がない場合もあります。

Score : 8 points

Warning

Do not make any mention of this problem until April 24, 2021, 6:00 p.m. JST. In case of violation, compensation may be demanded. After the examination, you can reveal your total score and grade to others, but nothing more (for example, which problems you solved).

Problem Statement

A company sells N types of cellphones, called Type 1 through Type N.
Also, there are M frequency bands used for cellular networks, called Band 1 through Band M.
A cellphone of Type i can only use K_i of those bands: Bands A_{i, 1}, A_{i, 2}, A_{i, 3}, \dots, A_{i, K_i}.
You will buy a cellphone by this company that satisfies the following condition:

  • The cellphone can use Q or more of the following P bands: Bands B_1, B_2, B_3, \dots, B_P.

Print the number of types of such cellphones.

Constraints

  • 1 \le N \le 50
  • 1 \le M \le 50
  • 1 \le K_i \le M
  • 1 \le A_{i, j} \le M
  • A_{i, j} \neq A_{i, k} for j \neq k
  • 1 \le Q \le P \le M
  • 1 \le B_i \le M
  • B_i \neq B_j for i \neq j
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N M
K_1 A_{1, 1} A_{1, 2} A_{1, 3} \dots A_{1, K_1}
K_2 A_{2, 1} A_{2, 2} A_{2, 3} \dots A_{2, K_2}
K_3 A_{3, 1} A_{3, 2} A_{3, 3} \dots A_{3, K_3}
\hspace{67pt} \vdots
K_N A_{N, 1} A_{N, 2} A_{N, 3} \dots A_{N, K_N}
P Q
B_1 B_2 B_3 \dots B_P

Output

Print the answer.


Sample Input 1

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

Sample Output 1

3

Each type of cellphone can use the following bands:

  • Type 1: Bands 4
  • Type 2: Bands 1, 3
  • Type 3: Bands 1, 2, 3
  • Type 4: Bands 2, 4

The types that can use one or more of Bands 2, 4 are Types 1, 3, 4.


Sample Input 2

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

Sample Output 2

3

Types 1, 3, 4 are desirable.


Sample Input 3

1 2
1 1
1 1
2

Sample Output 3

0

There can be no desirable types.

D - K Integers Summations

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 7

注意

この問題に対する言及は、2021/4/24 18:00 JST まで禁止されています。言及がなされた場合、賠償が請求される可能性があります。 試験後に総合得点や認定級を公表するのは構いませんが、どの問題が解けたかなどの情報は発信しないようにお願いします。

問題文

長さ N の数列 A=(A_1,A_2,...,A_N) と、1 以上 N 以下の整数 K が与えられます。

1 以上 N-K+1 以下の全ての整数 x について、以下の値を求めてください。

  • \displaystyle \sum_{i=x}^{x+K-1} A_i 、すなわち、 A_x から A_{x+K-1} までの K 項の総和

制約

  • 入力はすべて整数
  • 1 \le K \le N \le 5 \times 10^5
  • |A_i| \le 10^9 (1 \le i \le N)

入力

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

N K
A_1 A_2 \cdots A_N

出力

N-K+1 行出力せよ。

i 行目には、x=i とした場合の値を出力せよ。

出力する行数が大きくなる場合があるので、注意せよ。


入力例 1

6 3
2 0 2 -1 0 -4

出力例 1

4
1
1
-5
  • x=1 としたとき、求める値は A_1 + A_2 + A_3 = 4 です。
  • x=2 としたとき、求める値は A_2 + A_3 + A_4 = 1 です。
  • x=3 としたとき、求める値は A_3 + A_4 + A_5 = 1 です。
  • x=4 としたとき、求める値は A_4 + A_5 + A_6 = -5 です。

Score : 7 points

Warning

Do not make any mention of this problem until April 24, 2021, 6:00 p.m. JST. In case of violation, compensation may be demanded. After the examination, you can reveal your total score and grade to others, but nothing more (for example, which problems you solved).

Problem Statement

Given are a length-N sequence A=(A_1,A_2,...,A_N) and an integer K between 1 and N (inclusive).

For every integer x from 1 through N-K+1, find the following:

  • \displaystyle \sum_{i=x}^{x+K-1} A_i, that is, the sum of K elements from A_x through A_{x+K-1}.

Constraints

  • All values in input are integers.
  • 1 \le K \le N \le 5 \times 10^5
  • |A_i| \le 10^9 (1 \le i \le N)

Input

Input is given from Standard Input in the following format:

N K
A_1 A_2 \cdots A_N

Output

Print N-K+1 lines.

The i-th line should contain the sum for x=i.

Note that you may have to print many lines.


Sample Input 1

6 3
2 0 2 -1 0 -4

Sample Output 1

4
1
1
-5
  • The sum for x=1 is A_1 + A_2 + A_3 = 4.
  • The sum for x=2 is A_2 + A_3 + A_4 = 1.
  • The sum for x=3 is A_3 + A_4 + A_5 = 1.
  • The sum for x=4 is A_4 + A_5 + A_6 = -5.
E - Third from Front

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 7

注意

この問題に対する言及は、2021/4/24 18:00 JST まで禁止されています。言及がなされた場合、賠償が請求される可能性があります。 試験後に総合得点や認定級を公表するのは構いませんが、どの問題が解けたかなどの情報は発信しないようにお願いします。

問題文

数列 A があり、A は初め空です。 A, B, C, D, E, F, L, R からなる長さ N の文字列 S が与えられます。
Si 文字目を S_i と表すことにします。
i = 1, 2, 3, \dots, N のそれぞれについて、この順に以下の処理を行ってください。

  • S_iL のとき : A の先頭に i を挿入する。
  • S_iR のとき : A の末尾に i を挿入する。
  • S_iA のとき : A の長さが 0 以下なら ERROR と出力する。そうでなければ、A の前から 1 番目の数を出力し削除する。
  • S_iB のとき : A の長さが 1 以下なら ERROR と出力する。そうでなければ、A の前から 2 番目の数を出力し削除する。
  • S_iC のとき : A の長さが 2 以下なら ERROR と出力する。そうでなければ、A の前から 3 番目の数を出力し削除する。
  • S_iD のとき : A の長さが 0 以下なら ERROR と出力する。そうでなければ、A の後ろから 1 番目の数を出力し削除する。
  • S_iE のとき : A の長さが 1 以下なら ERROR と出力する。そうでなければ、A の後ろから 2 番目の数を出力し削除する。
  • S_iF のとき : A の長さが 2 以下なら ERROR と出力する。そうでなければ、A の後ろから 3 番目の数を出力し削除する。

制約

  • 1 ≤ N ≤ 3 \times 10^5
  • SA, B, C, D, E, F, L, R からなる長さ N の文字列

入力

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

N
S

出力

問題文の指示に従って、改行区切りで出力せよ。


入力例 1

11
LLRLRCDEFBA

出力例 1

1
5
2
ERROR
3
4

以下のように処理されます。

  • S_1L なので、1 を先頭に挿入する。A = (1) となる。
  • S_2L なので、2 を先頭に挿入する。A = (2, 1) となる。
  • S_3R なので、3 を末尾に挿入する。A = (2, 1, 3) となる。
  • S_4L なので、4 を先頭に挿入する。A = (4, 2, 1, 3) となる。
  • S_5R なので、5 を末尾に挿入する。A = (4, 2, 1, 3, 5) となる。
  • S_6C なので、前から 3 番目の数 1 を出力し削除する。A = (4, 2, 3, 5) となる。
  • S_7D なので、後ろから 1 番目の数 5 を出力し削除する。A = (4, 2, 3) となる。
  • S_8E なので、後ろから 2 番目の数 2 を出力し削除する。A = (4, 3) となる。
  • S_9F であるが、長さが 2 以下なので、ERROR を出力する。
  • S_{10}B なので、前から 2 番目の数 3 を出力し削除する。A = (4) となる。
  • S_{11}A なので、前から 1 番目の数 4 を出力し削除する。A = () となる。

入力例 2

36
RLLDBBDDLCLDFRLRRLRRFLRDRLALLELCAARF

出力例 2

1
2
ERROR
3
ERROR
ERROR
9
ERROR
17
23
26
20
28
31
29
19

Score : 7 points

Warning

Do not make any mention of this problem until April 24, 2021, 6:00 p.m. JST. In case of violation, compensation may be demanded. After the examination, you can reveal your total score and grade to others, but nothing more (for example, which problems you solved).

Problem Statement

We have a sequence A, which is initially empty. You are given a string S of length N consisting of A, B, C, D, E, F, L, and R.
Let S_i denotes the i-th character of S.
For each i = 1, 2, 3, \dots, N in this order, do as follows:

  • If S_i is L: insert i at the beginning of A.
  • If S_i is R: insert i at the end of A.
  • If S_i is A: if the length of A is less than 1, print ERROR; otherwise, print the first number from the beginning of A and delete it.
  • If S_i is B: if the length of A is less than 2, print ERROR; otherwise, print the second number from the beginning of A and delete it.
  • If S_i is C: if the length of A is less than 3, print ERROR; otherwise, print the third number from the beginning of A and delete it.
  • If S_i is D: if the length of A is less than 1, print ERROR; otherwise, print the first number from the end of A and delete it.
  • If S_i is C: if the length of A is less than 2, print ERROR; otherwise, print the second number from the end of A and delete it.
  • If S_i is C: if the length of A is less than 3, print ERROR; otherwise, print the third number from the end of A and delete it.

Constraints

  • 1 ≤ N ≤ 3 \times 10^5
  • S is a string of length N consisting of A, B, C, D, E, F, L, and R.

Input

Input is given from Standard Input in the following format:

N
S

Output

Print numbers as specified in Problem Statement, each in its own line.


Sample Input 1

11
LLRLRCDEFBA

Sample Output 1

1
5
2
ERROR
3
4

The process goes as follows:

  • S_1 is L, so we insert 1 at the beginning. A = (1) now.
  • S_2 is L, so we insert 2 at the beginning. A = (2, 1) now.
  • S_3 is R, so we insert 3 at the end. A = (2, 1, 3) now.
  • S_4 is L, so we insert 4 at the beginning. A = (4, 2, 1, 3) now.
  • S_5 is R, so we insert 5 at the beginning. A = (4, 2, 1, 3, 5) now.
  • S_6 is C, so we delete the third number from the beginning: 1. A = (4, 2, 3, 5) now.
  • S_7 is D, so we delete the first number from the end: 5. A = (4, 2, 3) now.
  • S_8 is E, so we delete the second number from the end: 2. A = (4, 3) now.
  • S_9 is F, but we have less than 3 numbers, so we print ERROR.
  • S_{10} is B, so we delete the second number from the beginning: 3. A = (4) now.
  • S_{11} is A, so we delete the first number from the beginning: 4. A = () now.

Sample Input 2

36
RLLDBBDDLCLDFRLRRLRRFLRDRLALLELCAARF

Sample Output 2

1
2
ERROR
3
ERROR
ERROR
9
ERROR
17
23
26
20
28
31
29
19
F - Safety System

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 7

注意

この問題に対する言及は、2021/4/24 18:00 JST まで禁止されています。言及がなされた場合、賠償が請求される可能性があります。 試験後に総合得点や認定級を公表するのは構いませんが、どの問題が解けたかなどの情報は発信しないようにお願いします。

問題文

あなたは画期的なコンピュータを発明し、これを使って N 個のタスクを処理しようとしています。
i 番目のタスクはこのコンピュータで A_i 秒で処理されます。処理時間とは別に各タスクには「負荷」という数値が定まっており、i 番目のタスクの負荷は B_i です。タスクは 1 個目から番号順に間隔を開けず処理します。
このコンピュータは負荷 L 以上の処理が連続 T 秒間に達した瞬間、安全装置によって X 秒間だけ処理を停止した後、再開します。処理停止時にあるタスクの処理途中だった場合、そのタスクの初めに戻って再開します。
有限の時間で全てのタスクを処理し終わるかを判定し、処理し終わる場合は全部のタスクを終わらせるのにかかる秒数を求めてください。最後のタスクを終わらせた瞬間に安全装置が作動する場合、その安全装置による処理停止が終わる瞬間までの秒数を求めるものとします。

制約

  • 1 \le N \le 100
  • 1 \le L \le 1000
  • 1 \le T \le 1000
  • 1 \le X \le 1000
  • 1 \le A_i \le 1000
  • 1 \le B_i \le 1000
  • 入力は全て整数

入力

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

N L T X
A_1 B_1
A_2 B_2
A_3 B_3
\hspace{14pt} \vdots
A_N B_N

出力

有限の時間で全てのタスクを処理し終わらない場合 forever を出力せよ。
そうでない場合、全てのタスクを終わらせるのにかかる秒数を出力せよ。


入力例 1

4 10 3 5
2 15
2 10
2 20
2 5

出力例 1

20

1, 2 番目のタスクの負荷が両方 10 以上なので、1 番目のタスクを完了し 2 番目のタスクを 1 秒実行した瞬間、負荷 L 以上の処理が 3 秒に達しコンピュータは 5 秒停止します。
その後、2 番目のタスクの最初に戻って再開します。3 番目のタスクの負荷も 10 以上なので同様に 3 番目のタスクを 1 秒実行した瞬間に再び安全装置が作動して 5 秒停止します。
同様に再開時は 3 番目のタスクの初めからになり、4 番目のタスクは負荷が 10 未満なので、この後は 3, 4 番目のタスクに 2 秒ずつ使って全てのタスクを完了します。
1 回目の停止から再開した時点で開始から 8 秒、2 回目の停止からの再開時で 16 秒経っており、最終的に 20 秒で全てのタスクを処理し終わります。


入力例 2

1 1 1 1
100 100

出力例 2

forever

最初のタスクの途中で安全装置が作動して最初に戻る、を繰り返して永遠に終了しません。


入力例 3

4 10 5 10
3 5
5 20
3 10
2 10

出力例 3

33

2 番目のタスクが終了した瞬間に安全装置が 1 度作動します。停止したのはタスクの処理途中ではないので、再開時は 3 番目のタスクから処理を開始します。
そして、最後のタスクを処理し終わった瞬間に安全装置が再び作動します。
問題文の最後の文で注意されている通り、この場合安全装置による停止の時間も含めて計算します。


入力例 4

3 10 5 10
3 10
3 9
3 10

出力例 4

9

負荷 10 以上の仕事が 5 秒以上連続することはないので、安全装置が作動することはありません。

Score : 7 points

Warning

Do not make any mention of this problem until April 24, 2021, 6:00 p.m. JST. In case of violation, compensation may be demanded. After the examination, you can reveal your total score and grade to others, but nothing more (for example, which problems you solved).

Problem Statement

You have invented a new epoch-making computer, which you will use to process N tasks.
The computer takes A_i seconds to process the i-th task. Additionally, each task has a value called the load; the load of the i-th task is B_i. The computer will process the tasks in the given order without pause.
At the moment when the computer has processed tasks of load L or higher for T consecutive seconds, the safety system halts the processing for X seconds, and then the computer restarts processing. Here, if the computer was in the middle of processing a task when interrupted, the computer has to process that task again from the beginning.
Determine whether the computer completes all tasks in finite time, and find that time needed if it is finite. If the safety system activates at the moment when the final task is finished, include that halt in the answer.

Constraints

  • 1 \le N \le 100
  • 1 \le L \le 1000
  • 1 \le T \le 1000
  • 1 \le X \le 1000
  • 1 \le A_i \le 1000
  • 1 \le B_i \le 1000
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N L T X
A_1 B_1
A_2 B_2
A_3 B_3
\hspace{14pt} \vdots
A_N B_N

Output

If the computer does not complete all tasks in finite time, print forever.
Otherwise, print the number of seconds needed to complete all tasks.


Sample Input 1

4 10 3 5
2 15
2 10
2 20
2 5

Sample Output 1

20

Since the 1-st and 2-nd tasks both have loads 10 or higher, at the moment when the computer has processed the 2-nd for 1 second after finishing the 1-st, it has processed tasks of load L or higher for 3 seconds, so it halts for 5 seconds.
Then, the computer starts processing the 2-nd task again from the beginning. The 3-rd task also has a load not lower than 10, so at the moment when the computer has processed it for 1 second, the safety system activates again and makes the computer halt for 5 seconds.
Then, the computer starts processing the 3-nd task again from the beginning. The 4-th task has a load lower than 10, so now the computer takes 2 seconds for each of the 3-rd and 4-th tasks, and all tasks are done.
At the end of the 1-st halt, 8 seconds have passed; at the end of the 2-nd halt, 16 seconds have passed; at the end of processing all tasks, 20 seconds have passed.


Sample Input 2

1 1 1 1
100 100

Sample Output 2

forever

The safety system activates in the middle of processing the first task, making the computer start over, and it repeats forever.


Sample Input 3

4 10 5 10
3 5
5 20
3 10
2 10

Sample Output 3

33

At the moment when the 2-nd task is finished, the safety system activates once. Since the computer was not in the middle of processing a task when interrupted, it starts processing the 3-rd task after the halt.
Then, at the moment when the final task is finished, the safety system activates again.
As noted at the end of Problem Statement, we include this second halt in the answer.


Sample Input 4

3 10 5 10
3 10
3 9
3 10

Sample Output 4

9

There is no moment when tasks of loads 10 or higher continue for 5 or more consecutive seconds, so the safety system never activates.

G - One Step at a Time

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 6

注意

この問題に対する言及は、2021/4/24 18:00 JST まで禁止されています。言及がなされた場合、賠償が請求される可能性があります。 試験後に総合得点や認定級を公表するのは構いませんが、どの問題が解けたかなどの情報は発信しないようにお願いします。

問題文

ある国には都市 1 から都市 N までの N 個の都市と、道 1 から道 M までの M 本の道があります。
i は都市 A_i と都市 B_i を双方向に繋ぎ、C_i 単位時間で通行することができます。
現在都市 1 にいるあなたは Q 日間にわたる旅をします。開始から i 日目の昼には以下のどちらかの行動を行います。

  • 何もしない
  • 今いる都市に繋がっている道を 1 つ選び、その道の先の都市に移動する。このとき選ぶ道は X_i 単位時間以下で通行できるものでなければならない。

1 以上 Q 以下の各整数 i について、開始から i 日目の夕方にあなたがいる可能性のある都市の数を求めてください。
1 単位時間は 1 日の \frac{1}{10^{100}} より短いものとします。

制約

  • 2 \le N \le 2 \times 10^5
  • 1 \le M \le 2 \times 10^5
  • 1 \le Q \le 2 \times 10^5
  • 1 \le A_i < B_i \le N
  • i \neq j ならば (A_i, B_i) \neq (A_j, B_j)
  • 1 \le C_i \le 10^9
  • 1 \le X_i \le 10^9
  • 入力に含まれる値は全て整数

入力

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

N M Q
A_1 B_1 C_1
A_2 B_2 C_2
A_3 B_3 C_3
\hspace{25pt} \vdots
A_M B_M C_M
X_1 X_2 X_3 \dots X_Q

出力

Q 行出力せよ。 i 行目には、開始から i 日目の夕方にあなたがいる可能性のある都市の数を出力せよ。


入力例 1

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

出力例 1

1
2
3
3
  • 1 日目
    昼には、都市 1 に繋がっている道で 2 単位時間以下で通れる道はないので、都市 1 にとどまるしかありません。
    夕方にあなたがいる可能性のある都市は、都市 11 つだけです。
  • 2 日目
    昼には、道 2 のみを使うことができ、都市 3 に移動することができます。都市 1 にとどまることもできます。
    夕方にあなたがいる可能性のある都市は、都市 1, 32 つです。
  • 3 日目
    昼には、(その道に繋がっている都市にいるならば) 道 2, 3 を使うことができます。前日に都市 3 に移動していれば、この昼に道 3 を使って都市 2 に辿りつけます。
    夕方にあなたがいる可能性のある都市は、都市 1, 2, 33 つです。
  • 4 日目
    昼には全ての道が使えますが、夕方にあなたがいる可能性のある都市は変わらず都市 1, 2, 33 つです。

入力例 2

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

出力例 2

2
3
4
4
5

1 日に複数本の道を使うことはできないことに注意してください。


入力例 3

4 1 3
1 4 100
50 100 1000000000

出力例 3

1
2
2

道を使って辿り着けない都市が存在するかもしれません。

Score : 6 points

Warning

Do not make any mention of this problem until April 24, 2021, 6:00 p.m. JST. In case of violation, compensation may be demanded. After the examination, you can reveal your total score and grade to others, but nothing more (for example, which problems you solved).

Problem Statement

In some country, there are N cities called City 1 through City N and M roads called Road 1 through Road N.
Road i connects City A_i and City B_i bidirectionally, and it takes C_i units of time to traverse it.
In City 1, you will start a Q-day trip. On the i-th day, you do one of the following actions:

  • Do nothing.
  • Choose one of the roads that go from the city you are in, and traverse that road to reach the city at the other end. Here, it must take at most X_i units of time to traverse the chosen road.

For each integer i from 1 through Q, find the number of cities that you are potentially in at the i-th night.
Assume that one unit of time is shorter than \frac{1}{10^{100}} days.

Constraints

  • 2 \le N \le 2 \times 10^5
  • 1 \le M \le 2 \times 10^5
  • 1 \le Q \le 2 \times 10^5
  • 1 \le A_i < B_i \le N
  • (A_i, B_i) \neq (A_j, B_j) for i \neq j
  • 1 \le C_i \le 10^9
  • 1 \le X_i \le 10^9
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N M Q
A_1 B_1 C_1
A_2 B_2 C_2
A_3 B_3 C_3
\hspace{25pt} \vdots
A_M B_M C_M
X_1 X_2 X_3 \dots X_Q

Output

Print Q lines. The i-th line should contain the number of cities that you are potentially in at the i-th night.


Sample Input 1

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

Sample Output 1

1
2
3
3
  • Day 1:
    There are no roads that go from City 1 and take at most 2 units of time to traverse, so you have to stay there.
    There is just one city that you are potentially in at night: City 1.
  • Day 2:
    Only Road 2 is available, which takes you to City 3. You can also choose to stay at City 1.
    There are two cities that you are potentially in at night: City 1 and 3.
  • Day 3:
    Roads 2 and 3 are available (if you are in a city they go from). If you moved to City 3 the previous day, you can use Road 3 to reach City 2 this day.
    There are three cities that you are potentially in at night: City 1, 2, and 3.
  • Day 4:
    All roads are available, but there are still three cities that you are potentially in at night: City 1, 2, and 3.

Sample Input 2

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

Sample Output 2

2
3
4
4
5

Note that you cannot traverse multiple roads in a day.


Sample Input 3

4 1 3
1 4 100
50 100 1000000000

Sample Output 3

1
2
2

There may be cities unreachable by roads.

H - Can Can Mart

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 6

注意

この問題に対する言及は、2021/4/24 18:00 JST まで禁止されています。言及がなされた場合、賠償が請求される可能性があります。 試験後に総合得点や認定級を公表するのは構いませんが、どの問題が解けたかなどの情報は発信しないようにお願いします。

問題文

コンビニ「カンカンマート」では N 個の缶詰が売られています。
i 番目の缶詰は P_i 円で売られており、 T_i = 1 であればその缶詰を開封するのに缶切りが必要で、 T_i = 0 であればその缶詰を開封するのに缶切りは不要です。同じ缶詰を複数個購入することはできません。
缶切りは、1Q 円で何個でも購入できます。1 つの缶切りで K 個の缶詰を開封すると、その缶切りは壊れて使えなくなってしまいます。
あなたは、N 個の缶詰のうち M 個を選び、それらを開けるのに必要な缶切りとともに購入します。このとき必要な最小の合計金額を求めてください。

制約

  • 入力はすべて整数
  • 1 \le M \le N \le 10^5
  • 1 \le K \le N
  • 1 \le Q \le 10^9
  • 1 \le P_i \le 10^9, T_i \in \{0,1\} (1 \le i \le N)

入力

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

N M K Q
P_1 T_1
P_2 T_2
\vdots
P_N T_N

出力

必要な最小の合計金額を出力せよ。


入力例 1

6 3 2 10
15 1
25 0
20 0
10 1
5 1
20 0

出力例 1

45

例えば、 3,4,5 番目の缶詰と、缶切りを 1 つ買うことによって必要な最小金額である 45 円を達成できます。これより安いような買い方は存在しないことが示せます。


入力例 2

5 2 5 40
120 0
1 1
90 0
10 0
50 0

出力例 2

51

缶切りを使って開ける缶詰が 1 つで、 K=5 であっても、缶切りを 1 つ購入する必要があります。


入力例 3

16 9 1 631593942
758234071 1
872232933 0
928146137 0
141777768 0
339097211 1
590423762 1
656886697 1
164443392 0
181259343 0
509224290 0
973377384 0
934014075 1
167877698 1
549037938 0
94228809 1
898548470 0

出力例 3

4841818525

答えは非常に大きくなる場合があります。

Score : 6 points

Warning

Do not make any mention of this problem until April 24, 2021, 6:00 p.m. JST. In case of violation, compensation may be demanded. After the examination, you can reveal your total score and grade to others, but nothing more (for example, which problems you solved).

Problem Statement

A convenience store Can-Can-Mart sells N cans.
The i-th can is sold for P_i yen, and you need a can opener to open it if T_i = 1; you can open it without an opener if T_i = 0.
You can buy any number of openers for Q yen each. An opener can be used to open K cans, after which it gets broken and unusable.
You will choose M of the N cans and buy them, along with openers needed to open them. Find the minimum total amount of money needed for this.

Constraints

  • All values in input are integers.
  • 1 \le M \le N \le 10^5
  • 1 \le K \le N
  • 1 \le Q \le 10^9
  • 1 \le P_i \le 10^9, T_i \in \{0,1\} (1 \le i \le N)

Input

Input is given from Standard Input in the following format:

N M K Q
P_1 T_1
P_2 T_2
\vdots
P_N T_N

Output

Print the minimum total amount of money needed, as an integer.


Sample Input 1

6 3 2 10
15 1
25 0
20 0
10 1
5 1
20 0

Sample Output 1

45

For example, you can buy the 3-rd, 4-th, 5-th cans, and one opener to make the total cost 45 yen. We can show that there is no way that costs less.


Sample Input 2

5 2 5 40
120 0
1 1
90 0
10 0
50 0

Sample Output 2

51

Even if we have just one can that needs an opener and K = 5, we have to buy one opener.


Sample Input 3

16 9 1 631593942
758234071 1
872232933 0
928146137 0
141777768 0
339097211 1
590423762 1
656886697 1
164443392 0
181259343 0
509224290 0
973377384 0
934014075 1
167877698 1
549037938 0
94228809 1
898548470 0

Sample Output 3

4841818525

The answer can be enormous.

I - PAST to Fishing

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 6

注意

この問題に対する言及は、2021/4/24 18:00 JST まで禁止されています。言及がなされた場合、賠償が請求される可能性があります。 試験後に総合得点や認定級を公表するのは構いませんが、どの問題が解けたかなどの情報は発信しないようにお願いします。

問題文

PAST島には、地図上で縦 H 行、横 W 列の区画に分かれた釣り堀があります。上から i 番目、左から j 番目の区画を (i,j) と表記します。区画 (i,j) にいる魚のおいしさは A_{i,j} です。

はじめ、あなたは区画 (1,1) にいます。これから、あなたは以下のルールで釣りをします。

  • 今いる区画を (p,q) とする。
  • 区画 (p,q) で、魚を 0 匹または 1 匹釣る。
  • その後、以下のルールで移動する。
    • (p,q) = (H,W) なら、釣りを終了する。
    • そうでなければ、区画 (p+1,q) または (p,q+1) に移動する。
      • ただし、 p=H のとき (p+1,q) への移動は許されない。
      • さらに、 q=W のとき (p,q+1) への移動は許されない。

1 以上 H+W-1 以下の全ての整数 k について、以下の問題を解いてください。

  • 魚を全体で k 匹まで釣ってよいとき、釣った魚のおいしさの総和の最大値はいくつか?

制約

  • 入力はすべて整数
  • 1 \le H,W \le 100
  • 1 \le A_{i,j} \le 10^9

入力

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

H W
A_{1,1} A_{1,2} \cdots A_{1,W}
A_{2,1} A_{2,2} \cdots A_{2,W}
\vdots
A_{H,1} A_{H,2} \cdots A_{H,W}

出力

H+W-1 行出力せよ。i 行目には k=i としたときの答えを出力せよ。


入力例 1

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

出力例 1

9
16
23
30
36
41
45
48
52
53

k=4 の場合、例えば、(3,1),(4,1),(4,2),(4,5) で魚を 1 匹ずつ釣るのが最適です。

このように釣りを行うためには、例えば (1,1) \rightarrow (2,1) \rightarrow (3,1) \rightarrow (4,1) \rightarrow (4,2) \rightarrow (4,3) \rightarrow (4,4) \rightarrow (4,5) \rightarrow (5,5) \rightarrow (5,6) と移動するとよいです。

Score : 6 points

Warning

Do not make any mention of this problem until April 24, 2021, 6:00 p.m. JST. In case of violation, compensation may be demanded. After the examination, you can reveal your total score and grade to others, but nothing more (for example, which problems you solved).

Problem Statement

In the PAST Island, there is a fishing pond, which is divided into H horizontal rows and W vertical columns of squares on the map. The deliciousness of a fish in Square (i, j) is A_{i,j}.

Initially, you are in Square (1, 1). Now, you will do fishing as follows:

  • Let (p, q) be the square you are currently in.
  • You catch zero or one fish in (p, q).
  • Then, you move as follows:
    • if (p, q) = (H, W), you end fishing;
    • otherwise, move to Square (p+1, q) or Square (p, q+1). However,
      • if p = H, you cannot move to Square (p+1, q);
      • if q = W, you cannot move to Square (p, q+1).

For every integer k from 1 through H+W-1, solve the following problem:

  • find the maximum possible total deliciousness of fish you catch when you are allowed to catch at most k fish in total.

Constraints

  • All values in input are integers.
  • 1 \le H,W \le 100
  • 1 \le A_{i,j} \le 10^9

Input

Input is given from Standard Input in the following format:

H W
A_{1,1} A_{1,2} \cdots A_{1,W}
A_{2,1} A_{2,2} \cdots A_{2,W}
\vdots
A_{H,1} A_{H,2} \cdots A_{H,W}

Output

Print H+W-1 lines. The i-th line should contain the answer for k=i.


Sample Input 1

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

Sample Output 1

9
16
23
30
36
41
45
48
52
53

For k=4, it is optimal to catch fish in, for example, (3,1),(4,1),(4,2),(4,5).

To catch fish in these squares, you can move as, for example, (1,1) \rightarrow (2,1) \rightarrow (3,1) \rightarrow (4,1) \rightarrow (4,2) \rightarrow (4,3) \rightarrow (4,4) \rightarrow (4,5) \rightarrow (5,5) \rightarrow (5,6).

J - Points to Cost

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 6

注意

この問題に対する言及は、2021/4/24 18:00 JST まで禁止されています。言及がなされた場合、賠償が請求される可能性があります。 試験後に総合得点や認定級を公表するのは構いませんが、どの問題が解けたかなどの情報は発信しないようにお願いします。

問題文

二次元平面上に点が N 個あります。このうち i 個目の点は (X_i,Y_i) です。同じ座標に点が複数あることもあります。 あなたへの課題は、直線 y=C 上から一点 P(p,C) をとって、以下で定義するコストを最小化することです。

  • (コスト) = \displaystyle \sum_{i=1}^{N} \bigl((p-X_i)^2+(C-Y_i)^2\bigr)

ありうるコストの最小値を出力して下さい。

制約

  • 入力はすべて整数
  • 1 \le N \le 2 \times 10^5
  • |C| \le 10^5
  • |X_i|,|Y_i| \le 10^5 (1 \le i \le N)

入力

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

N C
X_1 Y_1
X_2 Y_2
\vdots
X_N Y_N

出力

ありうるコストの最小値を出力せよ。 想定解との絶対誤差または相対誤差が 10^{-9} 以下の場合、正答として扱われる。


入力例 1

3 2
3 0
3 1
3 3

出力例 1

6.000000000000000

P(3,2) にとることにより、コストは最小の 6 を達成できます。


入力例 2

2 100000
-100000 100000
-100000 100000

出力例 2

0.000000000000000

同じ位置に複数の点がある場合があります。


入力例 3

13 -2
3 -6
-4 7
-8 -8
2 9
1 -3
0 4
-6 6
7 0
1 0
-9 7
6 -1
-7 -2
5 6

出力例 3

873.769230769230717

Score : 6 points

Warning

Do not make any mention of this problem until April 24, 2021, 6:00 p.m. JST. In case of violation, compensation may be demanded. After the examination, you can reveal your total score and grade to others, but nothing more (for example, which problems you solved).

Problem Statement

We have N points in a two-dimensional plane; the i-th point is (X_i,Y_i). There can be multiple points at the same coordinates. Your task is to choose a point P(p, C) on the line y=C to minimize the cost defined as follows:

  • (Cost) = \displaystyle \sum_{i=1}^{N} \bigl((p-X_i)^2+(C-Y_i)^2\bigr)

Print the minimized cost.

Constraints

  • All values in input are integers.
  • 1 \le N \le 2 \times 10^5
  • |C| \le 10^5
  • |X_i|,|Y_i| \le 10^5 (1 \le i \le N)

Input

Input is given from Standard Input in the following format:

N C
X_1 Y_1
X_2 Y_2
\vdots
X_N Y_N

Output

Print the minimized cost. Your output is considered correct when its absolute or relative error from our answer is at most 10^{-9}.


Sample Input 1

3 2
3 0
3 1
3 3

Sample Output 1

6.000000000000000

By choosing (3,2) as P, we can achieve the minimum cost of 6.


Sample Input 2

2 100000
-100000 100000
-100000 100000

Sample Output 2

0.000000000000000

There can be multiple points at the same position.


Sample Input 3

13 -2
3 -6
-4 7
-8 -8
2 9
1 -3
0 4
-6 6
7 0
1 0
-9 7
6 -1
-7 -2
5 6

Sample Output 3

873.769230769230717
K - Common Coupon

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 6

注意

この問題に対する言及は、2021/4/24 18:00 JST まで禁止されています。言及がなされた場合、賠償が請求される可能性があります。 試験後に総合得点や認定級を公表するのは構いませんが、どの問題が解けたかなどの情報は発信しないようにお願いします。

問題文

コンビニ「ルンルンマート」では、現在 N 個の商品が売られています。 i 個目の商品の価格は P_i 円で、効用は U_i 点です。

また、以下のルールで商品券を配布するイベントが行われています。

  • 購入金額 100 円ごとに 20 円分の商品券が 1 枚渡される。(100 円未満の端数は切り捨てる。)

10^{100} 円持っているあなたは、これらの商品から何個かを選んで ( 0 個でもよい) 購入します。ただし、同じ商品を複数回買うことはできません。
購入する商品の価格の合計を Q 円、効用の合計を T 点、渡される商品券の額面の合計を R 円として、買い物のスコア SS = T - Q + R と定義します。
S の最大値を求めてください。

制約

  • 入力はすべて整数
  • 1 \le N \le 10^5
  • 1 \le P_i,U_i \le 10^4 (1 \le i \le N)

入力

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

N
P_1 U_1
P_2 U_2
\vdots
P_N U_N

出力

答えを出力せよ。


入力例 1

3
50 40
30 29
60 55

出力例 1

5

例えば、1 個目の商品と 3 個目の商品を買うと、価格の合計は 110 円、効用の合計は 95 点、渡される商品券の額面の合計は 20 円で、買い物のスコアは 95 - 110 + 20 = 5 となります。
スコアはこれより大きくできません。


入力例 2

1
652 175

出力例 2

0

商品を 1 つも購入しないことが最適である場合があります。


入力例 3

10
859 346
669 705
344 425
693 747
24 808
462 344
930 67
878 35
906 253
531 832

出力例 3

1696

Score : 6 points

Warning

Do not make any mention of this problem until April 24, 2021, 6:00 p.m. JST. In case of violation, compensation may be demanded. After the examination, you can reveal your total score and grade to others, but nothing more (for example, which problems you solved).

Problem Statement

A convenient store Lun-Lun-Mart currently sells N products. The i-th product has a price of P_i yen and a utility of Q_i points. Also, the store is holding the following campaign:

  • For each 100 yen spent, one gift voucher worth 20 yen is awarded. (A fraction less than 100 yen is discarded.)

You have 10^{100} yen. Now, you will choose some (possibly none) of the products sold and buy them. You cannot buy the same product multiple times.
Let us define the score of purchase S as S = T - Q + R, where Q is the total price of products you buy, T is the total utility of products you buy, and R is the total value of vouchers you receive.
Find the maximum possible value of S.

Constraints

  • All values in input are integers.
  • 1 \le N \le 10^5
  • 1 \le P_i,U_i \le 10^4 (1 \le i \le N)

Input

Input is given from Standard Input in the following format:

N
P_1 U_1
P_2 U_2
\vdots
P_N U_N

Output

Print the answer.


Sample Input 1

3
50 40
30 29
60 55

Sample Output 1

5

For example, if you buy the 1-st and 3-rd products, the total price is 110 yen, the total utility is 95 points, and the total value of vouchers you receive is 20 yen, for the score of 95 - 110 + 20 = 5.
It is impossible to achieve a greater score.


Sample Input 2

1
652 175

Sample Output 2

0

It may be optimal to buy no products.


Sample Input 3

10
859 346
669 705
344 425
693 747
24 808
462 344
930 67
878 35
906 253
531 832

Sample Output 3

1696
L - Urban Planning

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 6

注意

この問題に対する言及は、2021/4/24 18:00 JST まで禁止されています。言及がなされた場合、賠償が請求される可能性があります。 試験後に総合得点や認定級を公表するのは構いませんが、どの問題が解けたかなどの情報は発信しないようにお願いします。

問題文

ある都市には、タワー 1 からタワー N までの N 個のタワーと、環状交差点 1 から 環状交差点 M までの M 個の環状交差点があります。
この都市は半径 10^9 メートルの円の形をしています。この円の中心にあたる地点から東に x メートル、北に y メートル進んだ地点を地点 (x, y) と表すことにします。
タワー i は地点 (\mathrm{PX}_i, \mathrm{PY}_i) に建っています。
環状交差点 i は地点 (\mathrm{CX}_i, \mathrm{CY}_i) を中心とする半径 R_i メートルの円 (内部は含まない) の形をしています。
高橋君は、以下の条件を満たすようにこの都市に線分状の道路をいくつか追加します。

  • 追加される道路の端点は全て、N 個のタワーの建っている地点のうちいずれかに一致するか、M 個の環状交差点のいずれかの上に乗っている
  • 以下のルールに従って、どの 2 つのタワーが建っている地点も互いに行き来可能である
    • 今いる地点が、ある環状交差点の上にあるとき、その環状交差点上の任意の地点に移動できる
    • 今いる地点が、ある道路の端点であるとき、その道路の他方の端点に移動できる (移動は端点から端点に限ることに注意せよ)
    • これ以外の移動は許されない

追加される道路の長さの合計として考えられる最小値を求めてください。

制約

  • 2 \le N \le 50
  • 1 \le M \le 8
  • 0 \le \mathrm{PX}_i \le 1000
  • 0 \le \mathrm{PY}_i \le 1000
  • i \neq j ならば (\mathrm{PX}_i, \mathrm{PY}_i) \neq (\mathrm{PX}_j, \mathrm{PY}_j)
  • 0 \le \mathrm{CX}_i \le 1000
  • 0 \le \mathrm{CY}_i \le 1000
  • 1 \le R_i \le 1000
  • i \neq j ならば (\mathrm{CX}_i, \mathrm{CY}_i, R_i) \neq (\mathrm{CX}_j, \mathrm{CY}_j, R_j)
  • 入力に含まれる値は全て整数

入力

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

N M
\mathrm{PX}_1 \mathrm{PY}_1
\mathrm{PX}_2 \mathrm{PY}_2
\mathrm{PX}_3 \mathrm{PY}_3
\hspace{22pt} \vdots
\mathrm{PX}_N \mathrm{PY}_N
\mathrm{CX}_1 \mathrm{CY}_1 R_1
\mathrm{CX}_2 \mathrm{CY}_2 R_2
\mathrm{CX}_3 \mathrm{CY}_3 R_3
\hspace{33pt} \vdots
\mathrm{CX}_M \mathrm{CY}_M R_M

出力

答えを出力せよ。
想定解答との絶対誤差または相対誤差が 10^{-5} 以下であるとき正解と判定される。


入力例 1

2 1
0 0
6 0
3 0 2

出力例 1

2.00000000000

各タワーと環状交差点の配置は下図のようになっています。

例えば以下の 2 つの道路を追加すると条件を満たします。

  • (0, 0)(1, 0) を結ぶ線分状の道路
  • (5, 0)(6, 0) を結ぶ線分状の道路

このとき、追加された道路の長さの和は 2 であり、これが最小です。


入力例 2

2 2
4 2
0 1
0 0 2
0 1 4

出力例 2

2.12310562562

各タワーと環状交差点の配置は下図のようになっています。

以下の 3 つの道路を追加するのが最適な追加方法です。

  • (0, 1)(0, 2) を結ぶ線分状の道路
  • (0, -2)(0, -3) を結ぶ線分状の道路
  • (\frac{16 \sqrt{17}}{17}, 1 + \frac{4 \sqrt{17}}{17})(4, 2) を結ぶ線分状の道路

入力例 3

3 4
9 2
5 20
0 21
0 0 2
0 0 10
16 0 10
10 15 3

出力例 3

13.10603728957

各タワーと環状交差点の配置は下図のようになっています。

Score : 6 points

Warning

Do not make any mention of this problem until April 24, 2021, 6:00 p.m. JST. In case of violation, compensation may be demanded. After the examination, you can reveal your total score and grade to others, but nothing more (for example, which problems you solved).

Problem Statement

In some city, there are N towers called Tower 1 through Tower N and M traffic circles called Traffic Circle 1 through Traffic Circle M.
The town has the shape of a circle with a radius of 10^9 meters. Let (x, y) represent the point that is x meters east and y meters north of the center of the circle.
Tower i is at (\mathrm{PX}_i, \mathrm{PY}_i).
Traffic Circle i has the shape of a circle with a radius of R_i meters centered at (\mathrm{CX}_i, \mathrm{CY}_i) (not including the interior).
In this city, Takahashi will build some number of roads, each in the shape of a line segment, to satisfy the following conditions:

  • Each endpoint of every road is a point at which one of the N towers stands or on one of the M traffic circles.
  • It is possible to travel between every pair of towers in the following manner:
    • if you are now on some traffic circle, you can get to anywhere on that traffic circle;
    • if you are now at an endpoint of some road, you can get to the other endpoint of that road (but not to intermediate points);
    • no other type of movement is allowed.

Find the minimum possible total length of the roads built.

Constraints

  • 2 \le N \le 50
  • 1 \le M \le 8
  • 0 \le \mathrm{PX}_i \le 1000
  • 0 \le \mathrm{PY}_i \le 1000
  • (\mathrm{PX}_i, \mathrm{PY}_i) \neq (\mathrm{PX}_j, \mathrm{PY}_j) for i \neq j
  • 0 \le \mathrm{CX}_i \le 1000
  • 0 \le \mathrm{CY}_i \le 1000
  • 1 \le R_i \le 1000
  • (\mathrm{CX}_i, \mathrm{CY}_i, R_i) \neq (\mathrm{CX}_j, \mathrm{CY}_j, R_j) for i \neq j
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N M
\mathrm{PX}_1 \mathrm{PY}_1
\mathrm{PX}_2 \mathrm{PY}_2
\mathrm{PX}_3 \mathrm{PY}_3
\hspace{22pt} \vdots
\mathrm{PX}_N \mathrm{PY}_N
\mathrm{CX}_1 \mathrm{CY}_1 R_1
\mathrm{CX}_2 \mathrm{CY}_2 R_2
\mathrm{CX}_3 \mathrm{CY}_3 R_3
\hspace{33pt} \vdots
\mathrm{CX}_M \mathrm{CY}_M R_M

Output

Print the answer. Your output is considered correct when its absolute or relative error from our answer is at most 10^{-5}.


Sample Input 1

2 1
0 0
6 0
3 0 2

Sample Output 1

2.00000000000

The towers and traffic circles are in the following positions:

We can satisfy the conditions by, for example, building the following two roads:

  • a road in the shape of a line segment connecting (0, 0) and (1, 0);
  • a road in the shape of a line segment connecting (5, 0) and (6, 0).

Here, the total length of the roads built is 2, which is the minimum possible sum.


Sample Input 2

2 2
4 2
0 1
0 0 2
0 1 4

Sample Output 2

2.12310562562

The towers and traffic circles are in the following positions:

It is optimal to build the following three roads:

  • a road connecting (0, 1) and (0, 2);
  • a road connecting (0, -2) and (0, -3);
  • a road connecting (\frac{16 \sqrt{17}}{17}, 1 + \frac{4 \sqrt{17}}{17}) and (4, 2).

Sample Input 3

3 4
9 2
5 20
0 21
0 0 2
0 0 10
16 0 10
10 15 3

Sample Output 3

13.10603728957

The towers and traffic circles are in the following positions:

M - Equal Queries

Time Limit: 4 sec / Memory Limit: 1024 MB

配点 : 6

注意

この問題に対する言及は、2021/4/24 18:00 JST まで禁止されています。言及がなされた場合、賠償が請求される可能性があります。 試験後に総合得点や認定級を公表するのは構いませんが、どの問題が解けたかなどの情報は発信しないようにお願いします。

問題文

長さ N の数列 A = (A_1, A_2, \dots, A_N) があります。

クエリが Q 個与えられるので、与えられた順に処理してください。各クエリでは、整数 l, r, x が与えられます。クエリの内容は以下の通りです。

  • A_l, A_{l+1}, \dots, A_r を、全て x に変更する。
  • その後、1 \le i < j \le N かつ A_i = A_j であるような整数の組 (i,j) の数を答える。

制約

  • 入力は全て整数
  • 2 \le N \le 2 \times 10^5
  • 1 \le Q \le 2 \times 10^5
  • 1 \le A_i \le 10^9 (1 \le i \le N)
  • 全てのクエリは以下を満たす
    • 1 \le l \le r \le N
    • 1 \le x \le 10^9

入力

入力は以下の形式で標準入力から与えられる。但し、Query_ii 回目のクエリを表す。

N
A_1 A_2 \cdots A_N
Q
Query_1
Query_2
\vdots
Query_Q

各クエリは以下の形式で与えられる。

l r x

出力

Q 行出力せよ。 i 行目には、i 回目のクエリに対する解答を出力せよ。


入力例 1

8
3 1 4 1 5 9 2 6
6
1 3 5
2 4 1
7 7 9
5 8 2
1 8 1000000000
2 7 999999999

出力例 1

6
4
5
9
28
16
  • はじめ、A=(3,1,4,1,5,9,2,6) です。
  • 1 回目のクエリを処理すると、A(5,5,5,1,5,9,2,6) となります。 このクエリでの解答は 6 です。
  • 2 回目のクエリを処理すると、A(5,1,1,1,5,9,2,6) となります。このクエリでの解答は 4 です。
  • 3 回目のクエリを処理すると、A(5,1,1,1,5,9,9,6) となります。このクエリでの解答は 5 です。
  • 4 回目のクエリを処理すると、A(5,1,1,1,2,2,2,2) となります。このクエリでの解答は 9 です。
  • 5 回目のクエリを処理すると、A(1000000000,1000000000,1000000000,1000000000,1000000000,1000000000,1000000000,1000000000) となります。このクエリでの解答は 28 です。
  • 6 回目のクエリを処理すると、A(1000000000,999999999,999999999,999999999,999999999,999999999,999999999,1000000000) となります。このクエリでの解答は 16 です。

Score : 6 points

Warning

Do not make any mention of this problem until April 24, 2021, 6:00 p.m. JST. In case of violation, compensation may be demanded. After the examination, you can reveal your total score and grade to others, but nothing more (for example, which problems you solved).

Problem Statement

We have a sequence of length N: A = (A_1, A_2, \dots, A_N).

You will be given Q queries, which should be processed in the order they are given. In each query, given integers l, r, and x, do as follows:

  • change each of the elements A_l, A_{l+1}, \dots, A_r to x;
  • then, report the number of pairs of integers (i, j) such that 1 \le i < j \le N and A_i = A_j.

Constraints

  • All values in input are integers.
  • 2 \le N \le 2 \times 10^5
  • 1 \le Q \le 2 \times 10^5
  • 1 \le A_i \le 10^9 (1 \le i \le N)
  • For every query, the following holds:
    • 1 \le l \le r \le N
    • 1 \le x \le 10^9

Input

Input is given from Standard Input in the following format, where Query_i represents the i-th query:

N
A_1 A_2 \cdots A_N
Q
Query_1
Query_2
\vdots
Query_Q

Each query is in the following format:

l r x

Output

Print Q lines. The i-th line should contain the response to the i-th query.


Sample Input 1

8
3 1 4 1 5 9 2 6
6
1 3 5
2 4 1
7 7 9
5 8 2
1 8 1000000000
2 7 999999999

Sample Output 1

6
4
5
9
28
16
  • Initially, we have A=(3,1,4,1,5,9,2,6).
  • The 1-st query makes A (5,5,5,1,5,9,2,6). The response to this query should be 6.
  • The 2-nd query makes A (5,1,1,1,5,9,2,6). The response to this query should be 4.
  • The 3-rd query makes A (5,1,1,1,5,9,9,6). The response to this query should be 5.
  • The 4-th query makes A (5,1,1,1,2,2,2,2). The response to this query should be 9.
  • The 5-th query makes A (1000000000,1000000000,1000000000,1000000000,1000000000,1000000000,1000000000,1000000000). The response to this query should be 28.
  • The 6-th query makes A (1000000000,999999999,999999999,999999999,999999999,999999999,999999999,1000000000). The response to this query should be 16.
N - Activities

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 6

注意

この問題に対する言及は、2021/4/24 18:00 JST まで禁止されています。言及がなされた場合、賠償が請求される可能性があります。 試験後に総合得点や認定級を公表するのは構いませんが、どの問題が解けたかなどの情報は発信しないようにお願いします。

問題文

N 種類の活動、活動 1, 2, \dots N があります。 あなたは、これらの活動の中から 1 つ以上を選び、好きな順序で行います。 ただし、同じ活動を複数回行うことはできません。

現在のあなたの体力は H です。 活動 i を行うと、あなたは a_i \times{}(体力) 点の得点を得て、その後、体力が b_i 減ります。 (活動後、体力が 0 未満になることも許されます。)
あなたの得ることができる合計得点の最大値を求めてください。

制約

  • 入力は全て整数
  • 1 ≤ N ≤ 100
  • 1 ≤ H ≤ 10^5
  • 1 ≤ a_i, b_i ≤ 10^5

入力

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

N H
a_1 b_1
a_2 b_2
\vdots
a_N b_N

出力

答えを出力せよ。


入力例 1

4 6
4 1
3 2
2 3
1 4

出力例 1

45

例えば、以下のようにすると合計得点が 45 点になります。

  • 初め、体力は 6 である。
  • 活動 1 を行う。4 \times 6 = 24 点を得て、体力が 6 - 1 = 5 になる。
  • 活動 2 を行う。3 \times 5 = 15 点を得て、体力が 5 - 2 = 3 になる。
  • 活動 3 を行う。2 \times 3 = 6 点を得て、体力が 3 - 3 = 0 になる。

入力例 2

4 6
1 1
2 2
3 3
4 4

出力例 2

30

入力例 3

16 100
18 17
5 18
7 2
5 8
6 2
16 16
2 18
13 17
18 10
11 10
17 8
1 2
20 7
4 11
7 15
2 1

出力例 3

9282

Score : 6 points

Warning

Do not make any mention of this problem until April 24, 2021, 6:00 p.m. JST. In case of violation, compensation may be demanded. After the examination, you can reveal your total score and grade to others, but nothing more (for example, which problems you solved).

Problem Statement

We have N kinds of activities: Activity 1, 2, \dots N. You will choose one or more from these activities and do them in the order you like. The same activity cannot be done multiple times.

Your current stamina is H. Doing activity i gets you a_i \times{}(stamina) points and decreases your stamina by b_i. (It is allowed to do an activity that makes your stamina less than 0.) Find the maximum total number of points you can get.

Constraints

  • All values in input are integers.
  • 1 ≤ N ≤ 100
  • 1 ≤ H ≤ 10^5
  • 1 ≤ a_i, b_i ≤ 10^5

Input

Input is given from Standard Input in the following format:

N H
a_1 b_1
a_2 b_2
\vdots
a_N b_N

Output

Print the answer.


Sample Input 1

4 6
4 1
3 2
2 3
1 4

Sample Output 1

45

One way to get a total of 45 points is as follows:

  • Your initial stamina is 6.
  • Do Activity 1. You get 4 \times 6 = 24 points and your stamina becomes 6 - 1 = 5.
  • Do Activity 2. You get 3 \times 5 = 15 points and your stamina becomes 5 - 2 = 3.
  • Do Activity 3. You get 2 \times 3 = 6 points and your stamina becomes 3 - 3 = 0.

Sample Input 2

4 6
1 1
2 2
3 3
4 4

Sample Output 2

30

Sample Input 3

16 100
18 17
5 18
7 2
5 8
6 2
16 16
2 18
13 17
18 10
11 10
17 8
1 2
20 7
4 11
7 15
2 1

Sample Output 3

9282
O - Shortest Distance Query

Time Limit: 4 sec / Memory Limit: 1024 MB

配点 : 6

注意

この問題に対する言及は、2021/4/24 18:00 JST まで禁止されています。言及がなされた場合、賠償が請求される可能性があります。 試験後に総合得点や認定級を公表するのは構いませんが、どの問題が解けたかなどの情報は発信しないようにお願いします。

問題文

N 頂点 M 辺の単純連結無向グラフが与えられます。ここで、M ≤ N + 10 です。
頂点には 1, 2, \dots, N の、辺には 1, 2, \dots, M の番号がついており、辺 i は頂点 a_i と頂点 b_i の間を結びます。 全ての辺の長さは 1 です。

Q 個のクエリを順番に処理してください。i 番目のクエリの内容は以下の通りです。

  • 整数 u_i, v_i が与えられる。頂点 u_i と頂点 v_i の間の最短距離を出力する。

制約

  • 入力は全て整数
  • 2 ≤ N ≤ 10^5
  • N - 1 ≤ M ≤ N + 10
  • 1 ≤ a_i < b_i ≤ N
  • i ≠ j ならば (a_i, b_i) ≠ (a_j, b_j)
  • 与えられるグラフは連結
  • 1 ≤ Q ≤ 10^4
  • 1 ≤ u_i < v_i ≤ N

入力

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

N M
a_1 b_1
a_2 b_2
\vdots
a_M b_M
Q
u_1 v_1
u_2 v_2
\vdots
u_Q v_Q

出力

問題文の指示に従って Q 個の整数を改行区切りで出力せよ。


入力例 1

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

出力例 1

2
4
1

与えられるグラフは以下のようになっています。

したがって、

  • 頂点 4 と頂点 6 の間の最短距離は 2
  • 頂点 1 と頂点 5 の間の最短距離は 4
  • 頂点 1 と頂点 2 の間の最短距離は 1

となります。


入力例 2

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

出力例 2

3
3
2
4
1
1
1
4

入力例 3

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

出力例 3

2
4
1
3
5
2

Score : 6 points

Warning

Do not make any mention of this problem until April 24, 2021, 6:00 p.m. JST. In case of violation, compensation may be demanded. After the examination, you can reveal your total score and grade to others, but nothing more (for example, which problems you solved).

Problem Statement

You are given an simple connected undirected graph, where M ≤ N + 10. The vertices are numbered 1, 2, \dots, N, and the edges are numbered 1, 2, \dots, M. Edge i connects Vertex a_i and Vertex b_i. The length of every edge is 1.

Process Q queries in order. The i-th query is as follows:

  • given integers u_i and v_i, find the shortest distance between Vertex u_i and Vertex v_i.

Constraints

  • All values in input are integers.
  • 2 ≤ N ≤ 10^5
  • N - 1 ≤ M ≤ N + 10
  • 1 ≤ a_i < b_i ≤ N
  • (a_i, b_i) ≠ (a_j, b_j) for i ≠ j
  • The given graph is connected.
  • 1 ≤ Q ≤ 10^4
  • 1 ≤ u_i < v_i ≤ N

Input

Input is given from Standard Input in the following format:

N M
a_1 b_1
a_2 b_2
\vdots
a_M b_M
Q
u_1 v_1
u_2 v_2
\vdots
u_Q v_Q

Output

Print Q integers as specified in Problem Statement, each in its own line.


Sample Input 1

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

Sample Output 1

2
4
1

The given graph is as follows:

Thus,

  • the shortest distance between Vertex 4 and Vertex 6 is 2;
  • the shortest distance between Vertex 1 and Vertex 5 is 4;
  • the shortest distance between Vertex 1 and Vertex 2 is 1.

Sample Input 2

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

Sample Output 2

3
3
2
4
1
1
1
4

Sample Input 3

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

Sample Output 3

2
4
1
3
5
2