A - Thermometer

実行時間制限: 2 sec / メモリ制限: 1024 MiB

配点 : 100

問題文

高橋君は自分の体温を計測し、 X {}^\circC であることがわかりました。

体温は次の 3 種類に分類されます。

  • 38.0 {}^\circC 以上のとき「高熱」
  • 37.5 {}^\circC 以上 38.0 {}^\circC 未満のとき「発熱」
  • 37.5 {}^\circC 未満のとき「平熱」

高橋君の体温は何に分類されるでしょうか?「出力」の項にしたがって整数で出力してください。

制約

  • 30 \leq X \leq 50
  • X は小数第一位まで与えられる

入力

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

X

出力

高橋君の体温が何に分類されるかを以下に定められる整数で出力せよ。

  • 高熱の場合: 1
  • 発熱の場合: 2
  • 平熱の場合: 3

入力例 1

40.0

出力例 1

1

高橋君の体温は 40.0 {}^\circC であるため、高熱に分類されます。よって、1 を出力します。


入力例 2

37.7

出力例 2

2

高橋君の体温は 37.7 {}^\circC であるため、発熱に分類されます。よって、2 を出力します。


入力例 3

36.6

出力例 3

3

高橋君の体温は 36.6 {}^\circC であるため、平熱に分類されます。よって、3 を出力します。

Score : 100 points

Problem Statement

Takahashi measured his body temperature and found it to be X {}^\circC.

Body temperature is classified into the following:

  • Higher than or equal to 38.0 {}^\circC: “High fever”
  • Higher than or equal to 37.5 {}^\circC and lower than 38.0 {}^\circC: “Fever”
  • Lower than 37.5 {}^\circC: “Normal”

Which classification does Takahashi's body temperature fall into? Present the answer as an integer according to the Output section.

Constraints

  • 30 \leq X \leq 50
  • X is given to one decimal place.

Input

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

X

Output

Print an integer specified below corresponding to Takahashi's body temperature classification.

  • High fever: 1
  • Fever: 2
  • Normal: 3

Sample Input 1

40.0

Sample Output 1

1

His body temperature is 40.0 {}^\circC, which is classified as a high fever. Thus, print 1.


Sample Input 2

37.7

Sample Output 2

2

His body temperature is 37.7 {}^\circC, which is classified as a fever. Thus, print 2.


Sample Input 3

36.6

Sample Output 3

3

His body temperature is 36.6 {}^\circC, which is classified as a normal temperature. Thus, print 3.

B - Ticket Gate Log

実行時間制限: 2 sec / メモリ制限: 1024 MiB

配点 : 250

問題文

高橋君は改札機の利用履歴を集計しました。 しかし、高橋君はうっかりいくつかの入退場記録を消してしまいました。 高橋君は消してしまった記録の復元を試みようとしています。

i, o のみからなる文字列 S が与えられます。 S の任意の位置に文字を 0 文字以上挿入することで、変更後の文字列が以下の条件を満たすようにしたいです。

  • 長さが偶数であり、奇数文字目が i で偶数文字目が o である。

挿入する必要のある文字数の最小値を求めて下さい。なお、問題の制約下で、有限個の文字を適切に挿入することで、S が条件をみたすようにできることが証明できます。

制約

  • Si, o からなる長さ 1 以上 100 以下の文字列

入力

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

S

出力

答えを出力せよ。


入力例 1

ioi

出力例 1

1

3 文字目のあとに o を挿入して ioio とすることで、条件を満たすことができます。0 文字以下の挿入で条件を満たすことはできません。


入力例 2

iioo

出力例 2

2

1 文字目のあとに o を、3 文字目のあとに i を挿入することで、条件を満たすことができます。1 文字以下の挿入で条件を満たすことはできません。


入力例 3

io

出力例 3

0

S がすでに条件を満たします。

Score : 250 points

Problem Statement

Takahashi aggregated usage records from ticket gates. However, he accidentally erased some records of entering and exiting stations. He is trying to restore the erased records.

You are given a string S consisting of i and o. We want to insert zero or more characters at arbitrary positions in S so that the resulting string satisfies the following conditions:

  • Its length is even, and every odd-numbered (1st, 3rd, ...) character is i while every even-numbered (2nd, 4th, ...) character is o.

Find the minimum number of characters that need to be inserted. It can be proved under the constraints of this problem that by inserting an appropriate finite number of characters, S can be made to satisfy the conditions.

Constraints

  • S is a string of length between 1 and 100, consisting of i and o.

Input

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

S

Output

Print the answer.


Sample Input 1

ioi

Sample Output 1

1

We can insert o after the 3rd character to form ioio to satisfy the conditions. The conditions cannot be satisfied by inserting zero or fewer characters.


Sample Input 2

iioo

Sample Output 2

2

