A - Water Pressure

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 100

問題文

水圧は水深のみに依存し、水深 x [m] の場所では \dfrac{x}{100} [MPa] になるものとします。

水深 D [m] の場所の水圧は何 [MPa] ですか?

制約

  • 1 \leq D \leq 10000
  • D は整数である。

入力

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

D

出力

答えを出力せよ。想定解答との絶対誤差または相対誤差が 10^{-3} 以下であれば正解として扱われる。


入力例 1

1000

出力例 1

10

水深 1000 [m] の場所の水圧は 10 [MPa] です。10.09.999999 などを出力しても正解となります。


入力例 2

50

出力例 2

0.5

入力例 3

3141

出力例 3

31.41

Score : 100 points

Problem Statement

Let us assume that water pressure depends only on depth and is \dfrac{x}{100} megapascal at a depth of x meters.

What is the water pressure in megapascals at a depth of D meters?

Constraints

  • 1 \leq D \leq 10000
  • D is an integer.

Input

Input is given from Standard Input in the following format:

D

Output

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


Sample Input 1

1000

Sample Output 1

10

The water pressure at a depth of 1000 meters is 10 megapascal. Outputs such as 10.0 and 9.999999 would also be accepted.


Sample Input 2

50

Sample Output 2

0.5

Sample Input 3

3141

Sample Output 3

31.41
B - Election

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 200

問題文

選挙が行われています。

N 人が投票を行い、i\,(1 \leq i \leq N) 番目の人は S_i という名前の候補者に投票しました。

得票数が最大の候補者の名前を答えてください。なお、与えられる入力では得票数が最大の候補者は一意に定まります。

制約

  • 1 \leq N \leq 100
  • S_i は英小文字からなる長さ 1 以上 10 以下の文字列
  • N は整数
  • 得票数が最大の候補者は一意に定まる

入力

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

N
S_1
S_2
\vdots
S_N

出力

得票数が最大の候補者の名前を出力せよ。


入力例 1

5
snuke
snuke
takahashi
takahashi
takahashi

出力例 1

takahashi

takahashi3 票、snuke2 票獲得しました。よって takahashi を出力します。


入力例 2

5
takahashi
takahashi
aoki
takahashi
snuke

出力例 2

takahashi

入力例 3

1
a

出力例 3

a

Score : 200 points

Problem Statement

An election is taking place.

N people voted. The i-th person (1 \leq i \leq N) cast a vote to the candidate named S_i.

Find the name of the candidate who received the most votes. The given input guarantees that there is a unique candidate with the most votes.

Constraints

  • 1 \leq N \leq 100
  • S_i is a string of length between 1 and 10 (inclusive) consisting of lowercase English letters.
  • N is an integer.
  • There is a unique candidate with the most votes.

Input

Input is given from Standard Input in the following format:

N
S_1
S_2
\vdots
S_N

Output

Print the name of the candidate who received the most votes.


Sample Input 1

5
snuke
snuke
takahashi
takahashi
takahashi

Sample Output 1

takahashi

takahashi got 3 votes, and snuke got 2, so we print takahashi.


Sample Input 2

5
takahashi
takahashi
aoki
takahashi
snuke

Sample Output 2

takahashi

Sample Input 3

1
a

Sample Output 3

a
C - Counting 2

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 300

問題文

N 人の生徒からなるクラスがあり、i\,(1 \leq i \leq N) 番目の生徒の身長は A_i です。

j=1,2,\ldots,Q について、以下の質問に答えてください。

  • N 人のうち、身長が x_j 以上の生徒は何人か?

制約

  • 1 \leq N,Q \leq 2 \times 10^5
  • 1 \leq A_i \leq 10^9
  • 1 \leq x_j \leq 10^9
  • 入力は全て整数

入力

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

N Q
A_1 A_2 \ldots A_N
x_1
x_2
\vdots
x_Q

出力

Q 行出力せよ。

j\,(1 \leq j \leq Q) 行目には身長が x_j 以上の生徒の数を出力せよ。


入力例 1

3 1
100 160 130
120

出力例 1

2

身長が 120 以上の生徒は 2 番目の生徒と 3 番目の生徒です。


入力例 2

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

出力例 2

