C - Cat

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 200

問題文

長さ N の文字列 S が与えられます。

S に連続して含まれる na を全て nya に置き換えて得られる文字列を答えてください。

制約

  • N1 以上 1000 以下の整数
  • S は英小文字からなる長さ N の文字列

入力

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

N
S

出力

答えを出力せよ。


入力例 1

4
naan

出力例 1

nyaan

naan に連続して含まれる na を全て nya に置き換えて得られる文字列は nyaan です。


入力例 2

4
near

出力例 2

near

Sna が連続して含まれないこともあります。


入力例 3

8
national

出力例 3

nyationyal

Score : 200 points

Problem Statement

You are given a string S of length N.

Find the string obtained by replacing all contiguous occurrences of na in S with nya.

Constraints

  • N is an integer between 1 and 1000, inclusive.
  • S is a string of length N consisting of lowercase English letters.

Input

The input is given from Standard Input in the following format:

N
S

Output

Print the answer.


Sample Input 1

4
naan

Sample Output 1

nyaan

Replacing all contiguous occurrences of na in naan with nya results in the string nyaan.


Sample Input 2

4
near

Sample Output 2

near

S may not contain a contiguous na.


Sample Input 3

8
national

Sample Output 3

nyationyal
D - How many?

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 200

問題文

a+b+c \leq S かつ a \times b \times c \leq T を満たす非負整数の組 (a,b,c) はいくつありますか?

制約

  • 0 \leq S \leq 100
  • 0 \leq T \leq 10000
  • S, T は整数である。

入力

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

S T

出力

条件を満たす非負整数の組 (a,b,c) の個数を出力せよ。


入力例 1

1 0

出力例 1

4

条件を満たす非負整数の組 (a,b,c)(0,0,0), (0,0,1), (0,1,0), (1,0,0)4 つです。


入力例 2

2 5

出力例 2

10

入力例 3

10 10

出力例 3

213

入力例 4

30 100

出力例 4

2471

Score : 200 points

Problem Statement

How many triples of non-negative integers (a, b, c) satisfy a+b+c \leq S and a \times b \times c \leq T?

Constraints

  • 0 \leq S \leq 100
  • 0 \leq T \leq 10000
  • S and T are integers.

Input

Input is given from Standard Input in the following format:

S T

Output

Print the number of triples of non-negative integers (a,b,c) satisfying the conditions.


Sample Input 1

1 0

Sample Output 1

4

The triples (a,b,c) satisfying the conditions are (0,0,0), (0,0,1), (0,1,0), and (1,0,0) ― there are four of them.


Sample Input 2

2 5

Sample Output 2

10

Sample Input 3

10 10

Sample Output 3

213

Sample Input 4

30 100

Sample Output 4

2471
E - Virus

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 300

問題文

1, 2, \ldots, N の番号がついた N 人の人が二次元平面上におり、人 i は座標 (X_i,Y_i) で表される地点にいます。

1 がウイルスに感染しました。ウイルスに感染した人から距離が D 以内にいる人にウイルスはうつります。

ただし、距離はユークリッド距離、すなわち 2(a_1, a_2)(b_1, b_2) に対し、この 2 点間の距離が \sqrt {(a_1-b_1)^2 + (a_2-b_2)^2} であるものとして定められています。

十分に時間が経過した、すなわち人 i がウイルスに感染しているならば 人 i との距離が D 以内にいるすべての人がウイルスに感染している状態になったときに、各 i について人 i がウイルスに感染しているか判定してください。

制約

  • 1 \leq N, D \leq 2000
  • -1000 \leq X_i, Y_i \leq 1000
  • i \neq j のとき (X_i, Y_i) \neq (X_j, Y_j)
  • 入力はすべて整数

入力

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

N D
X_1 Y_1
X_2 Y_2
\vdots
X_N Y_N

出力

N 行出力せよ。i 行目には、人 i がウイルスに感染しているならば Yes を、そうでないならば No を出力せよ。


入力例 1

