Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 250 点
問題文
長さ N の数列 A が与えられます。
A のうち丁度 K 要素を自由に選んで消し、残った要素を順序を保って連結した数列を B とします。
( B の最大値 ) - ( B の最小値 ) としてありうる最小値を求めてください。
制約
- 入力は全て整数
- 1 \le K < N \le 2 \times 10^5
- 1 \le A_i \le 10^9
入力
入力は以下の形式で標準入力から与えられる。
N K A_1 A_2 \dots A_N
出力
答えを整数として出力せよ。
入力例 1
5 2 3 1 5 4 9
出力例 1
2
A=(3,1,5,4,9) から丁度 2 要素を自由に選んで消すことを考えます。
- 例えば 2 要素目の 1 、 5 要素目の 9 を消すと、消した後の数列 B=(3,5,4) となります。
- このとき B の最大値は 5 、最小値は 3 なので ( B の最大値 ) - ( B の最小値 ) =2 となり、これは達成可能な最小値です。
入力例 2
6 5 1 1 1 1 1 1
出力例 2
0
入力例 3
8 3 31 43 26 6 18 36 22 13
出力例 3
18
Score : 250 points
Problem Statement
You are given a sequence A of length N.
Freely choose exactly K elements from A and remove them, then concatenate the remaining elements in their original order to form a new sequence B.
Find the minimum possible value of this: the maximum value of B minus the minimum value of B.
Constraints
- All inputs are integers.
- 1 \le K < N \le 2 \times 10^5
- 1 \le A_i \le 10^9
Input
The input is given from Standard Input in the following format:
N K A_1 A_2 \dots A_N
Output
Print the answer as an integer.
Sample Input 1
5 2 3 1 5 4 9
Sample Output 1
2
Consider removing exactly two elements from A=(3,1,5,4,9).
- For example, if you remove the 2nd element 1 and the 5th element 9, the resulting sequence is B=(3,5,4).
- In this case, the maximum value of B is 5 and the minimum value is 3, so (maximum value of B) - (minimum value of B) =2, which is the minimum possible value.
Sample Input 2
6 5 1 1 1 1 1 1
Sample Output 2
0
Sample Input 3
8 3 31 43 26 6 18 36 22 13
Sample Output 3
18
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
英小文字、,
、"
からなる長さ N の文字列 S が与えられます。S に含まれる "
の個数は偶数であることが保証されています。
S に含まれる "
の個数を 2K 個とすると、各 i=1,2,\ldots,K について 2i-1 番目の "
から 2i 番目の "
までの文字のことを 括られた文字 と呼びます。
あなたの仕事は、 S に含まれる ,
のうち、括られた文字 でないもの を .
で置き換えて得られる文字列を答えることです。
制約
- N は 1 以上 2\times 10^5 以下の整数
- S は英小文字、
,
、"
からなる長さ N の文字列 - S に含まれる
"
の個数は偶数
入力
入力は以下の形式で標準入力から与えられる。
N S
出力
答えを出力せよ。
入力例 1
8 "a,b"c,d
出力例 1
"a,b"c.d
S のうち "a,b"
が括られた文字であり、c,d
は括られた文字ではありません。
S に含まれる ,
のうち、括られた文字でないのは S の左から 7 番目の文字なので、7 番目の文字を .
で置き換えたものが答えとなります。
入力例 2
5 ,,,,,
出力例 2
.....
入力例 3
20 a,"t,"c,"o,"d,"e,"r,
出力例 3
a."t,"c."o,"d."e,"r.
Score : 300 points
Problem Statement
You are given a string S of length N consisting of lowercase English letters, ,
, and "
. It is guaranteed that S contains an even number of "
.
Let 2K be the number of "
in S. For each i=1,2,\ldots,K, the characters from the (2i-1)-th "
through the (2i)-th "
are said to be enclosed.
Your task is to replace each ,
in S that is not an enclosed character with .
and print the resulting string.
Constraints
- N is an integer between 1 and 2\times 10^5, inclusive.
- S is a string of length N consisting of lowercase English letters,
,
, and"
. - S contains an even number of
"
.
Input
The input is given from Standard Input in the following format:
N S
Output
Print the answer.
Sample Input 1
8 "a,b"c,d
Sample Output 1
"a,b"c.d
In S, "a,b"
are enclosed characters, and c,d
are not.
The ,
in S that is not an enclosed character is the seventh character from the left in S, so replace that character with .
to get the answer.
Sample Input 2
5 ,,,,,
Sample Output 2
.....
Sample Input 3
20 a,"t,"c,"o,"d,"e,"r,
Sample Output 3
a."t,"c."o,"d."e,"r.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 400 点
問題文
スーパーマンである高橋くんは、地上で困っている人を助けるため、あるビルの屋上から飛び降りようとしています。 高橋くんがいる星には重力の大きさを表す g という値が定まっており、 高橋くんが落下を開始してから地面に到達するまでにかかる時間は \frac{A}{\sqrt{g}} です。
現在の時刻は 0 であり、g = 1 が成り立ちます。 高橋くんは、今から次の操作を好きな回数(0 回でもよい)行います。
- 超能力により g の値を 1 増やす。時間が B 経過する。
その後、高橋くんはビルから飛び降ります。落下を開始した後は g の値を変えることはできません。 また、操作によって経過する時間と落下にかかる時間以外は考えないものとします。
高橋くんが地面に到達できる最も早い時刻を求めてください。
制約
- 1 \leq A \leq 10^{18}
- 1 \leq B \leq 10^{18}
- 入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。
A B
出力
高橋くんが地面に到達できる最も早い時刻を出力せよ。 出力は、真の値との絶対誤差または相対誤差が 10^{-6} 以下のとき正解と判定される。
入力例 1
10 1
出力例 1
7.7735026919
- 操作を 0 回行うとき、地面に到達する時刻は 1\times 0+\frac{10}{\sqrt{1}} = 10 です。
- 操作を 1 回行うとき、地面に到達する時刻は 1\times 1+\frac{10}{\sqrt{2}} \fallingdotseq 8.07 です。
- 操作を 2 回行うとき、地面に到達する時刻は 1\times 2+\frac{10}{\sqrt{3}} \fallingdotseq 7.77 です。
- 操作を 3 回行うとき、地面に到達する時刻は 1\times 3+\frac{10}{\sqrt{4}} = 8 です。
操作を 4 回以上行っても、地面への到達時刻は遅くなるのみです。 よって、操作を 2 回行ってから飛び降りるのが最適で、答えは 2+\frac{10}{\sqrt{3}} です。
入力例 2
5 10
出力例 2
5.0000000000
操作を 1 回も行わないのが最適です。
入力例 3
1000000000000000000 100
出力例 3
8772053214538.5976562500
Score : 400 points
Problem Statement
A superman, Takahashi, is about to jump off the roof of a building to help a person in trouble on the ground. Takahashi's planet has a constant value g that represents the strength of gravity, and the time it takes for him to reach the ground after starting to fall is \frac{A}{\sqrt{g}}.
It is now time 0, and g = 1. Takahashi will perform the following operation as many times as he wants (possibly zero).
- Use a superpower to increase the value of g by 1. This takes a time of B.
Then, he will jump off the building. After starting to fall, he cannot change the value of g. Additionally, we only consider the time it takes to perform the operation and fall.
Find the earliest time Takahashi can reach the ground.
Constraints
- 1 \leq A \leq 10^{18}
- 1 \leq B \leq 10^{18}
- All values in the input are integers.
Input
The input is given from Standard Input in the following format:
A B
Output
Print the earliest time Takahashi can reach the ground. Your output will be accepted when its absolute or relative error from the true value is at most 10^{-6}.
Sample Input 1
10 1
Sample Output 1
7.7735026919
- If he performs the operation zero times, he will reach the ground at time 1\times 0+\frac{10}{\sqrt{1}} = 10.
- If he performs the operation once, he will reach the ground at time 1\times 1+\frac{10}{\sqrt{2}} \fallingdotseq 8.07.
- If he performs the operation twice, he will reach the ground at time 1\times 2+\frac{10}{\sqrt{3}} \fallingdotseq 7.77.
- If he performs the operation three times, he will reach the ground at time 1\times 3+\frac{10}{\sqrt{4}} = 8.
Performing the operation four or more times will only delay the time to reach the ground. Therefore, it is optimal to perform the operation twice before jumping off, and the answer is 2+\frac{10}{\sqrt{3}}.
Sample Input 2
5 10
Sample Output 2
5.0000000000
It is optimal not to perform the operation at all.
Sample Input 3
1000000000000000000 100
Sample Output 3
8772053214538.5976562500
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 475 点
問題文
高橋君と青木君は N 枚のカードを使ってとあるゲームをします。i 枚目のカードの表面には A_i が、裏面には B_i が書かれています。初めに場には N 枚のカードが並べられており、高橋君を先手として、2 人は以下の操作を交互に繰り返します。
- 場にあるカードの中から表面同士に同じ数が書かれている、または裏面同士に同じ数が書かれている 2 枚のカードの組を選び、そのカードを場から取り除く。このようなカードの組が存在しない場合、操作を行えない。
先に操作を行えなくなった方が負けとなり、もう一方が勝ちとなります。 両者がそれぞれ勝つために最適な操作を選ぶ時、どちらが勝つか求めてください。
制約
- 1 \leq N \leq 18
- 1 \leq A_i,B_i \leq 10^9
- 入力は全て整数である。
入力
入力は以下の形式で標準入力から与えられる。
N A_1 B_1 A_2 B_2 \vdots A_N B_N
出力
2 人とも最適に操作を行なったとき、高橋君が勝つ場合は Takahashi
と、青木君が勝つ場合は Aoki
と出力せよ。
入力例 1
5 1 9 2 5 4 9 1 4 2 5
出力例 1
Aoki
髙橋君が最初に取り除いた 2 枚が
-
1 枚目と 3 枚目のカードだった場合: 青木君は 2 枚目と 5 枚目のカードを取り除くことで勝つことができる。
-
1 枚目と 4 枚目のカードだった場合: 青木君は 2 枚目と 5 枚目のカードを取り除くことで勝つことができる。
-
2 枚目と 5 枚目のカードだった場合: 青木君は 1 枚目と 3 枚目のカードを取り除くことで勝つことができる。
髙橋君が最初の操作で取り除くことができるカードの組み合わせは以上の 3 通りのみで、髙橋君がどのような操作を行っても青木君が勝つことができるため、青木君が答えとなります。
入力例 2
9 3 2 1 7 4 1 1 8 5 2 9 8 2 1 6 8 5 2
出力例 2
Takahashi
Score : 475 points
Problem Statement
Takahashi and Aoki are playing a game using N cards. The front side of the i-th card has A_i written on it, and the back side has B_i written on it. Initially, the N cards are laid out on the table. With Takahashi going first, the two players take turns performing the following operation:
- Choose a pair of cards from the table such that either the numbers on their front sides are the same or the numbers on their back sides are the same, and remove these two cards from the table. If no such pair of cards exists, the player cannot perform the operation.
The player who is first to be unable to perform the operation loses, and the other player wins. Determine who wins if both players play optimally.
Constraints
- 1 \leq N \leq 18
- 1 \leq A_i, B_i \leq 10^9
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N A_1 B_1 A_2 B_2 \vdots A_N B_N
Output
Print Takahashi
if Takahashi wins when both players play optimally, and Aoki
otherwise.
Sample Input 1
5 1 9 2 5 4 9 1 4 2 5
Sample Output 1
Aoki
If Takahashi first removes
-
the first and third cards: Aoki can win by removing the second and fifth cards.
-
the first and fourth cards: Aoki can win by removing the second and fifth cards.
-
the second and fifth cards: Aoki can win by removing the first and third cards.
These are the only three pairs of cards Takahashi can remove in his first move, and Aoki can win in all cases. Therefore, the answer is Aoki.
Sample Input 2
9 3 2 1 7 4 1 1 8 5 2 9 8 2 1 6 8 5 2
Sample Output 2
Takahashi
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 525 点
問題文
すぬけくんは、AtCoder Land の新たな目玉アトラクションとして迷路を建設しようと考えています。 迷路は縦 N 行・横 M 列のグリッドとして表され、右上のマスの上端が入口、右下のマスの下端が出口です。 すぬけくんは、隣接するマスの間に適切に壁を配置することで迷路を作ります。
すぬけくんは簡単な迷路が大好きなので、入口から出口までの道順は枝分かれを一切持たずにちょうど K マスを通るようなものにしたいです。 そのような迷路を作ることが可能か判定し、可能ならば 1 つ構築してください。
例えば以下の図では、N=3,M=3 であり、実線で書かれているところに壁が配置されています(入口と出口を除く外周部には必ず壁が配置されるものとします)。 このとき、入口から出口までの道順は枝分かれを一切持たずにちょうど 7 マスを通っています。
厳密には以下の通りです。
縦 N 行・横 M 列のグリッドがあります。 上から i 行目、左から j 列目のマスを (i,j) と表記します。 あなたは、辺で隣接する任意の 2 マスの間それぞれについて壁を置くか置かないか決めることができます。 壁を置く場所をうまく定めることで以下の条件を満たすことができるか判定し、できるならば実際に 1 つ構築してください。
NM 頂点からなる無向グラフ G を考える。G の各頂点は 2 つの整数の組 (i,j)\ (1\leq i\leq N, 1\leq j\leq M) によって互いに相異なるラベルが付けられている。 相異なる 2 頂点 (i_1,j_1),(i_2,j_2) は、|i_1-i_2|+|j_1-j_2|=1 かつグリッド上の 2 マス (i_1,j_1),(i_2,j_2) の間に壁が置かれていない場合、またその場合に限り辺で結ばれている。
条件:K 頂点からなり 2 頂点 (1,M),(N,M) を結ぶような単純パスが存在し、また 2 頂点 (1,M),(N,M) を含む連結成分はこのパスのみからなる。
制約
- 2\leq N \leq 100
- 1\leq M \leq 100
- 1\leq K\leq NM
- 入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N M K
出力
条件を満たす壁の配置が存在しないならば No
を出力し、存在するならばそのうちの 1 つを以下の形式で出力せよ。
条件を満たす壁の配置が複数存在する場合は、そのどれを出力してもよい。
複雑な出力形式のため、下記の出力例も参考にしてください。
Yes +++++ \dots +++S+ +o?o? \dots ?o?o+ +?+?+ \dots +?+?+ +o?o? \dots ?o?o+ +?+?+ \dots +?+?+ \vdots +o?o? \dots ?o?o+ +?+?+ \dots +?+?+ +o?o? \dots ?o?o+ +++++ \dots +++G+
ここで、S
, G
, +
, o
はそれぞれ入口、出口、壁、マスを表し、マスとマスの間にある ?
は壁を置くことができる場所である。
横に隣接する 2 マスの間にある ?
は、壁を置くならば |
で、壁を置かないならば .
で置き換えよ。
縦に隣接する 2 マスの間にある ?
は、壁を置くならば -
で、壁を置かないならば .
で置き換えよ。
厳密には以下の通りである。
- 出力は 2N+2 行からなり、1 行目には文字列
Yes
を、2 行目から 2N+2 行目には以下で説明されるように長さ 2M+1 の文字列を出力する。- 2 行目には、2M-1 個の
+
,S
,+
をこの順に連結して出力する。 - 1+2i 行目 (1\leq i\leq N) には、
+
,o
, c_{i,1},o
, c_{i,2}, \dots, c_{i,M-1},o
,+
をこの順に連結して出力する。 ここで、c_{i,j} はマス (i,j),(i,j+1) の間に壁を置くならば|
、置かないならば.
である。 - 2+2i 行目 (1\leq i\leq N-1) には、
+
, r_{i,1},+
, r_{i,2},+
, \dots,+
, r_{i,M},+
をこの順に連結して出力する。 ここで、r_{i,j} はマス (i,j),(i+1,j) の間に壁を置くならば-
、置かないならば.
である。 - 2N+2 行目には、2M-1 個の
+
,G
,+
をこの順に連結して出力する。
- 2 行目には、2M-1 個の
入力例 1
3 3 7
出力例 1
Yes +++++S+ +o.o.o+ +.+-+-+ +o.o.o+ +-+-+.+ +o.o|o+ +++++G+
問題文中の図と同じ壁の配置です。
入力例 2
3 3 2
出力例 2
No
入力例 3
4 1 4
出力例 3
Yes +S+ +o+ +.+ +o+ +.+ +o+ +.+ +o+ +G+
Score : 525 points
Problem Statement
Snuke is planning to build a maze as a new attraction in AtCoder Land. The maze is represented as a grid with N rows and M columns, with the top edge of the top-right cell being the entrance and the bottom edge of the bottom-right cell being the exit. He will create the maze by appropriately placing walls between adjacent cells.
He loves simple mazes, so he wants the path from the entrance to the exit to pass through exactly K cells without any branches. Determine if it is possible to create such a maze, and if possible, construct one.
For example, in the following figure, N=3 and M=3, and walls are placed at the solid lines (walls are always placed around the outer perimeter except for the entrance and exit). In this case, the path from the entrance to the exit passes through exactly 7 cells without any branches.
Below is a formal statement.
There is a grid with N rows and M columns. Let (i, j) denote the cell at the i-th row from the top and j-th column from the left. For each pair of side-adjacent cells, you can decide whether to place a wall between them. Determine whether it is possible to place walls to satisfy the following condition, and if it is possible, construct one such placement.
Consider an undirected graph G with NM vertices. Each vertex of G is uniquely labeled by a pair of integers (i,j)\ (1\leq i\leq N, 1\leq j\leq M). Two distinct vertices (i_1,j_1) and (i_2,j_2) are connected by an edge if and only if |i_1-i_2|+|j_1-j_2|=1 and there is no wall between the corresponding cells (i_1,j_1) and (i_2,j_2) on the grid.
Condition: there exists a simple path with K vertices that connects the two vertices (1,M) and (N,M), and the connected component containing the vertices (1,M) and (N,M) consists only of this path.
Constraints
- 2\leq N \leq 100
- 1\leq M \leq 100
- 1\leq K\leq NM
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N M K
Output
If there is no placement of walls that satisfies the condition, print No
. Otherwise, print one such placement in the following format. If multiple valid placements exist, any of them can be printed.
See also the sample outputs below to better understand the complicated output format.
Yes +++++ \dots +++S+ +o?o? \dots ?o?o+ +?+?+ \dots +?+?+ +o?o? \dots ?o?o+ +?+?+ \dots +?+?+ \vdots +o?o? \dots ?o?o+ +?+?+ \dots +?+?+ +o?o? \dots ?o?o+ +++++ \dots +++G+
Here, S
, G
, +
, and o
represent the entrance, exit, a wall, and a cell, respectively, and ?
between cells represents a position where a wall can be placed. Replace ?
between two horizontally adjacent cells with |
if a wall is placed, and .
otherwise. Replace ?
between two vertically adjacent cells with -
if a wall is placed, and .
otherwise.
Below is a formal instruction.
- The output should consist of 2N+2 lines. Line 1 should contain the string
Yes
, and lines 2 to 2N+2 should contain strings of length 2M+1 as described below.- Line 2 should be a concatenation of
+
repeated 2M-1 times,S
, and+
, in this order. - Line 1+2i (1\leq i\leq N) should be a concatenation of
+
,o
, c_{i,1},o
, c_{i,2}, \dots, c_{i,M-1},o
,+
, in this order. Here, c_{i,j} is|
if a wall is placed between cells (i,j) and (i,j+1), and.
otherwise. - Line 2+2i (1\leq i\leq N-1) should be a concatenation of
+
, r_{i,1},+
, r_{i,2},+
, \dots,+
, r_{i,M},+
, in this order. Here, r_{i,j} is-
if a wall is placed between cells (i,j) and (i+1,j), and.
otherwise. - Line 2N+2 should be a concatenation of
+
repeated 2M-1 times,G
, and+
, in this order.
- Line 2 should be a concatenation of
Sample Input 1
3 3 7
Sample Output 1
Yes +++++S+ +o.o.o+ +.+-+-+ +o.o.o+ +-+-+.+ +o.o|o+ +++++G+
This is the same placement of walls as in the figure in the problem statement.
Sample Input 2
3 3 2
Sample Output 2
No
Sample Input 3
4 1 4
Sample Output 3
Yes +S+ +o+ +.+ +o+ +.+ +o+ +.+ +o+ +G+