We can insert o after the 1st character and i after the 3rd character to satisfy the conditions. The conditions cannot be satisfied by inserting one or fewer characters.


Sample Input 3

io

Sample Output 3

0

S already satisfies the conditions.

C - Variety Split Easy

実行時間制限: 2 sec / メモリ制限: 1024 MiB

配点 : 350

問題文

この問題は F 問題の簡易版です。

長さ N の整数列 A=(A_1,A_2,\ldots,A_N) が与えられます。

A1 か所で区切って 2 個の空でない連続する部分列に分割するとき、数列に含まれる数の種類数の和としてありえる最大値を求めてください。

より厳密には、1 \leq i \leq N-1 を満たす整数 i について (A_1,A_2,\ldots,A_i), (A_{i+1},A_{i+2},\ldots,A_N) のそれぞれに含まれる整数の種類数の和としてありえる最大値を求めてください。

制約

  • 2 \leq N \leq 3 \times 10^5
  • 1 \leq A_i \leq N (1 \leq i \leq N)
  • 入力はすべて整数である

入力

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

N
A_1 A_2 \ldots A_N

出力

答えを出力せよ。


入力例 1

5
3 1 4 1 5

出力例 1

5
  • i=1 としたとき、(3)(1,4,1,5) のそれぞれに含まれる整数の種類数は 1,3 で、これらの和は 4 です。
  • i=2 としたとき、(3,1)(4,1,5) のそれぞれに含まれる整数の種類数は 2,3 で、これらの和は 5 です。
  • i=3 としたとき、(3,1,4)(1,5) のそれぞれに含まれる整数の種類数は 3,2 で、これらの和は 5 です。
  • i=4 としたとき、(3,1,4,1)(5) のそれぞれに含まれる整数の種類数は 3,1 で、これらの和は 4 です。

よって、 i=2,3 のときに、最大値 5 を取ります。


入力例 2

10
2 5 6 5 2 1 7 9 7 2

出力例 2

8

Score : 350 points

Problem Statement

This problem is a simplified version of Problem F.

You are given an integer sequence of length N: A = (A_1, A_2, \ldots, A_N).

When splitting A at one position into two non-empty (contiguous) subarrays, find the maximum possible sum of the counts of distinct integers in those subarrays.

More formally, find the maximum sum of the following two values for an integer i such that 1 \leq i \leq N-1: the count of distinct integers in (A_1, A_2, \ldots, A_i), and the count of distinct integers in (A_{i+1}, A_{i+2}, \ldots, A_N).

Constraints

  • 2 \leq N \leq 3 \times 10^5
  • 1 \leq A_i \leq N (1 \leq i \leq N)
  • All input values are integers.

Input

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

N
A_1 A_2 \ldots A_N

Output

Print the answer.


Sample Input 1

5
3 1 4 1 5

Sample Output 1

5
  • For i=1, (3) contains 1 distinct integer, and (1,4,1,5) contains 3 distinct integers, for a total of 4.
  • For i=2, (3,1) contains 2 distinct integers, and (4,1,5) contains 3 distinct integers, for a total of 5.
  • For i=3, (3,1,4) contains 3 distinct integers, and (1,5) contains 2 distinct integers, for a total of 5.
  • For i=4, (3,1,4,1) contains 3 distinct integers, and (5) contains 1 distinct integer, for a total of 4.

Therefore, the maximum sum is 5 for i=2,3.


Sample Input 2

10
2 5 6 5 2 1 7 9 7 2

Sample Output 2

8
D - Cubes

実行時間制限: 2 sec / メモリ制限: 1024 MiB

配点 : 425

問題文

正整数 N が与えられます。x^{3}-y^{3}=N を満たす正整数の組 (x,y) が存在するか判定し、存在する場合はそのような (x,y) を一つ出力してください。

制約

  • 1 \leq N \leq 10^{18}
  • 入力はすべて整数である

入力

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

N

出力

x^{3}-y^{3}=N を満たす正整数の組 (x,y) が存在しない場合は -1 を出力せよ。 存在する場合は、x,y を順番に空白区切りで出力せよ。答えが複数存在する場合、どれを出力しても正解とみなされる。


入力例 1

397

出力例 1

12 11

12^3-11^3=397 であるため、(x,y)=(12,11) が答えの一つです。


入力例 2

1

出力例 2

-1

x^3-y^3=1 となるような正整数の組 (x,y) は存在しません。よって、-1 を出力します。


入力例 3

39977273855577088

出力例 3

342756 66212

Score : 425 points

Problem Statement

You are given a positive integer N. Determine whether there exists a pair of positive integers (x,y) such that x^3 - y^3 = N. If such a pair exists, print one such pair (x,y).

Constraints

  • 1 \leq N \leq 10^{18}
  • All input values are integers.

