E - Happy New Year!

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 300

問題文

10 進法で表記したときに 0,2 のみからなる正整数のうち、 K 番目に小さいものを求めてください。

制約

  • K1 以上 10^{18} 以下の整数

入力

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

K

出力

答えを整数として出力せよ。
ただし、たとえ答えが大きな整数であっても、求める答えを正確に整数として出力する必要がある。たとえば、 2.34e+22 のような指数表記や、 0523 のような先頭に不要な 0 を付けたような表記は許されない。


入力例 1

3

出力例 1

22

10 進法で表記した時に 0,2 のみからなる正整数を小さい方から並べると、 2,20,22,\dots となります。
このうち K=3 番目である 22 を出力してください。


入力例 2

11

出力例 2

2022

入力例 3

923423423420220108

出力例 3

220022020000202020002022022000002020002222002200002022002200

たとえ答えが大きな整数であっても、求める答えを正確に整数として出力する必要があることに注意してください。

Score : 300 points

Problem Statement

Among the positive integers that consist of 0's and 2's when written in base 10, find the K-th smallest integer.

Constraints

  • K is an integer between 1 and 10^{18} (inclusive).

Input

Input is given from Standard Input in the following format:

K

Output

Print the answer as an integer.
Here, the exact value must be printed as an integer, even if it is big. Exponential notations such as 2.34e+22, for example, or unnecessary leading zeros such as 0523 are not allowed.


Sample Input 1

3

Sample Output 1

22

The positive integers that consist of 0's and 2's when written in base 10 are 2,20,22,\dots in ascending order.
The (K=) 3-rd of them, which is 22, should be printed.


Sample Input 2

11

Sample Output 2

2022

Sample Input 3

923423423420220108

Sample Output 3

220022020000202020002022022000002020002222002200002022002200

Note that the exact value of the answer must be printed as an integer, even if it is big.

F - Repunit Trio

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 300

問題文

十進法ですべての桁の数字が 1 である整数をレピュニットと呼びます。レピュニットを小さい順に並べると 1,11,111,\ldots です。

ちょうど 3 つのレピュニットの和として表せる整数のうち N 番目に小さいものを求めてください。

制約

  • N1 以上 333 以下の整数

入力

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

N

出力

答えを出力せよ。


入力例 1

5

出力例 1

113

ちょうど 3 つのレピュニットの和として表せる整数を小さい順に並べると 3,13,23,33,113,\ldots です。例えば 113113=1+1+111 と表せます。

3 つのレピュニットは相異ならなくてもよいことに注意してください。


入力例 2

19

出力例 2

2333

入力例 3

333

出力例 3

112222222233

Score : 300 points

Problem Statement

A repunit is an integer whose digits are all 1 in decimal representation. The repunits in ascending order are 1, 11, 111, \ldots.

Find the N-th smallest integer that can be expressed as the sum of exactly three repunits.

Constraints

  • N is an integer between 1 and 333, inclusive.

Input

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

N

Output

Print the answer.


Sample Input 1

5

Sample Output 1

113

The integers that can be expressed as the sum of exactly three repunits are 3, 13, 23, 33, 113, \ldots in ascending order. For example, 113 can be expressed as 113 = 1 + 1 + 111.

Note that the three repunits do not have to be distinct.


Sample Input 2

19

Sample Output 2

2333

Sample Input 3

333

Sample Output 3

112222222233
G - Sum of Maximum Weights

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 400

問題文

N 頂点の木があり、頂点は 1, 2, \dots, N と番号付けられています。
i \, (1 \leq i \leq N - 1) 番目の辺は頂点 u_i と頂点 v_i を結び、重みは w_i です。

異なる頂点 u, v に対し、頂点 u から頂点 v までの最短パスに含まれる辺の重みの最大値を f(u, v) とおきます。

\displaystyle \sum_{i = 1}^{N - 1} \sum_{j = i + 1}^N f(i, j) を求めてください。

制約

  • 2 \leq N \leq 10^5
  • 1 \leq u_i, v_i \leq N
  • 1 \leq w_i \leq 10^7
  • 与えられるグラフは木である。
  • 入力は全て整数である。

入力

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

N
u_1 v_1 w_1
\vdots
u_{N - 1} v_{N - 1} w_{N - 1}

出力

答えを出力せよ。


入力例 1

3
1 2 10
2 3 20

出力例 1

50

f(1, 2) = 10, f(2, 3) = 20, f(1, 3) = 20 であるので、これらの和である 50 を出力します。


入力例 2

5
1 2 1
2 3 2
4 2 5
3 5 14

出力例 2

76

Score : 400 points

Problem Statement

We have a tree with N vertices numbered 1, 2, \dots, N.
The i-th edge (1 \leq i \leq N - 1) connects Vertex u_i and Vertex v_i and has a weight w_i.

For different vertices u and v, let f(u, v) be the greatest weight of an edge contained in the shortest path from Vertex u to Vertex v.

Find \displaystyle \sum_{i = 1}^{N - 1} \sum_{j = i + 1}^N f(i, j).

