Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 100 点
問題文
英小文字 a, b, \ldots, z の ASCII 文字コードはこの順に 97,98,\ldots,122 です。
97 以上 122 以下の整数 N が与えられるので、ASCII 文字コードが N であるような英小文字を出力してください。
制約
- N は 97 以上 122 以下の整数
入力
入力は以下の形式で標準入力から与えられる。
N
出力
答えを出力せよ。
入力例 1
97
出力例 1
a
ASCII 文字コードが 97 である英小文字は a です。
入力例 2
122
出力例 2
z
Score : 100 points
Problem Statement
The ASCII values of the lowercase English letters a, b, \ldots, z are 97,98,\ldots,122 in this order.
Given an integer N between 97 and 122, print the letter whose ASCII value is N.
Constraints
- N is an integer between 97 and 122 (inclusive).
Input
Input is given from Standard Input in the following format:
N
Output
Print the answer.
Sample Input 1
97
Sample Output 1
a
97 is the ASCII value of a.
Sample Input 2
122
Sample Output 2
z
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 100 点
問題文
人 1 、人 2 、\ldots 、人 N と番号付けられた N 人が、この順番で時計回りに円卓に座っています。 特に、時計回りで人 N の次の位置には人 1 が座っています。
i = 1, 2, \ldots, N について、人 i の名前は S_i 、年齢は A_i です。 ここで、異なる 2 人が同じ名前や同じ年齢であることはありません。
年齢が最も小さい人を起点として、座っている位置の時計回りの順番で、N 人全員の名前を出力してください。
制約
- 2 \leq N \leq 100
- N は整数
- S_i は英小文字のみからなる長さ 1 以上 10 以下の文字列
- i \neq j \implies S_i \neq S_j
- 0 \leq A_i \leq 10^9
- A_i は整数
- i \neq j \implies A_i \neq A_j
入力
入力は以下の形式で標準入力から与えられる。
N S_1 A_1 S_2 A_2 \vdots S_N A_N
出力
N 行出力せよ。 i = 1, 2, \ldots, N について、i 行目には、年齢が最も小さい人を起点として時計回りで i 番目の位置に座っている人の名前を出力せよ。
入力例 1
5 alice 31 bob 41 carol 5 dave 92 ellen 65
出力例 1
carol dave ellen alice bob
年齢が最も小さい人は人 3 です。よって、人 3 を起点として座っている位置の時計回りの順番、すなわち、人 3 、人 4 、人 5 、人 1 、人 2 の順に名前を出力します。
入力例 2
2 takahashi 1000000000 aoki 999999999
出力例 2
aoki takahashi
Score : 100 points
Problem Statement
There are N people numbered 1, 2, \ldots, N, sitting in this clockwise order around a round table. In particular, person 1 is sitting next to person N in the clockwise direction.
For each i = 1, 2, \ldots, N, person i has a name S_i and an age A_i. Here, no two people have the same name or the same age.
Starting from the youngest person, print the names of all N people in the order of their seating positions in clockwise order.
Constraints
- 2 \leq N \leq 100
- N is an integer.
- S_i is a string of length between 1 and 10, consisting of lowercase English letters.
- i \neq j \implies S_i \neq S_j
- 0 \leq A_i \leq 10^9
- A_i is an integer.
- i \neq j \implies A_i \neq A_j
Input
The input is given from Standard Input in the following format:
N S_1 A_1 S_2 A_2 \vdots S_N A_N
Output
Print N lines. For each i = 1, 2, \ldots, N, the i-th line should contain the name of the person sitting in the i-th position clockwise from the youngest person.
Sample Input 1
5 alice 31 bob 41 carol 5 dave 92 ellen 65
Sample Output 1
carol dave ellen alice bob
The youngest person is person 3. Therefore, starting from person 3, print the names in the clockwise order of their seating positions: person 3, person 4, person 5, person 1, and person 2.
Sample Input 2
2 takahashi 1000000000 aoki 999999999
Sample Output 2
aoki takahashi
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
横書きの文章が与えられます。縦書きに直してください。空白を
*で埋めてください。
N 個の、英小文字からなる文字列 S_1,S_2,\dots,S_N が与えられます。これらの文字列の長さの最大値を M とします。
以下の条件を満たす M 個の文字列 T_1,T_2,\dots,T_M を出力してください。
- 各 T_i は英小文字および
*からなる - 各 T_i の末尾は
*でない - 各 1 \leq i \leq N について、次が成り立つ
- 各 1 \leq j \leq |S_i| について、T_j の N-i+1 文字目が存在し、T_1,T_2,\dots,T_{|S_i|} それぞれの N-i+1 文字目をこの順に連結したものは S_i と一致する
- 各 |S_i| + 1 \leq j \leq M について、T_j の N-i+1 文字目は存在しないか、
*である
ただし、|S_i| で文字列 S_i の長さを表します。
制約
- N は 1 以上 100 以下の整数
- S_i は長さ 1 以上 100 以下の英小文字からなる文字列
入力
入力は以下の形式で標準入力から与えられる。
N S_1 S_2 \vdots S_N
出力
答えを以下の形式で出力せよ。
T_1 T_2 \vdots T_M
入力例 1
3 abc de fghi
出力例 1
fda geb h*c i
T_3 の 2 文字目を * とすることで、 c が正しい位置に来ます。
T_4 の 2,3 文字目を * とした場合、T_4 の末尾が * となり、条件を満たしません。
入力例 2
3 atcoder beginner contest
出力例 2
cba oet ngc tio end sne ter *r
Score : 200 points
Problem Statement
You are given a horizontally written text. Convert it to vertical writing, filling spaces with
*.
You are given N strings S_1, S_2, \dots, S_N consisting of lowercase English letters. Let M be the maximum length of these strings.
Print M strings T_1, T_2, \dots, T_M that satisfy the following conditions:
- Each T_i consists of lowercase English letters and
*. - Each T_i does not end with
*. - For each 1 \leq i \leq N, the following holds:
- For each 1 \leq j \leq |S_i|, the (N-i+1)-th character of T_j exists, and the concatenation of the (N-i+1)-th characters of T_1, T_2, \dots, T_{|S_i|} in this order equals S_i.
- For each |S_i| + 1 \leq j \leq M, the (N-i+1)-th character of T_j either does not exist or is
*.
Here, |S_i| denotes the length of the string S_i.
Constraints
- N is an integer between 1 and 100, inclusive.
- Each S_i is a string of lowercase English letters with length between 1 and 100, inclusive.
Input
The input is given from Standard Input in the following format:
N S_1 S_2 \vdots S_N
Output
Print the answer in the following format:
T_1 T_2 \vdots T_M
Sample Input 1
3 abc de fghi
Sample Output 1
fda geb h*c i
Placing * as the 2nd character of T_3 puts the c in the correct position.
On the other hand, placing * as the 2nd and 3rd characters of T_4 would make T_4 end with *, which violates the condition.
Sample Input 2
3 atcoder beginner contest
Sample Output 2
cba oet ngc tio end sne ter *r
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
高橋君は chess960 と呼ばれるゲームで遊んでいます。 高橋君はランダムに決めた初期配置が chess960 の条件を満たすか確認するプログラムを書くことにしました。
長さ 8 の文字列 S が与えられます。S には K, Q がちょうど 1 文字ずつ、R, B, N がちょうど 2 文字ずつ含まれます。 S が以下の条件を全て満たしているか判定してください。
-
S において左から x,y\ (x < y) 文字目が
Bであるとする。このとき x と y の偶奇が異なる。 -
Kは 2 つのRの間にある。より形式的には、S において左から x,y\ (x < y) 文字目がRであり、 z 文字目がKであるとする。このとき、 x< z < y が成り立つ。
制約
- S は 長さ 8 の文字列であり、
K,Qがちょうど 1 文字ずつ、R,B,Nがちょうど 2 文字ずつ含まれる。
入力
入力は以下の形式で標準入力から与えられる。
S
出力
S が条件を満たす場合 Yes を、そうでない場合 No を出力せよ。
入力例 1
RNBQKBNR
出力例 1
Yes
B は左から 3 番目、6 番目にあり、3 と 6 は偶奇が異なります。
また、K は 2 つの R の間にあります。よって条件を満たします。
入力例 2
KRRBBNNQ
出力例 2
No
K は 2 つの R の間にありません。
入力例 3
BRKRBQNN
出力例 3
No
Score : 200 points
Problem Statement
Takahashi is playing a game called Chess960. He has decided to write a code that determines if a random initial state satisfies the conditions of Chess960.
You are given a string S of length eight. S has exactly one K and Q, and exactly two R's, B's , and N's. Determine if S satisfies all of the following conditions.
-
Suppose that the x-th and y-th (x < y) characters from the left of S are
B; then, x and y have different parities. -
Kis between twoR's. More formally, suppose that the x-th and y-th (x < y) characters from the left of S areRand the z-th isK; then x< z < y.
Constraints
- S is a string of length 8 that contains exactly one
KandQ, and exactly twoR's,B's , andN's.
Input
The input is given from Standard Input in the following format:
S
Output
Print Yes if S satisfies the conditions; print No otherwise.
Sample Input 1
RNBQKBNR
Sample Output 1
Yes
The 3-rd and 6-th characters are B, and 3 and 6 have different parities.
Also, K is between the two R's. Thus, the conditions are fulfilled.
Sample Input 2
KRRBBNNQ
Sample Output 2
No
K is not between the two R's.
Sample Input 3
BRKRBQNN
Sample Output 3
No
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
長さ N の非負整数列 A=(A_1,A_2,\ldots,A_N) が与えられます。
A の異なる 2 要素の和として表せる値の中に偶数が存在するか判定し、存在する場合その最大値を求めてください。
制約
- 2\leq N \leq 2\times 10^5
- 0\leq A_i\leq 10^9
- A の要素は相異なる
- 入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N A_1 A_2 \ldots A_N
出力
A の異なる 2 要素の和として表せる値の中に偶数が存在しない場合、-1 を出力せよ。
偶数が存在する場合、その最大値を出力せよ。
入力例 1
3 2 3 4
出力例 1
6
A の異なる 2 要素の和として表せる値は 5,6,7 です。この中に偶数は存在し、その最大値は 6 です。
入力例 2
2 1 0
出力例 2
-1
A の異なる 2 要素の和として表せる値は 1 です。この中に偶数は存在しないので、 -1 を出力してください。
Score : 300 points
Problem Statement
You are given a sequence A=(A_1,A_2,\ldots,A_N) of length N consisting of non-negative integers.
Determine if there is an even number represented as the sum of two different elements of A. If it exists, find the maximum such number.
Constraints
- 2\leq N \leq 2\times 10^5
- 0\leq A_i\leq 10^9
- The elements of A are distinct.
- All values in the input are integers.
Input
The input is given from Standard Input in the following format:
N A_1 A_2 \ldots A_N
Output
Print -1 if there is no even number represented as the sum of two different elements of A.
If such an even number exists, print the maximum such number.
Sample Input 1
3 2 3 4
Sample Output 1
6
The values represented as the sum of two distinct elements of A are 5, 6, and 7. We have an even number here, and the maximum is 6.
Sample Input 2
2 1 0
Sample Output 2
-1
The value represented as the sum of two distinct elements of A is 1. We have no even number here, so -1 should be printed.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
長さ N の狭義単調増加列 A=(A _ 1,A _ 2,\ldots,A _ N) と、長さ M の狭義単調増加列 B=(B _ 1,B _ 2,\ldots,B _ M) が与えられます。 ここで、すべての i,j\ (1\leq i\leq N,1\leq j\leq M) について A _ i\neq B _ j が成り立っています。
長さ N+M の狭義単調増加列 C=(C _ 1,C _ 2,\ldots,C _ {N+M}) を、次の操作を行った結果得られる列として定めます。
- C を A と B を連結した列とする。厳密には、i=1,2,\ldots,N について C _ i=A _ i とし、i=N+1,N+2,\ldots,N+M について C _ i=B _ {i-N} とする。
- C を昇順にソートする。
A _ 1,A _ 2,\ldots,A _ N と B _ 1,B _ 2,\ldots,B _ M がそれぞれ C では何番目にあるか求めてください。 より厳密には、まず i=1,2,\ldots,N について C _ k=A _ i を満たす k を順に求めたのち、j=1,2,\ldots,M について C _ k=B _ j を満たす k を順に求めてください。
制約
- 1\leq N,M\leq 10^5
- 1\leq A _ 1\lt A _ 2\lt\cdots\lt A _ N\leq 10^9
- 1\leq B _ 1\lt B _ 2\lt\cdots\lt B _ M\leq 10^9
- すべての i,j\ (1\leq i\leq N,1\leq j\leq M) について A _ i\neq B _ j
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N M A _ 1 A _ 2 \ldots A _ N B _ 1 B _ 2 \ldots B _ M
出力
答えを 2 行で出力せよ。
1 行目には A _ 1,A _ 2,\ldots,A _ N がそれぞれ C では何番目にあるかを空白区切りで出力せよ。
2 行目には B _ 1,B _ 2,\ldots,B _ M がそれぞれ C では何番目にあるかを空白区切りで出力せよ。
入力例 1
4 3 3 14 15 92 6 53 58
出力例 1
1 3 4 7 2 5 6
C は (3,6,14,15,53,58,92) となります。 A=(3,14,15,92) の要素はそれぞれ 1,3,4,7 番目にあり、B=(6,53,58) の要素はそれぞれ 2,5,6 番目にあります。
入力例 2
4 4 1 2 3 4 100 200 300 400
出力例 2
1 2 3 4 5 6 7 8
入力例 3
8 12 3 4 10 15 17 18 22 30 5 7 11 13 14 16 19 21 23 24 27 28
出力例 3
1 2 5 9 11 12 15 20 3 4 6 7 8 10 13 14 16 17 18 19
Score : 300 points
Problem Statement
You are given strictly increasing sequences of length N and M: A=(A _ 1,A _ 2,\ldots,A _ N) and B=(B _ 1,B _ 2,\ldots,B _ M). Here, A _ i\neq B _ j for every i and j (1\leq i\leq N,1\leq j\leq M).
Let C=(C _ 1,C _ 2,\ldots,C _ {N+M}) be a strictly increasing sequence of length N+M that results from the following procedure.
- Let C be the concatenation of A and B. Formally, let C _ i=A _ i for i=1,2,\ldots,N, and C _ i=B _ {i-N} for i=N+1,N+2,\ldots,N+M.
- Sort C in ascending order.
For each of A _ 1,A _ 2,\ldots,A _ N, B _ 1,B _ 2,\ldots,B _ M, find its position in C. More formally, for each i=1,2,\ldots,N, find k such that C _ k=A _ i, and for each j=1,2,\ldots,M, find k such that C _ k=B _ j.
Constraints
- 1\leq N,M\leq 10^5
- 1\leq A _ 1\lt A _ 2\lt\cdots\lt A _ N\leq 10^9
- 1\leq B _ 1\lt B _ 2\lt\cdots\lt B _ M\leq 10^9
- A _ i\neq B _ j for every i and j (1\leq i\leq N,1\leq j\leq M).
- All values in the input are integers.
Input
The input is given from Standard Input in the following format:
N M A _ 1 A _ 2 \ldots A _ N B _ 1 B _ 2 \ldots B _ M
Output
Print the answer in two lines.
The first line should contain the positions of A _ 1,A _ 2,\ldots,A _ N in C, with spaces in between.
The second line should contain the positions of B _ 1,B _ 2,\ldots,B _ M in C, with spaces in between.
Sample Input 1
4 3 3 14 15 92 6 53 58
Sample Output 1
1 3 4 7 2 5 6
C will be (3,6,14,15,53,58,92). Here, the 1-st, 3-rd, 4-th, 7-th elements are from A=(3,14,15,92), and the 2-nd, 5-th, 6-th elements are from B=(6,53,58).
Sample Input 2
4 4 1 2 3 4 100 200 300 400
Sample Output 2
1 2 3 4 5 6 7 8
Sample Input 3
8 12 3 4 10 15 17 18 22 30 5 7 11 13 14 16 19 21 23 24 27 28
Sample Output 3
1 2 5 9 11 12 15 20 3 4 6 7 8 10 13 14 16 17 18 19
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 450 点
問題文
非負整数 l,r\ (l<r) に対して、l 以上 r 未満の整数を順に並べた数列 (l,l+1,\ldots,r-2,r-1) を S(l,r) で表します。また、非負整数 i,j を用いて S(2^{i}j,2^{i}(j+1)) と表される数列を良い数列と呼ぶことにします。
非負整数 L,R\ (L\lt R) が与えられます。数列 S(L,R) をできるだけ少ない個数の良い数列に分割するとき、その個数と分割の方法を出力してください。より厳密には、以下を満たす非負整数の組の列 (l_1,r_1),(l_2,r_2),\ldots,(l_M,r_M) が存在するような正整数 M の最小値を求め、そのときの (l_1,r_1),(l_2,r_2),\ldots,(l_M,r_M) を出力してください。
- L=l_1<r_1=l_2<r_2=\cdots=l_M<r_M=R
- S(l_1,r_1),S(l_2,r_2),\ldots,S(l_M,r_M) は良い数列
なお、M が最小となるような分割方法は一通りのみ存在することが示せます。
制約
- 0\leq L\lt R\leq 2^{60}
- 入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。
L R
出力
以下の形式にしたがって出力せよ。
M l_1 r_1 \vdots l_M r_M
(l_1,r_1),\dots,(l_M,r_M) を昇順で出力することに注意せよ。
入力例 1
3 19
出力例 1
5 3 4 4 8 8 16 16 18 18 19
S(3,19)=(3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18) です。これは以下の 5 つの良い数列に分割でき、これが個数が最小となるような分割方法です。
- S(3,4)=S(2^0\cdot 3,2^0\cdot4)=(3)
- S(4,8)=S(2^2\cdot 1,2^2\cdot 2)=(4,5,6,7)
- S(8,16)=S(2^3\cdot 1,2^3\cdot 2)=(8,9,10,11,12,13,14,15)
- S(16,18)=S(2^1\cdot 8,2^1\cdot 9)=(16,17)
- S(18,19)=S(2^0\cdot 18,2^0\cdot 19)=(18)
入力例 2
0 1024
出力例 2
1 0 1024
入力例 3
3940649673945088 11549545024454656
出力例 3
8 3940649673945088 3940649673949184 3940649673949184 4503599627370496 4503599627370496 9007199254740992 9007199254740992 11258999068426240 11258999068426240 11540474045136896 11540474045136896 11549270138159104 11549270138159104 11549545016066048 11549545016066048 11549545024454656
Score: 450 points
Problem Statement
For non-negative integers l and r (l < r), let S(l, r) denote the sequence (l, l+1, \ldots, r-2, r-1) formed by arranging integers from l through r-1 in order. Furthermore, a sequence is called a good sequence if and only if it can be represented as S(2^i j, 2^i (j+1)) using non-negative integers i and j.
You are given non-negative integers L and R (L < R). Divide the sequence S(L, R) into the fewest number of good sequences, and print that number of sequences and the division. More formally, find the minimum positive integer M for which there is a sequence of pairs of non-negative integers (l_1, r_1), (l_2, r_2), \ldots, (l_M, r_M) that satisfies the following, and print such (l_1, r_1), (l_2, r_2), \ldots, (l_M, r_M).
- L = l_1 < r_1 = l_2 < r_2 = \cdots = l_M < r_M = R
- S(l_1, r_1), S(l_2, r_2), \ldots, S(l_M, r_M) are good sequences.
It can be shown that there is only one division that minimizes M.
Constraints
- 0 \leq L < R \leq 2^{60}
- All input values are integers.
Input
The input is given from Standard Input in the following format:
L R
Output
Print the answer in the following format:
M l_1 r_1 \vdots l_M r_M
Note that the pairs (l_1, r_1), \dots, (l_M, r_M) should be printed in ascending order.
Sample Input 1
3 19
Sample Output 1
5 3 4 4 8 8 16 16 18 18 19
S(3,19)=(3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18) can be divided into the following five good sequences, which is the minimum possible number:
- S(3,4)=S(2^0\cdot 3,2^0\cdot4)=(3)
- S(4,8)=S(2^2\cdot 1,2^2\cdot 2)=(4,5,6,7)
- S(8,16)=S(2^3\cdot 1,2^3\cdot 2)=(8,9,10,11,12,13,14,15)
- S(16,18)=S(2^1\cdot 8,2^1\cdot 9)=(16,17)
- S(18,19)=S(2^0\cdot 18,2^0\cdot 19)=(18)
Sample Input 2
0 1024
Sample Output 2
1 0 1024
Sample Input 3
3940649673945088 11549545024454656
Sample Output 3
8 3940649673945088 3940649673949184 3940649673949184 4503599627370496 4503599627370496 9007199254740992 9007199254740992 11258999068426240 11258999068426240 11540474045136896 11540474045136896 11549270138159104 11549270138159104 11549545016066048 11549545016066048 11549545024454656
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 500 点
問題文
2 次元平面上に N 個の街と M 個の宝箱があります。街 i は座標 (X_i,Y_i) に、宝箱 i は座標 (P_i,Q_i) にあります。
高橋君は原点を出発し、N 個の街全てを訪れたのち原点に戻る旅行をしようと考えています。
宝箱を訪れる必要はありませんが、宝箱の中にはそれぞれブースターが 1 つあり、ブースターを拾うごとに移動速度が 2 倍になります。
高橋君の最初の移動速度が単位時間あたり 1 であるとき、旅行にかかる時間の最小値を求めてください。
制約
- 1 \leq N \leq 12
- 0 \leq M \leq 5
- -10^9 \leq X_i,Y_i,P_i,Q_i \leq 10^9
- (0,0),(X_i,Y_i),(P_i,Q_i) は相異なる
- 入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N M X_1 Y_1 \vdots X_N Y_N P_1 Q_1 \vdots P_M Q_M
出力
答えを出力せよ。なお、想定解答との絶対誤差または相対誤差が 10^{-6} 以下であれば正解として扱われる。
入力例 1
2 1 1 1 0 1 1 0
出力例 1
2.5000000000
以下のように移動するのが最適解の一つです。
- 原点から宝箱 1 までの距離 1 を速さ 1 で移動する。時間が 1 かかる
- 宝箱 1 から街 1 までの距離 1 を速さ 2 で移動する。時間が 0.5 かかる
- 街 1 から街 2までの距離 1 を速さ 2 で移動する。時間が 0.5 かかる
- 街 2から原点までの距離 1 を速さ 2 で移動する。時間が 0.5 かかる
入力例 2
2 1 1 1 0 1 100 0
出力例 2
3.4142135624
以下のように移動するのが最適解の一つです。
- 原点 から街 1 までの距離 1.41\ldots を速さ 1 で移動する。時間が 1.41\ldots かかる
- 街 1 から街 2 までの距離 1 を速さ 1 で移動する。時間が 1 かかる
- 街 2 から原点までの距離 1 を速さ 1 で移動する。時間が 1 かかる
入力例 3
1 2 4 4 1 0 0 1
出力例 3
4.3713203436
以下のように移動するのが最適解の一つです。
- 原点から宝箱 1 までの距離 1 を速さ 1 で移動する。時間が 1 かかる
- 宝箱 1 から宝箱 2 までの距離 1.41\ldots を速さ 2 で移動する。時間が 0.707\ldots かかる
- 宝箱 2 から街 1 までの距離 5 を速さ 4 で移動する。時間が 1.25 かかる
- 街 1 から原点までの距離 5.65\ldots を速さ 4 で移動する。時間が 1.41\ldots かかる
Score : 500 points
Problem Statement
In a two-dimensional plane, there are N towns and M chests. Town i is at the coordinates (X_i,Y_i), and chest i is at the coordinates (P_i,Q_i).
Takahashi will go on a trip where he starts at the origin, visits all N towns, and then returns to the origin.
It is not mandatory to visit chests, but each chest contains an accelerator. Each time he picks up an accelerator, his moving speed gets multiplied by 2.
Takahashi's initial moving speed is 1. Find the shortest time needed to complete the trip.
Constraints
- 1 \leq N \leq 12
- 0 \leq M \leq 5
- -10^9 \leq X_i,Y_i,P_i,Q_i \leq 10^9
- (0,0), (X_i,Y_i), and (P_i,Q_i) are distinct.
- All values in the input are integers.
Input
The input is given from Standard Input in the following format:
N M X_1 Y_1 \vdots X_N Y_N P_1 Q_1 \vdots P_M Q_M
Output
Print the answer. Your output will be considered correct if the absolute or relative error from the judge's answer is at most 10^{-6}.
Sample Input 1
2 1 1 1 0 1 1 0
Sample Output 1
2.5000000000
Here is one optimal way to complete the trip.
- Go the distance 1 from the origin to chest 1 at a speed of 1, taking a time of 1.
- Go the distance 1 from chest 1 to town 1 at a speed of 2, taking a time of 0.5.
- Go the distance 1 from town 1 to town 2 at a speed of 2, taking a time of 0.5.
- Go the distance 1 from town 2 to the origin at a speed of 2, taking a time of 0.5.
Sample Input 2
2 1 1 1 0 1 100 0
Sample Output 2
3.4142135624
Here is one optimal way to complete the trip.
- Go the distance 1.41\ldots from the origin to town 1 at a speed of 1, taking a time of 1.41\ldots.
- Go the distance 1 from town 1 to town 2 at a speed of 1, taking a time of 1.
- Go the distance 1 from town 2 to the origin at a speed of 1, taking a time of 1.
Sample Input 3
1 2 4 4 1 0 0 1
Sample Output 3
4.3713203436
Here is one optimal way to complete the trip.
- Go the distance 1 from the origin to chest 1 at a speed of 1, taking a time of 1.
- Go the distance 1.41\ldots from chest 1 to chest 2 at a speed of 2, taking a time of 0.707\ldots.
- Go the distance 5 from chest 2 to town 1 at a speed of 4, taking a time of 1.25.
- Go the distance 5.65\ldots from town 1 to the origin at a speed of 4, taking a time of 1.41\ldots.
Time Limit: 5 sec / Memory Limit: 1024 MiB
配点 : 500 点
問題文
N 個の頂点と M 本の辺からなる有向グラフがあります。各辺には美しさとコストの 2 つの正整数値が定められています。
i = 1, 2, \ldots, M について、i 番目の辺は頂点 u_i から頂点 v_i への有向辺であり、その美しさは b_i 、コストは c_i です。 ここで、u_i \lt v_i が制約として保証されます。
頂点 1 から頂点 N へのパス P を 1 つ選んだときの、下記の値としてあり得る最大値を求めてください。
- P 上のすべての辺の美しさの総和を、P 上のすべての辺のコストの総和で割った値
ここで、与えられるグラフにおいて頂点 1 から頂点 N へのパスが 1 個以上存在することが制約として保証されます。
制約
- 2 \leq N \leq 2 \times 10^5
- 1 \leq M \leq 2 \times 10^5
- 1 \leq u_i \lt v_i \leq N
- 1 \leq b_i, c_i \leq 10^4
- 頂点 1 から頂点 N へのパスが存在する
- 入力される値はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N M u_1 v_1 b_1 c_1 u_2 v_2 b_2 c_2 \vdots u_M v_M b_M c_M
出力
答えを出力せよ。出力された値と真の値の相対誤差もしくは絶対誤差が 10^{-9} 以下のとき、正答と判定される。
入力例 1
5 7 1 2 3 6 1 3 9 5 2 3 1 5 2 4 5 3 2 5 1 9 3 4 4 8 4 5 2 7
出力例 1
0.7500000000000000
パス P として、 2, 6, 7 番目の辺をこの順に通り頂点 1 \rightarrow 3 \rightarrow 4 \rightarrow 5 とたどるパスを選んだとき、「 P 上のすべての辺の美しさの総和を P 上のすべての辺のコストの総和で割った値」 は、 (b_2 + b_6 + b_7) / (c_2 + c_6 + c_7) = (9 + 4 + 2) / (5 + 8 + 7) = 15 / 20 = 0.75 であり、これがあり得る最大値です。
入力例 2
3 3 1 3 1 1 1 3 2 1 1 3 3 1
出力例 2
3.0000000000000000
入力例 3
10 20 3 4 1 2 7 9 4 5 2 4 4 5 4 5 1 4 6 9 4 1 9 10 3 2 6 10 5 5 5 6 1 2 5 6 5 2 2 3 2 3 6 10 4 4 4 6 3 4 4 8 4 1 3 5 3 2 2 4 3 2 3 5 4 2 1 5 3 4 1 2 4 2 3 7 2 2 7 8 1 3
出力例 3
1.8333333333333333
Score : 500 points
Problem Statement
There is a directed graph with N vertices and M edges. Each edge has two positive integer values: beauty and cost.
For i = 1, 2, \ldots, M, the i-th edge is directed from vertex u_i to vertex v_i, with beauty b_i and cost c_i. Here, the constraints guarantee that u_i \lt v_i.
Find the maximum value of the following for a path P from vertex 1 to vertex N.
- The total beauty of all edges on P divided by the total cost of all edges on P.
Here, the constraints guarantee that the given graph has at least one path from vertex 1 to vertex N.
Constraints
- 2 \leq N \leq 2 \times 10^5
- 1 \leq M \leq 2 \times 10^5
- 1 \leq u_i \lt v_i \leq N
- 1 \leq b_i, c_i \leq 10^4
- There is a path from vertex 1 to vertex N.
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N M u_1 v_1 b_1 c_1 u_2 v_2 b_2 c_2 \vdots u_M v_M b_M c_M
Output
Print the answer. Your output will be judged as correct if the relative or absolute error from the true answer is at most 10^{-9}.
Sample Input 1
5 7 1 2 3 6 1 3 9 5 2 3 1 5 2 4 5 3 2 5 1 9 3 4 4 8 4 5 2 7
Sample Output 1
0.7500000000000000
For the path P that passes through the 2-nd, 6-th, and 7-th edges in this order and visits vertices 1 \rightarrow 3 \rightarrow 4 \rightarrow 5, the total beauty of all edges on P divided by the total cost of all edges on P is (b_2 + b_6 + b_7) / (c_2 + c_6 + c_7) = (9 + 4 + 2) / (5 + 8 + 7) = 15 / 20 = 0.75, and this is the maximum possible value.
Sample Input 2
3 3 1 3 1 1 1 3 2 1 1 3 3 1
Sample Output 2
3.0000000000000000
Sample Input 3
10 20 3 4 1 2 7 9 4 5 2 4 4 5 4 5 1 4 6 9 4 1 9 10 3 2 6 10 5 5 5 6 1 2 5 6 5 2 2 3 2 3 6 10 4 4 4 6 3 4 4 8 4 1 3 5 3 2 2 4 3 2 3 5 4 2 1 5 3 4 1 2 4 2 3 7 2 2 7 8 1 3
Sample Output 3
1.8333333333333333