Input

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

N

Output

If there is no pair of positive integers (x,y) satisfying x^3 - y^3 = N, print -1. If there is such a pair, print x and y in this order separated by a space. If there are multiple solutions, printing any one of them is accepted as correct.


Sample Input 1

397

Sample Output 1

12 11

We have 12^3 - 11^3 = 397, so (x,y) = (12,11) is a solution.


Sample Input 2

1

Sample Output 2

-1

No pair of positive integers (x,y) satisfies x^3 - y^3 = 1. Thus, print -1.


Sample Input 3

39977273855577088

Sample Output 3

342756 66212
E - Path Decomposition of a Tree

実行時間制限: 2 sec / メモリ制限: 1024 MiB

配点 : 475

問題文

NK 頂点の木が与えられます。頂点には 1,2,\dots,NK の番号がついており、i 番目 (i=1,2,\dots,NK-1) の辺は頂点 u_i,v_i を双方向に結んでいます。

この木を N 本の長さ K のパスに分解できるか判定してください。より詳細には、以下を満たす N \times K 行列 P が存在するかどうか判定してください。

  • P_{1,1},\dots,P_{1,K},P_{2,1},\dots,P_{N,K}1,2,\dots,NK の並べ替えである。
  • i=1,2,\dots,N,\;j=1,2,\dots,K-1 について、頂点 P_{i,j} と頂点 P_{i,j+1} を結ぶ辺が存在する。

制約

  • 1 \leq N
  • 1 \leq K
  • NK \leq 2 \times 10^5
  • 1 \leq u_i < v_i \leq NK
  • 与えられるグラフは木である
  • 入力はすべて整数

入力

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

N K
u_1 v_1
u_2 v_2
\vdots
u_{NK-1} v_{NK-1}

出力

N 本の長さ K のパスに分解できるなら Yes を、そうでないなら No を出力せよ。


入力例 1

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

出力例 1

Yes

頂点 1,2 からなるパス、頂点 3,4 からなるパス、頂点 5,6 からなるパスに分解することができます。


入力例 2

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

出力例 2

No

Score : 475 points

Problem Statement

You are given a tree with NK vertices. The vertices are numbered 1,2,\dots,NK, and the i-th edge (i=1,2,\dots,NK-1) connects vertices u_i and v_i bidirectionally.

Determine whether this tree can be decomposed into N paths, each of length K. More precisely, determine whether there exists an N \times K matrix P satisfying the following:

  • P_{1,1}, \dots, P_{1,K}, P_{2,1}, \dots, P_{N,K} is a permutation of 1,2,\dots,NK.
  • For each i=1,2,\dots,N and j=1,2,\dots,K-1, there is an edge connecting vertices P_{i,j} and P_{i,j+1}.

Constraints

  • 1 \leq N
  • 1 \leq K
  • NK \leq 2 \times 10^5
  • 1 \leq u_i < v_i \leq NK
  • The given graph is a tree.
  • All input values are integers.

Input

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

N K
u_1 v_1
u_2 v_2
\vdots
u_{NK-1} v_{NK-1}

Output

If it is possible to decompose the tree into N paths each of length K, print Yes. Otherwise, print No.


Sample Input 1

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

Sample Output 1

Yes

It can be decomposed into a path with vertices 1,2, a path with vertices 3,4, and a path with vertices 5,6.


Sample Input 2

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

Sample Output 2

No
F - Variety Split Hard

実行時間制限: 2 sec / メモリ制限: 1024 MiB

配点 : 550

問題文

この問題は C 問題の強化版です。分割する個数が 3 個になります。

長さ N の整数列 A=(A_1,A_2,\ldots,A_N) が与えられます。

A2 か所で区切って 3 個の空でない連続する部分列に分割するとき、数列に含まれる数の種類数の和としてありえる最大値を求めてください。

より厳密には、1 \leq i < j \leq N-1 を満たす整数の組 (i,j) について (A_1,A_2,\ldots,A_i) , (A_{i+1},A_{i+2},\ldots,A_j) , (A_{j+1},A_{j+2},\ldots,A_{N}) のそれぞれに含まれる整数の種類数の和としてありえる最大値を求めてください。

制約

  • 3 \leq N \leq 3 \times 10^5
  • 1 \leq A_i \leq N (1 \leq i \leq N)
  • 入力はすべて整数である

入力

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

N
A_1 A_2 \ldots A_N

出力

答えを出力せよ。


入力例 1

5
3 1 4 1 5

出力例 1

5

(i,j)=(2,4) とし、(3,1)(4,1)(5)3 つの連続する部分列に分割すると、それぞれに含まれる整数の種類数は 2,2,1 でこれらの和は 5 です。また、5 より大きい値は取り得ないので、答えは 5 です。他にも、(i,j)=(1,3),(2,3),(3,4) などでも種類数の和は 5 になります。