4 5
2 -1
3 1
8 8
0 5

出力例 1

Yes
Yes
No
Yes

1 と人 2 の距離は \sqrt 5 であるため、人 2 はウイルスに感染します。
また、人 2 と人 4 の距離は 5 であるため、人 4 はウイルスに感染します。
3 は距離 5 以内に人がいないので、ウイルスに感染することはありません。


入力例 2

3 1
0 0
-1000 -1000
1000 1000

出力例 2

Yes
No
No

入力例 3

9 4
3 2
6 -1
1 6
6 5
-2 -3
5 3
2 -3
2 1
2 6

出力例 3

Yes
No
No
Yes
Yes
Yes
Yes
Yes
No

Score : 300 points

Problem Statement

There are N people numbered 1, 2, \ldots, N on a two-dimensional plane, and person i is at the point represented by the coordinates (X_i,Y_i).

Person 1 has been infected with a virus. The virus spreads to people within a distance of D from an infected person.

Here, the distance is defined as the Euclidean distance, that is, for two points (a_1, a_2) and (b_1, b_2), the distance between these two points is \sqrt {(a_1-b_1)^2 + (a_2-b_2)^2}.

After a sufficient amount of time has passed, that is, when all people within a distance of D from person i are infected with the virus if person i is infected, determine whether person i is infected with the virus for each i.

Constraints

  • 1 \leq N, D \leq 2000
  • -1000 \leq X_i, Y_i \leq 1000
  • (X_i, Y_i) \neq (X_j, Y_j) if i \neq j.
  • All input values are integers.

Input

The input is given from Standard Input in the following format:

N D
X_1 Y_1
X_2 Y_2
\vdots
X_N Y_N

Output

Print N lines. The i-th line should contain Yes if person i is infected with the virus, and No otherwise.


Sample Input 1

4 5
2 -1
3 1
8 8
0 5

Sample Output 1

Yes
Yes
No
Yes

The distance between person 1 and person 2 is \sqrt 5, so person 2 gets infected with the virus.
Also, the distance between person 2 and person 4 is 5, so person 4 gets infected with the virus.
Person 3 has no one within a distance of 5, so they will not be infected with the virus.


Sample Input 2

3 1
0 0
-1000 -1000
1000 1000

Sample Output 2

Yes
No
No

Sample Input 3

9 4
3 2
6 -1
1 6
6 5
-2 -3
5 3
2 -3
2 1
2 6

Sample Output 3

Yes
No
No
Yes
Yes
Yes
Yes
Yes
No
F - Colorful Beans

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 250

問題文

N 種類のビーンズが 1 粒ずつあります。 i 種類目のビーンズはおいしさが A_i で色が C_i です。ビーンズは混ぜられており、色でしか区別することができません。

あなたはビーンズの色を 1 つ選び、その色のビーンズをどれか 1 粒食べます。ビーンズの色をうまく選ぶことで、食べる可能性のあるビーンズのおいしさの最小値を最大化してください。

制約

  • 1 \leq N \leq 2 \times 10^{5}
  • 1 \leq A_i \leq 10^{9}
  • 1 \leq C_i \leq 10^{9}
  • 入力は全て整数である。

入力

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

N
A_1 C_1
A_2 C_2
\vdots
A_N C_N

出力

食べる可能性のあるビーンズのおいしさの最小値の最大値を整数として出力せよ。


入力例 1

4
100 1
20 5
30 5
40 1

出力例 1

40

同じ色のビーンズは互いに区別がつかないことに注意してください。

選ぶことができる色は 色 1 と 色 5 です。

  • 1 のビーンズは 2 種類あり、美味しさはそれぞれ 100, 40 です。よって、色 1 を選んだときのおいしさの最小値は 40 です。
  • 5 のビーンズは 2 種類あり、美味しさはそれぞれ 20, 30 です。よって、色 5 を選んだときのおいしさの最小値は 20 です。

おいしさの最小値を最大化するには 色 1 を選べばよいため、そのときの最小値である 40 を出力します。


