Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 100 点
問題文
初項が A、末項が B、公差が D であるような等差数列を出力してください。
なお、そのような等差数列が存在する入力のみが与えられます。
制約
- 1 \leq A \leq B \leq 100
- 1\leq D \leq 100
- 初項が A、末項が B、公差が D であるような等差数列が存在する
- 入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。
A B D
出力
初項が A、末項が B、公差が D であるような等差数列の項を順に空白区切りで出力せよ。
入力例 1
3 9 2
出力例 1
3 5 7 9
初項が 3、末項が 9、公差が 2 であるような等差数列は (3,5,7,9) です。
入力例 2
10 10 1
出力例 2
10
初項が 10、末項が 10、公差が 1 であるような等差数列は (10) です。
Score: 100 points
Problem Statement
Print an arithmetic sequence with first term A, last term B, and common difference D.
You are only given inputs for which such an arithmetic sequence exists.
Constraints
- 1 \leq A \leq B \leq 100
- 1 \leq D \leq 100
- There is an arithmetic sequence with first term A, last term B, and common difference D.
- All input values are integers.
Input
The input is given from Standard Input in the following format:
A B D
Output
Print the terms of the arithmetic sequence with first term A, last term B, and common difference D, in order, separated by spaces.
Sample Input 1
3 9 2
Sample Output 1
3 5 7 9
The arithmetic sequence with first term 3, last term 9, and common difference 2 is (3,5,7,9).
Sample Input 2
10 10 1
Sample Output 2
10
The arithmetic sequence with first term 10, last term 10, and common difference 1 is (10).
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 100 点
問題文
英小文字からなる N 個の文字列 W_1,W_2,\dots,W_N が与えられます。
これらのうち一つ以上が and, not, that, the, you のいずれかと一致するなら Yes 、そうでないなら No と出力してください。
制約
- N は 1 以上 100 以下の整数
- 1 \le |W_i| \le 50 ( |W_i| は文字列 W_i の長さ )
- W_i は英小文字からなる
入力
入力は以下の形式で標準入力から与えられる。
N W_1 W_2 \dots W_N
出力
答えを出力せよ。
入力例 1
10 in that case you should print yes and not no
出力例 1
Yes
例えば W_4= you なので、 Yes と出力します。
入力例 2
10 in diesem fall sollten sie no und nicht yes ausgeben
出力例 2
No
文字列 W_i はいずれも、 and, not, that, the, you のいずれとも一致しません。
Score : 100 points
Problem Statement
You are given N strings W_1,W_2,\dots,W_N consisting of lowercase English letters.
If one or more of these strings equal and, not, that, the, or you, then print Yes; otherwise, print No.
Constraints
- N is an integer between 1 and 100, inclusive.
- 1 \le |W_i| \le 50 (|W_i| is the length of W_i.)
- W_i consists of lowercase English letters.
Input
The input is given from Standard Input in the following format:
N W_1 W_2 \dots W_N
Output
Print the answer.
Sample Input 1
10 in that case you should print yes and not no
Sample Output 1
Yes
We have, for instance, W_4= you, so you should print Yes.
Sample Input 2
10 in diesem fall sollten sie no und nicht yes ausgeben
Sample Output 2
No
None of the strings W_i equals any of and, not, that, the, and you.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
正整数 N, M が与えられます。
X = \displaystyle\sum_{i = 0}^{M} N^i とします。X \leq 10^9 のときは X の値を、X > 10^9 のときは文字列 inf を出力してください。
制約
- 1 \leq N \leq 10^9
- 1 \leq M \leq 100
- 入力される値はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N M
出力
問題文の指示に従って X の値あるいは inf を出力せよ。
入力例 1
7 3
出力例 1
400
X = 1 + 7 + 49 + 343 = 400 です。400 \leq 10^9 であるため 400 を出力します。
入力例 2
1000000 2
出力例 2
inf
X = 1000001000001 > 10^9 であるため、inf を出力します。
入力例 3
999999999 1
出力例 3
1000000000
入力例 4
998244353 99
出力例 4
inf
Score : 200 points
Problem Statement
You are given two positive integers N and M.
Let X = \displaystyle\sum_{i = 0}^{M} N^i. If X \leq 10^9, print the value of X. If X > 10^9, print inf.
Constraints
- 1 \leq N \leq 10^9
- 1 \leq M \leq 100
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N M
Output
Print the value of X or inf as specified by the problem statement.
Sample Input 1
7 3
Sample Output 1
400
X = 1 + 7 + 49 + 343 = 400. Since 400 \leq 10^9, print 400.
Sample Input 2
1000000 2
Sample Output 2
inf
X = 1000001000001 > 10^9, so print inf.
Sample Input 3
999999999 1
Sample Output 3
1000000000
Sample Input 4
998244353 99
Sample Output 4
inf
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
N 人の客がおり、1 から N までの番号が付けられています。また、M 本の缶ジュースがあり、1 から M までの番号が付けられています。
客 i (1 \leq i \leq N) は長さ L_i の希望リストを持っています。客 i の希望リストの先頭から j 番目 (1 \leq j \leq L_i) は缶ジュース X_{i,j} です。任意の客 i に対して、客 i の希望リストに載っている番号 X_{i, 1}, \dots, X_{i, L_i} は相異なります。
これから客 1, \dots, N が番号の小さいほうから順に、以下にしたがって自分が飲む飲料を選びます。
- その時点で誰にも選ばれていない缶ジュースの番号が自分の希望リストに存在する場合、そのうち先頭に最も近い番号の缶ジュースを選ぶ。そうでない場合は水を選ぶ。
それぞれの客がどの飲料を得るかを求めてください。
制約
- 1 \leq N \leq 100
- 1 \leq M \leq 100
- 1 \leq L_i \leq M (1 \leq i \leq N)
- 1 \leq X_{i,j} \leq M (1 \leq i \leq N, 1 \leq j \leq L_i)
- X_{i, 1}, \dots, X_{i, L_i} は相異なる (1 \leq i \leq N)
- 入力される値はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N M
L_1
X_{1,1} X_{1,2} \cdots X_{1,L_1}
L_2
X_{2,1} X_{2,2} \cdots X_{2,L_2}
\vdots
L_N
X_{N,1} X_{N,2} \cdots X_{N,L_N}
出力
N 行出力せよ。i 行目 (1 \leq i \leq N) には、客 i が缶ジュースを得る場合はその番号を、水を得る場合は 0 を出力せよ。
入力例 1
4 5 3 3 1 2 3 3 2 1 2 2 3 4 2 5 3 1
出力例 1
3 2 0 5
客 1 の希望リストにある番号のうち、対応する缶ジュースが誰にも選ばれていないのは 3,1,2 です。このうち先頭に最も近いのは 3 なので、客 1 は缶ジュース 3 を選びます。
客 2 の希望リストにある番号のうち、対応する缶ジュースが誰にも選ばれていないのは 2,1 です。このうち先頭に最も近いのは 2 なので、客 2 は缶ジュース 2 を選びます。
客 3 の希望リストにある番号について、対応する缶ジュースはすべてその時点で誰かに選ばれています。よって客 3 は水を選びます。
客 4 の希望リストにある番号のうち、対応する缶ジュースが誰にも選ばれていないのは 5,1 です。このうち先頭に最も近いのは 5 なので、客 4 は缶ジュース 5 を選びます。
入力例 2
6 5 1 3 2 3 5 5 5 3 1 4 2 5 5 1 3 4 2 5 3 4 1 5 2 5 5 1 3 2 4
出力例 2
3 5 1 4 2 0
Score : 200 points
Problem Statement
There are N customers numbered 1 to N, and M canned juices numbered 1 to M.
Customer i (1 \leq i \leq N) has a wish list of length L_i. The j-th item (1 \leq j \leq L_i) from the top of customer i's wish list is canned juice X_{i,j}. For any customer i, the numbers X_{i, 1}, \dots, X_{i, L_i} on customer i's wish list are distinct.
Customers 1, \dots, N, in this order, will now choose their beverages, following the procedure below.
- If the customer's wish list contains a canned juice that has not yet been chosen by anyone at that point, they choose the canned juice whose number appears earliest in their wish list. Otherwise, they choose water.
Determine which beverage each customer gets.
Constraints
- 1 \leq N \leq 100
- 1 \leq M \leq 100
- 1 \leq L_i \leq M (1 \leq i \leq N)
- 1 \leq X_{i,j} \leq M (1 \leq i \leq N, 1 \leq j \leq L_i)
- X_{i, 1}, \dots, X_{i, L_i} are distinct. (1 \leq i \leq N)
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N M
L_1
X_{1,1} X_{1,2} \cdots X_{1,L_1}
L_2
X_{2,1} X_{2,2} \cdots X_{2,L_2}
\vdots
L_N
X_{N,1} X_{N,2} \cdots X_{N,L_N}
Output
Output N lines. The i-th line (1 \leq i \leq N) should contain the number of the canned juice customer i gets if they get one, or 0 if customer i gets water.
Sample Input 1
4 5 3 3 1 2 3 3 2 1 2 2 3 4 2 5 3 1
Sample Output 1
3 2 0 5
Among the numbers on customer 1's wish list, the canned juices not yet chosen by anyone are 3, 1, 2. The one appearing earliest in the list is 3, so customer 1 chooses canned juice 3.
Among the numbers on customer 2's wish list, the canned juices not yet chosen by anyone are 2, 1. The one appearing earliest in the list is 2, so customer 2 chooses canned juice 2.
For the numbers on customer 3's wish list, all corresponding canned juices have already been chosen by someone at that point. Thus, customer 3 chooses water.
Among the numbers on customer 4's wish list, the canned juices not yet chosen by anyone are 5, 1. The one appearing earliest in the list is 5, so customer 4 chooses canned juice 5.
Sample Input 2
6 5 1 3 2 3 5 5 5 3 1 4 2 5 5 1 3 4 2 5 3 4 1 5 2 5 5 1 3 2 4
Sample Output 2
3 5 1 4 2 0
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
正整数 x,y に対して f(x,y) を「(x+y) を 10^8 で割ったあまり」として定義します。
長さ N の正整数列 A=(A_1,\ldots,A_N) が与えられます。次の式の値を求めてください。
制約
- 2\leq N\leq 3\times 10^5
- 1\leq A_i < 10^8
- 入力される数値は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N A_1 \ldots A_N
出力
答えを出力せよ。
入力例 1
3 3 50000001 50000002
出力例 1
100000012
- f(A_1,A_2)=50000004
- f(A_1,A_3)=50000005
- f(A_2,A_3)=3
なので、答えは f(A_1,A_2)+f(A_1,A_3)+f(A_2,A_3) = 100000012 です。
総和を 10^8 で割ったあまりを求めるわけではないことに注意してください。
入力例 2
5 1 3 99999999 99999994 1000000
出力例 2
303999988
Score: 300 points
Problem Statement
For positive integers x and y, define f(x, y) as the remainder of (x + y) divided by 10^8.
You are given a sequence of positive integers A = (A_1, \ldots, A_N) of length N. Find the value of the following expression:
Constraints
- 2 \leq N \leq 3\times 10^5
- 1 \leq A_i < 10^8
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N A_1 \ldots A_N
Output
Print the answer.
Sample Input 1
3 3 50000001 50000002
Sample Output 1
100000012
- f(A_1,A_2)=50000004
- f(A_1,A_3)=50000005
- f(A_2,A_3)=3
Thus, the answer is f(A_1,A_2) + f(A_1,A_3) + f(A_2,A_3) = 100000012.
Note that you are not asked to compute the remainder of the sum divided by 10^8.
Sample Input 2
5 1 3 99999999 99999994 1000000
Sample Output 2
303999988
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
高橋君はレベル N の赤い宝石を 1 個持っています。(他に宝石は持っていません。)
高橋君は次の操作を好きなだけ行うことができます。
- レベル n の赤い宝石 (n は 2 以上) を「レベル n-1 の赤い宝石 1 個と、レベル n の青い宝石 X 個」に変換する。
- レベル n の青い宝石 (n は 2 以上) を「レベル n-1 の赤い宝石 1 個と、レベル n-1 の青い宝石 Y 個」に変換する。
高橋君はレベル 1 の青い宝石ができるだけたくさんほしいです。操作によって高橋君はレベル 1 の青い宝石を最大何個入手できますか?
制約
- 1 \leq N \leq 10
- 1 \leq X \leq 5
- 1 \leq Y \leq 5
- 入力される値はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N X Y
出力
答えを出力せよ。
入力例 1
2 3 4
出力例 1
12
次のような変換を行うことで、高橋君はレベル 1 の青い宝石を 12 個手に入れることができます。
- まず、レベル 2 の赤い宝石 1 個を、レベル 1 の赤い宝石 1 個とレベル 2 の青い宝石 3 個に変換します。
- 操作後の高橋君は、レベル 1 の赤い宝石 1 個とレベル 2 の青い宝石 3 個を持っています。
- 次に、レベル 2 の青い宝石 1 個を、レベル 1 の赤い宝石 1 個とレベル 1 の青い宝石 4 個に変換します。この変換を 3 回繰り返します。
- 操作後の高橋君は、レベル 1 の赤い宝石 4 個とレベル 1 の青い宝石 12 個を持っています。
- これ以上変換を行うことはできません。
12 個より多くレベル 1 の青い宝石を手に入れることはできないので、答えは 12 になります。
入力例 2
1 5 5
出力例 2
0
高橋君がレベル 1 の青い宝石を 1 個も手に入れられない場合もあります。
入力例 3
10 5 5
出力例 3
3942349900
答えが 32 bit 整数に収まらない場合があることに注意してください。
Score : 300 points
Problem Statement
Takahashi has a red jewel of level N. (He has no other jewels.)
Takahashi can do the following operations any number of times.
- Convert a red jewel of level n (n is at least 2) into "a red jewel of level (n-1) and X blue jewels of level n".
- Convert a blue jewel of level n (n is at least 2) into "a red jewel of level (n-1) and Y blue jewels of level (n-1)".
Takahashi wants as many blue jewels of level 1 as possible. At most, how many blue jewels of level 1 can he obtain by the operations?
Constraints
- 1 \leq N \leq 10
- 1 \leq X \leq 5
- 1 \leq Y \leq 5
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N X Y
Output
Print the answer.
Sample Input 1
2 3 4
Sample Output 1
12
Takahashi can obtain 12 blue jewels of level 1 by the following conversions.
- First, he converts a red jewel of level 2 into a red jewel of level 1 and 3 blue jewels of level 2.
- After this operation, Takahashi has 1 red jewel of level 1 and 3 blue jewels of level 2.
- Next, he repeats the following conversion 3 times: converting a blue jewel of level 2 into a red jewel of level 1 and 4 blue jewels of level 1.
- After these operations, Takahashi has 4 red jewels of level 1 and 12 blue jewels of level 1.
- He cannot perform a conversion anymore.
He cannot obtain more than 12 blue jewels of level 1, so the answer is 12.
Sample Input 2
1 5 5
Sample Output 2
0
Takahashi may not be able to obtain a blue jewel of level 1.
Sample Input 3
10 5 5
Sample Output 3
3942349900
Note that the answer may not fit into a 32-bit integer type.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 425 点
問題文
N 頂点 M 辺の単純無向グラフ G があります。頂点には 1, 2, \ldots, N の番号が付けられており、i 番目の辺は頂点 A_i と頂点 B_i を結ぶ無向辺です。
あなたは、以下の 2 つの操作を好きな順序で好きな回数繰り返すことができます。
- G に無向辺を 1 つ追加する
- G から無向辺を 1 つ削除する
G をすべての頂点の次数が 2 である単純無向グラフにするために行う操作回数として考えられる最小値を求めてください。
単純無向グラフとは
単純無向グラフとは、自己ループと多重辺を持たない無向グラフのことを指します。
制約
- 3 \leq N \leq 8
- 0 \leq M \leq \frac{N(N-1)}{2}
- 入力で与えられるグラフ G は単純無向グラフ
- 入力される値はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N M A_1 B_1 \vdots A_M B_M
出力
答えを出力せよ。
入力例 1
5 4 1 2 1 5 2 4 4 5
出力例 1
3
例えば以下のようにすることで、3 回の操作で G をすべての頂点の次数が 2 の単純無向グラフにすることができます。
- 頂点 2 と頂点 3 を結ぶ辺を追加する。
- 頂点 2 と頂点 4 を結ぶ辺を削除する。
- 頂点 3 と頂点 4 を結ぶ辺を追加する。
入力例 2
3 0
出力例 2
3
入力例 3
6 8 1 4 1 5 2 3 2 6 3 4 3 6 4 5 4 6
出力例 3
2
入力例 4
8 21 1 4 5 7 8 4 3 4 2 5 8 1 5 1 2 8 2 1 2 4 3 1 6 7 5 8 2 7 6 8 5 4 3 8 7 3 7 8 5 3 7 4
出力例 4
13
Score : 425 points
Problem Statement
There is a simple undirected graph G with N vertices and M edges. The vertices are numbered 1, 2, \ldots, N, and the i-th edge is an undirected edge connecting vertices A_i and B_i.
You can repeat the following two operations in any order and any number of times:
- Add one undirected edge to G
- Remove one undirected edge from G
Find the minimum number of operations to make G a simple undirected graph where all vertices have degree 2.
What is a simple undirected graph?
A simple undirected graph refers to an undirected graph that has no self-loops and no multi-edges.
Constraints
- 3 \leq N \leq 8
- 0 \leq M \leq \frac{N(N-1)}{2}
- The graph G given in the input is a simple undirected graph.
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N M A_1 B_1 \vdots A_M B_M
Output
Output the answer.
Sample Input 1
5 4 1 2 1 5 2 4 4 5
Sample Output 1
3
For example, the following three operations make G a simple undirected graph where all vertices have degree 2.
- Add an edge connecting vertices 2 and 3.
- Remove the edge connecting vertices 2 and 4.
- Add an edge connecting vertices 3 and 4.
Sample Input 2
3 0
Sample Output 2
3
Sample Input 3
6 8 1 4 1 5 2 3 2 6 3 4 3 6 4 5 4 6
Sample Output 3
2
Sample Input 4
8 21 1 4 5 7 8 4 3 4 2 5 8 1 5 1 2 8 2 1 2 4 3 1 6 7 5 8 2 7 6 8 5 4 3 8 7 3 7 8 5 3 7 4
Sample Output 4
13
Time Limit: 3 sec / Memory Limit: 1024 MiB
配点 : 500 点
問題文
英小文字のみからなる文字列 X に対し、以下の手続きによって文字列を得ることを考えます。
- X を異なる文字が隣り合っている部分で分割する。
- 分割した各文字列 Y に対して、Y を Y を構成する文字と Y の長さを繋げた文字列に置き換える。
- 元の順番を保ったまま、置き換えた文字列をすべて繋げる。
例えば、aaabbcccc の場合、aaa,bb,cccc に分けられ、それぞれを a3,b2,c4 に置き換え、その順番のまま繋げることにより a3b2c4 を得ます。また、aaaaaaaaaa の場合、a10 になります。
長さ N の英小文字のみからなる文字列 S のうち、上記の手続きによって得られた文字列 T との長さを比べたとき、T の方が短いものの個数を P で割ったあまりを求めてください。
制約
- 1 \le N \le 3000
- 10^8 \le P \le 10^9
- N,P は整数
- P は素数
入力
入力は以下の形式で標準入力から与えられる。
N P
出力
答えを出力せよ。
入力例 1
3 998244353
出力例 1
26
1,2,3 文字目が全て等しい文字列のみが条件を満たします。
例えば、aaa は a3 となり条件を満たしますが、abc は a1b1c1 となり条件を満たしません。
入力例 2
2 998244353
出力例 2
0
aa → a2 のように、長さが等しいものは条件を満たさないことに注意してください。
入力例 3
5 998244353
出力例 3
2626
aaabb や aaaaa などが条件を満たします。
入力例 4
3000 924844033
出力例 4
607425699
条件を満たす文字列の個数を P で割ったあまりを求めてください。
Score : 500 points
Problem Statement
Consider the following procedure of, given a string X consisting of lowercase English alphabets, obtaining a new string:
- Split the string X off at the positions where two different characters are adjacent to each other.
- For each string Y that has been split off, replace Y with a string consisting of the character which Y consists of, followed by the length of Y.
- Concatenate the replaced strings without changing the order.
For example, aaabbcccc is divided into aaa,bb,cccc, which are replaced by a3,b2,c4, respectively, which in turn are concatenated without changing the order, resulting in a3b2c4.If the given string is aaaaaaaaaa , the new string is a10 .
Find the number, modulo P, of strings S of lengths N consisting of lowercase English alphabets, such that the length of T is smaller than that of S, where T is the string obtained by the procedure above against the string S.
Constraints
- 1 \le N \le 3000
- 10^8 \le P \le 10^9
- N and P are integers.
- P is a prime.
Input
Input is given from Standard Input in the following format:
N P
Output
Print the answer.
Sample Input 1
3 998244353
Sample Output 1
26
Those strings of which the 1-st, 2-nd, and 3-rd characters are all the same satisfy the condition.
For example, aaa becomes a3, which satisfies the condition, while abc becomes a1b1c1, which does not.
Sample Input 2
2 998244353
Sample Output 2
0
Note that if a string is transformed into another string of the same length, such as aa that becomes a2, it does not satisfy the condition.
Sample Input 3
5 998244353
Sample Output 3
2626
Strings like aaabb and aaaaa satisfy the condition.
Sample Input 4
3000 924844033
Sample Output 4
607425699
Find the number of strings satisfying the condition modulo P.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 500 点
問題文
座標平面上でチェックポイント 1,2,\dots,N をこの順に通るレースが行われます。
チェックポイント i の座標は (X_i,Y_i) であり、すべてのチェックポイントの座標は異なります。
チェックポイント 1,N 以外のチェックポイントは、通過を省略することもできます。
ただし、通らなかったチェックポイントの個数を C として、以下の通りペナルティが課せられます。
- C>0 なら \displaystyle 2^{C−1}
- C=0 なら 0
チェックポイント 1 からチェックポイント N までの総移動距離(ユークリッド距離)とペナルティの和を s とします。
このとき、 s として達成可能な最小の値を求めてください。
制約
- 入力は全て整数
- 2 \le N \le 10^4
- 0 \le X_i,Y_i \le 10^4
- i \neq j ならば (X_i,Y_i) \neq (X_j,Y_j)
入力
入力は以下の形式で標準入力から与えられる。
N X_1 Y_1 X_2 Y_2 \vdots X_N Y_N
出力
答えを出力せよ。 出力は、真の値との絶対誤差または相対誤差が 10^{−5} 以下のとき正解と判定される。
入力例 1
6 0 0 1 1 2 0 0 1 1 0 2 1
出力例 1
5.82842712474619009753
チェックポイント 1,2,5,6 を通過し、 3,4 の通過を省略することを考えます。
- チェックポイント 1 \rightarrow 2 に移動する。 2 点間の距離は \sqrt{2} である。
- チェックポイント 2 \rightarrow 5 に移動する。 2 点間の距離は 1 である。
- チェックポイント 5 \rightarrow 6 に移動する。 2 点間の距離は \sqrt{2} である。
- 通らなかったチェックポイントは 2 つであり、このとき科せられるペナルティは 2 である。
以上のようにして、 s = 3 + 2\sqrt{2} \approx 5.828427 を達成できます。
s をこの値より小さくすることはできません。
入力例 2
10 1 8 3 7 9 4 4 9 6 1 7 5 0 0 1 3 6 8 6 4
出力例 2
24.63441361516795872523
入力例 3
10 34 24 47 60 30 31 12 97 87 93 64 46 82 50 14 7 17 24 3 78
出力例 3
110.61238353245736230207
Score : 500 points
Problem Statement
There is a race through checkpoints 1,2,\dots,N in this order on a coordinate plane.
The coordinates of checkpoint i are (X_i,Y_i), and all checkpoints have different coordinates.
Checkpoints other than checkpoints 1 and N can be skipped.
However, let C be the number of checkpoints skipped, and the following penalty will be imposed:
- \displaystyle 2^{C−1} if C>0, and
- 0 if C=0.
Let s be the total distance traveled (Euclidean distance) from checkpoint 1 to checkpoint N plus the penalty.
Find the minimum achievable value as s.
Constraints
- All input values are integers.
- 2 \le N \le 10^4
- 0 \le X_i,Y_i \le 10^4
- (X_i,Y_i) \neq (X_j,Y_j) if i \neq j.
Input
The input is given from Standard Input in the following format:
N X_1 Y_1 X_2 Y_2 \vdots X_N Y_N
Output
Print the answer. Your output is considered correct if the absolute or relative error from the true value is at most 10^{-5}.
Sample Input 1
6 0 0 1 1 2 0 0 1 1 0 2 1
Sample Output 1
5.82842712474619009753
Consider passing through checkpoints 1,2,5,6 and skip checkpoints 3,4.
- Move from checkpoint 1 to 2. The distance between them is \sqrt{2}.
- Move from checkpoint 2 to 5. The distance between them is 1.
- Move from checkpoint 5 to 6. The distance between them is \sqrt{2}.
- Two checkpoints are skipped, so the penalty of 2 is imposed.
In this way, you can achieve s = 3 + 2\sqrt{2} \approx 5.828427.
You cannot make s smaller than this value.
Sample Input 2
10 1 8 3 7 9 4 4 9 6 1 7 5 0 0 1 3 6 8 6 4
Sample Output 2
24.63441361516795872523
Sample Input 3
10 34 24 47 60 30 31 12 97 87 93 64 46 82 50 14 7 17 24 3 78
Sample Output 3
110.61238353245736230207