入力例 2

10
2 5 6 4 4 1 1 3 1 4

出力例 2

9

Score : 550 points

Problem Statement

This problem is a harder version of Problem C. Here, the sequence is split into three subarrays.

You are given an integer sequence of length N: A = (A_1, A_2, \ldots, A_N).

When splitting A at two positions into three non-empty (contiguous) subarrays, find the maximum possible sum of the counts of distinct integers in those subarrays.

More formally, find the maximum sum of the following three values for a pair of integers (i,j) such that 1 \leq i < j \leq N-1: the count of distinct integers in (A_1, A_2, \ldots, A_i), the count of distinct integers in (A_{i+1},A_{i+2},\ldots,A_j), and the count of distinct integers in (A_{j+1},A_{j+2},\ldots,A_{N}).

Constraints

  • 3 \leq N \leq 3 \times 10^5
  • 1 \leq A_i \leq N (1 \leq i \leq N)
  • All input values are integers.

Input

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

N
A_1 A_2 \ldots A_N

Output

Print the answer.


Sample Input 1

5
3 1 4 1 5

Sample Output 1

5

If we let (i,j) = (2,4) to split the sequence into three subarrays (3,1), (4,1), (5), the counts of distinct integers in those subarrays are 2, 2, 1, respectively, for a total of 5. This sum cannot be greater than 5, so the answer is 5. Other partitions, such as (i,j) = (1,3), (2,3), (3,4), also achieve this sum.


Sample Input 2

10
2 5 6 4 4 1 1 3 1 4

Sample Output 2

9
G - Maximize Distance

実行時間制限: 2 sec / メモリ制限: 1024 MiB

配点 : 625

問題文

N 頂点 M 辺の有向グラフが与えられます。頂点には 1,2,\dots,N の番号がついており、辺 j (j=1,2,\dots,M) は頂点 u_j から頂点 v_j に向かいます。ここで、頂点 1 から頂点 N に到達可能であることが保証されます。

はじめ、すべての辺の重みは 0 です。M 本の辺からちょうど K 本の辺を選んで重みを 1 に変更するとき、変更後のグラフにおける頂点 1 から頂点 N への最短距離としてあり得る最大値を求めてください。

制約

  • 2 \leq N \leq 30
  • 1 \leq K \leq M \leq 100
  • 1 \leq u_j,v_j \leq N
  • u_j \neq v_j
  • 与えられるグラフにおいて、頂点 1 から頂点 N へ到達可能である
  • 入力はすべて整数

入力

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

N M K
u_1 v_1
u_2 v_2
\vdots
u_M v_M

出力

答えを出力せよ。


入力例 1

3 3 2
1 2
2 3
1 3

出力例 1

1

1,3 を選べば、頂点 1 から頂点 3 への最短距離が 1 になります。最短距離を 2 以上にする選び方は存在しないので、答えは 1 です。


入力例 2

4 4 3
1 2
1 3
3 2
2 4

出力例 2

2

1,2,4 を選べば、頂点 1 から頂点 4 への最短距離が 2 になります。最短距離を 3 以上にする選び方は存在しないので、答えは 2 です。


入力例 3

2 2 1
1 2
1 2

出力例 3

0

多重辺が存在しうることに注意してください。

Score : 625 points

Problem Statement

You are given a directed graph with N vertices and M edges. The vertices are numbered 1,2,\dots,N. Edge j (j=1,2,\dots,M) goes from vertex u_j to vertex v_j. It is guaranteed that vertex N is reachable from vertex 1.

Initially, all edges have weight 0. We choose exactly K out of the M edges and change their weights to 1. Find the maximum possible value of the shortest distance from vertex 1 to vertex N in the resulting graph.

Constraints

  • 2 \leq N \leq 30
  • 1 \leq K \leq M \leq 100
  • 1 \leq u_j, v_j \leq N
  • u_j \neq v_j
  • In the given graph, vertex N is reachable from vertex 1.
  • All input values are integers.

Input

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

N M K
u_1 v_1
u_2 v_2
\vdots
u_M v_M

Output

Print the answer.


Sample Input 1

3 3 2
1 2
2 3
1 3

Sample Output 1

1

By choosing edges 1,3, the shortest distance from vertex 1 to vertex 3 becomes 1. There is no way to make the shortest distance 2 or greater, so the answer is 1.


Sample Input 2

4 4 3
1 2
1 3
3 2
2 4

Sample Output 2

2

By choosing edges 1,2,4, the shortest distance from vertex 1 to vertex 4 becomes 2. There is no way to make the shortest distance 3 or greater, so the answer is 2.


Sample Input 3

2 2 1
1 2
1 2

Sample Output 3

0

Note that there may be multi-edges.