入力例 2

10
68 3
17 2
99 2
92 4
82 4
10 3
100 2
78 1
3 1
35 4

出力例 2

35

Score: 250 points

Problem Statement

There are N types of beans, one bean of each type. The i-th type of bean has a deliciousness of A_i and a color of C_i. The beans are mixed and can only be distinguished by color.

You will choose one color of beans and eat one bean of that color. By selecting the optimal color, maximize the minimum possible deliciousness of the bean you eat.

Constraints

  • 1 \leq N \leq 2 \times 10^{5}
  • 1 \leq A_i \leq 10^{9}
  • 1 \leq C_i \leq 10^{9}
  • All input values are integers.

Input

The input is given from Standard Input in the following format:

N
A_1 C_1
A_2 C_2
\vdots
A_N C_N

Output

Print as an integer the maximum value of the minimum possible deliciousness of the bean you eat.


Sample Input 1

4
100 1
20 5
30 5
40 1

Sample Output 1

40

Note that beans of the same color cannot be distinguished from each other.

You can choose color 1 or color 5.

  • There are two types of beans of color 1, with deliciousness of 100 and 40. Thus, the minimum deliciousness when choosing color 1 is 40.
  • There are two types of beans of color 5, with deliciousness of 20 and 30. Thus, the minimum deliciousness when choosing color 5 is 20.

To maximize the minimum deliciousness, you should choose color 1, so print the minimum deliciousness in that case: 40.


Sample Input 2

10
68 3
17 2
99 2
92 4
82 4
10 3
100 2
78 1
3 1
35 4

Sample Output 2

35
G - Iroha and Haiku (New ABC Edition)

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 400

問題文

長さ N の数列 A=(A_0,\ldots,A_{N-1}) があります。
次の条件を全て満たす整数の組 (x,y,z,w) が存在するか判定してください。

  • 0 \leq x < y < z < w \leq N
  • A_x + A_{x+1} + \ldots + A_{y-1} = P
  • A_y + A_{y+1} + \ldots + A_{z-1} = Q
  • A_z + A_{z+1} + \ldots + A_{w-1} = R

制約

  • 3 \leq N \leq 2\times 10^5
  • 1 \leq A_i \leq 10^9
  • 1 \leq P,Q,R \leq 10^{15}
  • 入力に含まれる値は全て整数である

入力

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

N P Q R
A_0 A_1 \ldots A_{N-1}

出力

条件を満たす組が存在するなら Yes、存在しないなら No を出力せよ。


入力例 1

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

出力例 1

Yes

(x,y,z,w)=(1,3,6,8) が条件を満たします。


入力例 2

9 100 101 100
31 41 59 26 53 58 97 93 23

出力例 2

No

入力例 3

7 1 1 1
1 1 1 1 1 1 1

出力例 3

Yes

Score : 400 points

Problem Statement

There is a sequence A=(A_0,\ldots,A_{N-1}) of length N.
Determine if there exists a tuple of integers (x,y,z,w) that satisfies all of the following conditions:

  • 0 \leq x < y < z < w \leq N
  • A_x + A_{x+1} + \ldots + A_{y-1} = P
  • A_y + A_{y+1} + \ldots + A_{z-1} = Q
  • A_z + A_{z+1} + \ldots + A_{w-1} = R

Constraints

  • 3 \leq N \leq 2\times 10^5
  • 1 \leq A_i \leq 10^9
  • 1 \leq P,Q,R \leq 10^{15}
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N P Q R
A_0 A_1 \ldots A_{N-1}

Output

If there exists a tuple that satisfies the conditions, print Yes; otherwise, print No.


Sample Input 1

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

Sample Output 1

Yes

(x,y,z,w)=(1,3,6,8) satisfies the conditions.


Sample Input 2

9 100 101 100
31 41 59 26 53 58 97 93 23

Sample Output 2

No

Sample Input 3

7 1 1 1
1 1 1 1 1 1 1

Sample Output 3

Yes