0
1
2
3
4

入力例 3

5 5
804289384 846930887 681692778 714636916 957747794
424238336
719885387
649760493
596516650
189641422

出力例 3

5
3
5
5
5

Score : 300 points

Problem Statement

There is a class with N students. The height of the i-th student (1 \leq i \leq N) is A_i.

For each j=1,2,\ldots,Q, answer the following question.

  • How many of the N students have a height of at least x_j?

Constraints

  • 1 \leq N,Q \leq 2 \times 10^5
  • 1 \leq A_i \leq 10^9
  • 1 \leq x_j \leq 10^9
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N Q
A_1 A_2 \ldots A_N
x_1
x_2
\vdots
x_Q

Output

Print Q lines.

The j-th line (1 \leq j \leq Q) should contain the number of students with a height of at least x_j.


Sample Input 1

3 1
100 160 130
120

Sample Output 1

2

The students with a height of at least 120 are the 2-nd and 3-rd ones.


Sample Input 2

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

Sample Output 2

0
1
2
3
4

Sample Input 3

5 5
804289384 846930887 681692778 714636916 957747794
424238336
719885387
649760493
596516650
189641422

Sample Output 3

5
3
5
5
5
D - Neighbors

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 400

問題文

1 から N の番号がついた N 人を横一列に並べる方法のうち、以下の形式の M 個の条件全てを満たすものが存在するか判定してください。

  • 条件:人 A_i と人 B_i は隣り合っている

制約

  • 2 \leq N \leq 10^5
  • 0 \leq M \leq 10^5
  • 1\leq A_i < B_i \leq N
  • (A_i,B_i) は相異なる

入力

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

N M
A_1 B_1
\vdots
A_M B_M

出力

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


入力例 1

4 2
1 3
2 3

出力例 1

Yes

例えば 4,1,3,2 の順に並べることで全ての条件を満たすことができます。


入力例 2

4 3
1 4
2 4
3 4

出力例 2

No

どのように並べても全ての条件を満たすことはできません。

Score : 400 points

Problem Statement

Determine whether there is a way to line up N people, numbered 1 to N, in a row side by side to satisfy all of the M conditions in the following format.

  • Condition: Person A_i and Person B_i are adjacent.

Constraints

  • 2 \leq N \leq 10^5
  • 0 \leq M \leq 10^5
  • 1\leq A_i < B_i \leq N
  • All pairs (A_i,B_i) are distinct.

Input

Input is given from Standard Input in the following format:

N M
A_1 B_1
\vdots
A_M B_M

Output

If there is a way to line up people to satisfy the conditions, print Yes; if not, print No.


Sample Input 1

4 2
1 3
2 3

Sample Output 1

Yes

One way to satisfy all the conditions is to line them up in the order 4,1,3,2.


Sample Input 2

4 3
1 4
2 4
3 4

Sample Output 2

No

There is no way to line them up to satisfy all the conditions.

E - Minimal payments

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 500

問題文

Atcoder 王国では A_1 円, A_2 円, \ldots, A_N 円の N 種類の硬貨が使用されています。
ここで、1=A_1 < \ldots < A_N であり、全ての 1\leq i \leq N-1 に対し、A_{i+1}A_i の倍数です。

硬貨のみを使って X 円を支払うとき、支払いに使う硬貨の枚数とお釣りでもらう硬貨の枚数の合計の最小値はいくつですか?

正確には、YX 以上の整数を自由に動く時、Y 円ちょうどを表すために必要な硬貨の枚数と、Y-X 円ちょうどを表すために必要な硬貨の枚数の和の最小値を求めてください。

制約

  • 入力に含まれる値は全て整数である
  • 1 \leq N \leq 60
  • 1=A_1 < \ldots <A_N \leq 10^{18}
  • 全ての 1\leq i \leq N-1A_{i+1}A_i の倍数である
  • 1\leq X \leq 10^{18}

入力

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

N X
A_1 \ldots A_N

出力

答えを出力せよ。


入力例 1

3 87
1 10 100

出力例 1

5

100 円硬貨 1 枚で支払いを行い、10 円硬貨 1 枚と 1 円硬貨 3 枚をお釣りでもらうと、合計枚数は 5 枚になります。