Constraints

  • 2 \leq N \leq 10^5
  • 1 \leq u_i, v_i \leq N
  • 1 \leq w_i \leq 10^7
  • 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 w_1
\vdots
u_{N - 1} v_{N - 1} w_{N - 1}

Output

Print the answer.


Sample Input 1

3
1 2 10
2 3 20

Sample Output 1

50

We have f(1, 2) = 10, f(2, 3) = 20, and f(1, 3) = 20, so we should print their sum, or 50.


Sample Input 2

5
1 2 1
2 3 2
4 2 5
3 5 14

Sample Output 2

76
H - Karuta

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 500

問題文

英小文字からなる文字列が N 個与えられます。i \, (i = 1, 2, \dots, N) 番目のものを S_i と表します。

二つの文字列 x, y に対し、以下の条件を全て満たす最大の整数 n\mathrm{LCP}(x, y) と表します。

  • x, y の長さはいずれも n 以上
  • 1 以上 n 以下の全ての整数 i に対し、xi 文字目と yi 文字目が等しい

全ての i = 1, 2, \dots, N に対し、以下の値を求めてください。

  • \displaystyle \max_{i \neq j} \mathrm{LCP}(S_i, S_j)

制約

  • 2 \leq N \leq 5 \times 10^5
  • N は整数
  • S_i は英小文字からなる長さ 1 以上の文字列 (i = 1, 2, \dots, N)
  • S_i の長さの総和は 5 \times 10^5 以下

入力

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

N
S_1
S_2
\vdots
S_N

出力

N 行出力せよ。i \, (i = 1, 2, \dots, N) 行目には、\displaystyle \max_{i \neq j} \mathrm{LCP}(S_i, S_j) を出力せよ。


入力例 1

3
abc
abb
aac

出力例 1

2
2
1

\mathrm{LCP}(S_1, S_2) = 2, \mathrm{LCP}(S_1, S_3) = 1, \mathrm{LCP}(S_2, S_3) = 1 です。


入力例 2

11
abracadabra
bracadabra
racadabra
acadabra
cadabra
adabra
dabra
abra
bra
ra
a

出力例 2

4
3
2
1
0
1
0
4
3
2
1

Score : 500 points

Problem Statement

You are given N strings consisting of lowercase English letters. Let S_i be the i-th (i = 1, 2, \dots, N) of them.

For two strings x and y, \mathrm{LCP}(x, y) is defined to be the maximum integer n that satisfies all of the following conditions:

  • The lengths of x and y are both at least n.
  • For all integers i between 1 and n, inclusive, the i-th character of x and that of y are equal.

Find the following value for all i = 1, 2, \dots, N:

  • \displaystyle \max_{i \neq j} \mathrm{LCP}(S_i, S_j)

Constraints

  • 2 \leq N \leq 5 \times 10^5
  • N is an integer.
  • S_i is a string of length at least 1 consisting of lowercase English letters (i = 1, 2, \dots, N).
  • The sum of lengths of S_i is at most 5 \times 10^5.

Input

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

N
S_1
S_2
\vdots
S_N

Output

Print N lines. The i-th (i = 1, 2, \dots, N) line should contain \displaystyle \max_{i \neq j} \mathrm{LCP}(S_i, S_j).


Sample Input 1

3
abc
abb
aac

Sample Output 1

2
2
1

\mathrm{LCP}(S_1, S_2) = 2, \mathrm{LCP}(S_1, S_3) = 1, and \mathrm{LCP}(S_2, S_3) = 1.


Sample Input 2

11
abracadabra
bracadabra
racadabra
acadabra
cadabra
adabra
dabra
abra
bra
ra
a

Sample Output 2

4
3
2
1
0
1
0
4
3
2
1
I - Regular Triangle Inside a Rectangle

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 500

問題文

縦の長さが A、横の長さが B の長方形の内部に描ける正三角形の一辺の長さの最大値を求めてください。

制約

  • 1 \leq A,B \leq 1000
  • A,B は整数

入力

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

A B

出力

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


入力例 1

1 1

出力例 1

1.03527618041008295791

下図のように描くのが最適で、一辺の長さが \sqrt{6} - \sqrt{2} になります。

image

なお、この出力例の値は \sqrt{6}- \sqrt{2} と厳密には一致しませんが、誤差が 10^{-9} 以下なので正解として扱われます。

Score : 500 points

Problem Statement

Find the maximum side length of a regular triangle that can be drawn within a rectangle whose side lengths are A and B.

Constraints

  • 1 \leq A,B \leq 1000
  • A and B are integers.

Input

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

A B

Output

Print the answer.
Your output is considered correct if the absolute or relative error from the true answer is at most 10^{-9}.


Sample Input 1

1 1

Sample Output 1

1.03527618041008295791

The following figure shows an optimal drawing, with the side length of \sqrt{6} - \sqrt{2}.

image

Note that the sample output does not strictly match \sqrt{6}- \sqrt{2}, but the error is within 10^{-9}, so it is considered correct.