入力例 2

2 49
1 7

出力例 2

7

7 円硬貨 7 枚で支払いを行うのが最適です。


入力例 3

10 123456789012345678
1 100 10000 1000000 100000000 10000000000 1000000000000 100000000000000 10000000000000000 1000000000000000000

出力例 3

233

Score : 500 points

Problem Statement

There are N kinds of coins used in the Kingdom of Atcoder: A_1-yen, A_2-yen, \ldots, A_N-yen coins.
Here, 1=A_1 < \ldots < A_N holds, and A_{i+1} is a multiple of A_i for every 1\leq i \leq N-1.

When paying for a product worth X yen using just these coins, what is the minimum total number of coins used in payment and returned as change?

Accurately, when Y is an integer at least X, find the minimum sum of the number of coins needed to represent exactly Y yen and the number of coins needed to represent exactly Y-X yen.

Constraints

  • All values in input are integers.
  • 1 \leq N \leq 60
  • 1=A_1 < \ldots <A_N \leq 10^{18}
  • A_{i+1} is a multiple of A_i for every 1\leq i \leq N-1.
  • 1\leq X \leq 10^{18}

Input

Input is given from Standard Input in the following format:

N X
A_1 \ldots A_N

Output

Print the answer.


Sample Input 1

3 87
1 10 100

Sample Output 1

5

If we pay with one 100-yen coin and receive one 10-yen coin and three 1-yen coins as the change, the total number of coins will be 5.


Sample Input 2

2 49
1 7

Sample Output 2

7

It is optimal to pay with seven 7-yen coins.


Sample Input 3

10 123456789012345678
1 100 10000 1000000 100000000 10000000000 1000000000000 100000000000000 10000000000000000 1000000000000000000

Sample Output 3

233
F - Jealous Two

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 500

問題文

すぬけ君は高橋君と青木君にプレゼントを 1 個ずつ渡そうと考えています。
プレゼントの候補は N 種類あり、i 番目の候補は、高橋君にとって嬉しさ A_i 、青木君にとって嬉しさ B_i です。

高橋君と青木君はとても嫉妬深いので、相手がもらったプレゼントの自分にとっての嬉しさが、自分がもらったプレゼントの自分にとっての嬉しさより大きい場合、相手に嫉妬してけんかになってしまいます。

N^2 通りあるプレゼントの渡し方のうち、高橋君と青木君がけんかしないようなものは何通りありますか?

制約

  • 1 \leq N \leq 2\times 10^5
  • 0 \leq A_i \leq 10^9
  • 0 \leq B_i \leq 10^9
  • 入力に含まれる値は全て整数である

入力

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

N
A_1 \ldots A_N
B_1 \ldots B_N

出力

答えを出力せよ。


入力例 1

3
50 100 150
1 3 2

出力例 1

4

例えば高橋君に 1 番目の候補を、青木君に 2 番目の候補をプレゼントした場合、 青木君がもらったプレゼントの高橋君にとっての嬉しさが 100、 高橋君がもらったプレゼントの高橋君にとっての嬉しさは 50 なので、高橋君は青木君に嫉妬し、けんかしてしまいます。

また、例えば高橋君に 3 番目の候補を、青木君に 2 番目の候補をプレゼントした場合、2 人はけんかしません。

2 人に同じものをプレゼントしてもよいことに注意してください。


入力例 2

3
123456789 123456 123
987 987654 987654321

出力例 2

6

入力例 3

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

出力例 3

37

Score : 500 points

Problem Statement

Snuke is planning on giving one gift each to Takahashi and Aoki.
There are N candidates for the gifts. Takahashi's impression of the i-th candidate is A_i, and Aoki's impression of it is B_i.

The two are very jealous. If Takahashi's impression of the gift Aoki gets is greater than Takahashi's impression of the gift Takahashi gets, Takahashi gets jealous of Aoki and starts fighting, and vice versa.

Among the N^2 possible ways of giving the gifts, how many do not lead to fighting?

Constraints

  • 1 \leq N \leq 2\times 10^5
  • 0 \leq A_i \leq 10^9
  • 0 \leq B_i \leq 10^9
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 \ldots A_N
B_1 \ldots B_N

Output

Print the answer.


Sample Input 1

3
50 100 150
1 3 2

Sample Output 1

4

For example, if we give the 1-st candidate to Takahashi and the 2-nd candidate to Aoki, Takahashi's impression of the gift Aoki gets is 100, while Takahashi's impression of the gift Takahashi gets is 50, so Takahashi gets jealous of Aoki and starts fighting.

As another example, if we give the 3-rd candidate to Takahashi and the 2-nd candidate to Aoki, the two will not start fighting.

Note that it is allowed to give the same gift to the two.


Sample Input 2

3
123456789 123456 123
987 987654 987654321

Sample Output 2

6

Sample Input 3

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

Sample Output 3

37
G - Balls in Boxes

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 600

問題文

1 から N の番号がついた N 個の箱があります。最初、箱 i には A_i 個のボールが入っています。

あなたは次の操作を K 回繰り返します。

  • N 個の箱の中から等確率で 1 個選ぶ(この選択は操作ごとに独立である)。選んだ箱にボールを 1 個追加する。

K 回の操作が終了した後で箱 i に入っているボールの個数を B_i とするとき、スコアはボールの個数の総積 \prod_{i=1}^{N}B_i になります。

スコアの期待値を \bmod 998244353 で求めてください。

注意

求める期待値が既約分数 p/q で表されるとき、rq\equiv p \pmod{998244353} かつ 0\leq r < 998244353 を満たす整数 r がこの問題の制約のもとで一意に定まります。この r が求める値です。

制約

  • 1 \leq N \leq 1000
  • 1 \leq K \leq 10^9
  • 0 \leq A_i \leq 10^9

入力

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

N K
A_1 \ldots A_N

出力

答えを出力せよ。


入力例 1

3 1
1 2 3

出力例 1

665496245

操作の結果、スコアは次のようになります。

  • 操作で箱 1 を選んだとき、2\times 2\times 3=12
  • 操作で箱 2 を選んだとき、1\times 3\times 3=9
  • 操作で箱 3 を選んだとき、1\times 2\times 4=8

したがって、求める期待値は \frac{1}{3}(12+9+8)=\frac{29}{3} となります。これを \bmod 998244353 で表すと 665496245 になります。


入力例 2

2 2
1 2

出力例 2

499122182

操作の結果、スコアは次のようになります。

  • 1 回目の操作で箱 1 を選び、2 回目の操作で箱 1 を選んだとき、3\times 2=6
  • 1 回目の操作で箱 1 を選び、2 回目の操作で箱 2 を選んだとき、2\times 3=6
  • 1 回目の操作で箱 2 を選び、2 回目の操作で箱 1 を選んだとき、2\times 3=6
  • 1 回目の操作で箱 2 を選び、2 回目の操作で箱 2 を選んだとき、1\times 4=4

したがって、求める期待値は \frac{1}{4}(6+6+6+4)=\frac{11}{2} となります。


入力例 3

10 1000000000
998244350 998244351 998244352 998244353 998244354 998244355 998244356 998244357 998244358 998244359

出力例 3

138512322

Score : 600 points

Problem Statement

We have N boxes numbered 1 to N. Initially, Box i contains A_i balls.

You will repeat the following operation K times.

  • Choose one box out of the N uniformly at random (each time independently). Add one ball to the chosen box.

Let B_i be the number of balls in Box i after the K operations, and the score be the product of the numbers of balls, \prod_{i=1}^{N}B_i.

Find the expected value of the score modulo 998244353.

Notes

When the expected value in question is represented as an irreducible fraction p/q, there uniquely exists an integer r such that rq\equiv p \pmod{998244353} and 0\leq r < 998244353 under the Constraints of this problem. This r is the value we seek.

Constraints

  • 1 \leq N \leq 1000
  • 1 \leq K \leq 10^9
  • 0 \leq A_i \leq 10^9

Input

Input is given from Standard Input in the following format:

N K
A_1 \ldots A_N

Output

Print the answer.


Sample Input 1

3 1
1 2 3

Sample Output 1

665496245

After the operation, the score will be as follows.

  • When choosing Box 1 in the operation, 2\times 2\times 3=12.
  • When choosing Box 2 in the operation, 1\times 3\times 3=9.
  • When choosing Box 3 in the operation, 1\times 2\times 4=8.

Therefore, the expected value in question is \frac{1}{3}(12+9+8)=\frac{29}{3}. This value modulo 998244353 is 665496245.


Sample Input 2

2 2
1 2

Sample Output 2

499122182

After the operations, the score will be as follows.

  • When choosing Box 1 in the first operation and Box 1 in the second, 3\times 2=6.
  • When choosing Box 1 in the first operation and Box 2 in the second, 2\times 3=6.
  • When choosing Box 2 in the first operation and Box 1 in the second, 2\times 3=6.
  • When choosing Box 2 in the first operation and Box 2 in the second, 1\times 4=4.

Therefore, the expected value in question is \frac{1}{4}(6+6+6+4)=\frac{11}{2}.


Sample Input 3

10 1000000000
998244350 998244351 998244352 998244353 998244354 998244355 998244356 998244357 998244358 998244359

Sample Output 3

138512322
H - Minimum Coloring

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 600

問題文

HW 列のグリッドがあります。上から i 行目、左から j 列目のマスをマス (i,j) と表します。

グリッド上には 1 から N の番号がついた N 個の白い駒が置かれています。駒 i が置かれているマスは (A_i,B_i) です。

あなたはコストを C_i 払うことで、駒 i を黒い駒に変えることができます。

どの行どの列にも黒い駒が 1 個以上ある状態にするために必要なコストの和の最小値を求めてください。

制約

  • 1 \leq H,W \leq 10^3
  • 1 \leq N \leq 10^3
  • 1 \leq A_i \leq H
  • 1 \leq B_i \leq W
  • 1 \leq C_i \leq 10^9
  • (A_i,B_i) は相異なる
  • 全ての行、全ての列に 1 個以上の白い駒が置かれている
  • 入力に含まれる値は全て整数である

入力

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

H W N
A_1 B_1 C_1
\hspace{23pt} \vdots
A_N B_N C_N

出力

答えを出力せよ。


入力例 1

2 3 6
1 1 1
1 2 10
1 3 100
2 1 1000
2 2 10000
2 3 100000

出力例 1

1110

コスト 1110 を払い駒 2,3,4 を黒い駒に変えることで、どの行どの列にも黒い駒がある状態にすることができます。


入力例 2

1 7 7
1 2 200000000
1 7 700000000
1 4 400000000
1 3 300000000
1 6 600000000
1 5 500000000
1 1 100000000

出力例 2

2800000000

入力例 3

3 3 8
3 2 1
3 1 2
2 3 1
2 2 100
2 1 100
1 3 2
1 2 100
1 1 100

出力例 3

6

Score : 600 points

Problem Statement

We have a grid with H rows and W columns. Let (i,j) denote the square at the i-th row from the top and j-th column from the left.

On this grid, there are N white pieces numbered 1 to N. Piece i is on (A_i,B_i).

You can pay the cost of C_i to change Piece i to a black piece.

Find the minimum total cost needed to have at least one black piece in every row and every column.

Constraints

  • 1 \leq H,W \leq 10^3
  • 1 \leq N \leq 10^3
  • 1 \leq A_i \leq H
  • 1 \leq B_i \leq W
  • 1 \leq C_i \leq 10^9
  • All pairs (A_i,B_i) are distinct.
  • There is at least one white piece in every row and every column.
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

H W N
A_1 B_1 C_1
\hspace{23pt} \vdots
A_N B_N C_N

Output

Print the answer.


Sample Input 1

2 3 6
1 1 1
1 2 10
1 3 100
2 1 1000
2 2 10000
2 3 100000

Sample Output 1

1110

By paying the cost of 1110 to change Pieces 2, 3, 4 to black pieces, we can have a black piece in every row and every column.


Sample Input 2

1 7 7
1 2 200000000
1 7 700000000
1 4 400000000
1 3 300000000
1 6 600000000
1 5 500000000
1 1 100000000

Sample Output 2

2800000000

Sample Input 3

3 3 8
3 2 1
3 1 2
2 3 1
2 2 100
2 1 100
1 3 2
1 2 100
1 1 100

Sample Output 3

6