実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 100 点
問題文
xy 平面上に長方形があります。この長方形の各辺は x 軸または y 軸に平行であり、面積は 0 ではありません。
この長方形の 4 つの頂点のうち異なる 3 つの頂点の座標 (x_1, y_1), (x_2, y_2), (x_3, y_3) が与えられるので、残る 1 つの頂点の座標を求めてください。
制約
- -100 \leq x_i, y_i \leq 100
- (x_1, y_1), (x_2, y_2), (x_3, y_3) のすべてを頂点に持つ長方形がただ一つ存在し、その各辺は x 軸または y 軸に平行であり、面積は 0 ではない。
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
x_1 y_1 x_2 y_2 x_3 y_3
出力
答えとなる頂点の座標 (x, y) を下記の形式にしたがい空白区切りで出力せよ。
x y
入力例 1
-1 -1 -1 2 3 2
出力例 1
3 -1
(-1, -1), (-1, 2), (3, 2) を頂点とする長方形の残る 1 つの頂点は (3, -1) です。
入力例 2
-60 -40 -60 -80 -20 -80
出力例 2
-20 -40
Score : 100 points
Problem Statement
There is a rectangle in the xy-plane. Each edge of this rectangle is parallel to the x- or y-axis, and its area is not zero.
Given the coordinates of three of the four vertices of this rectangle, (x_1, y_1), (x_2, y_2), and (x_3, y_3), find the coordinates of the other vertex.
Constraints
- -100 \leq x_i, y_i \leq 100
- There uniquely exists a rectangle with all of (x_1, y_1), (x_2, y_2), (x_3, y_3) as vertices, edges parallel to the x- or y-axis, and a non-zero area.
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
x_1 y_1 x_2 y_2 x_3 y_3
Output
Print the sought coordinates (x, y) separated by a space in the following format:
x y
Sample Input 1
-1 -1 -1 2 3 2
Sample Output 1
3 -1
The other vertex of the rectangle with vertices (-1, -1), (-1, 2), (3, 2) is (3, -1).
Sample Input 2
-60 -40 -60 -80 -20 -80
Sample Output 2
-20 -40
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 100 点
問題文
長さ 3 の英大文字からなる文字列 S が与えられます。
S の各文字を並び替えることで S を文字列 ABC と一致させることができるか判定してください。
制約
- S は英大文字からなる長さ 3 の文字列
入力
入力は以下の形式で標準入力から与えられる。
S
出力
S の各文字を並び替えることで文字列 ABC と一致させることができるなら Yes を、そうでないなら No を出力せよ。
入力例 1
BAC
出力例 1
Yes
S の 1 文字目と S の 2 文字目を入れ替えることで ABC と一致させることができます。
入力例 2
AAC
出力例 2
No
どのように並び替えても S を ABC と一致させることはできません。
入力例 3
ABC
出力例 3
Yes
入力例 4
ARC
出力例 4
No
Score : 100 points
Problem Statement
You are given a string S of length 3 consisting of uppercase English letters.
Determine whether it is possible to rearrange the characters in S to make it match the string ABC.
Constraints
- S is a string of length 3 consisting of uppercase English letters.
Input
The input is given from Standard Input in the following format:
S
Output
Print Yes if it is possible to rearrange the characters in S to make it match the string ABC, and No otherwise.
Sample Input 1
BAC
Sample Output 1
Yes
You can make S match ABC by swapping the first and second characters of S.
Sample Input 2
AAC
Sample Output 2
No
You cannot make S match ABC no matter how you rearrange the characters.
Sample Input 3
ABC
Sample Output 3
Yes
Sample Input 4
ARC
Sample Output 4
No
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 200 点
問題文
高橋君は漢文の勉強をしていて、漢字を読む順番が分からず困っています。高橋君を助けましょう!
1 から N までの N 個の整数が小さい方から順に 1 列に並んでいます。
整数の間に M 個の「レ」が挟まっています。i 個目の「レ」は、整数 a_i と整数 a_i + 1 の間にあります。
あなたは次の手順に従って、N 個の整数を 1 回ずつ全て読みます。
- まず、頂点に 1 から N までの番号がついた N 頂点 M 辺の無向グラフ G を考える。i 本目の辺は頂点 a_i と頂点 a_i + 1 を結んでいる。
- そして、読まれていない整数が無くなるまで次の操作を繰り返す。
- 読まれていない整数のうち最小のものを x とする。頂点 x が含まれる連結成分 C を選び、C に含まれる頂点の番号を大きい方から順に全て読む。
例えば、整数と「レ」が

という順番で並んでいる場合を考えます。(この場合 N = 5, M = 3, a = (1, 3, 4) です。)
このとき、整数が読まれる順番は以下の手順によって 2, 1, 5, 4, 3 に決定します。
- 最初、読まれていない整数のうち最小のものは 1 であり、グラフ G の頂点 1 を含む連結成分に含まれる頂点は \lbrace 1, 2 \rbrace である。よって 2, 1 がこの順で読まれる。
- 次に、読まれていない整数のうち最小のものは 3 であり、グラフ G の頂点 3 を含む連結成分に含まれる頂点は \lbrace 3, 4, 5 \rbrace である。よって 5, 4, 3 がこの順で読まれる。
- すべての整数が読まれたので手順を終了する。
N, M, (a_1, a_2, \dots, a_M) が入力として与えられるので、 N 個の整数を読む順番を出力してください。
連結成分とは
あるグラフの 部分グラフ とは、元のグラフのいくつかの頂点といくつかの辺を選んでできるグラフのことをいいます。グラフが 連結 であるとは、グラフに含まれるすべての頂点同士が辺を経由して互いに行き来できることをいいます。
連結成分 とは、連結な部分グラフのうち、そのグラフを含んだより大きい連結な部分グラフが存在しないものをいいます。
制約
- 1 \leq N \leq 100
- 0 \leq M \leq N - 1
- 1 \leq a_1 \lt a_2 \lt \dots \lt a_M \leq N-1
- 入力される値は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N M a_1 a_2 \dots a_M
出力
答えを以下の形式で出力せよ。ここで p_i は、i 番目に読まれる整数を意味する。
p_1 p_2 \dots p_N
入力例 1
5 3 1 3 4
出力例 1
2 1 5 4 3
問題文の例にある通り、整数と「レ」が

という順で並んでいる場合は 2, 1, 5, 4, 3 の順で読みます。
入力例 2
5 0
出力例 2
1 2 3 4 5
「レ」が存在しない場合もあります。
入力例 3
10 6 1 2 3 7 8 9
出力例 3
4 3 2 1 5 6 10 9 8 7
Score : 200 points
Problem Statement
Studying Kanbun, Takahashi is having trouble figuring out the order to read words. Help him out!
There are N integers from 1 through N arranged in a line in ascending order.
Between them are M "レ" marks. The i-th "レ" mark is between the integer a_i and integer (a_i + 1).
You read each of the N integers once by the following procedure.
- Consider an undirected graph G with N vertices numbered 1 through N and M edges. The i-th edge connects vertex a_i and vertex (a_i+1).
- Repeat the following operation until there is no unread integer:
- let x be the minimum unread integer. Choose the connected component C containing vertex x, and read all the numbers of the vertices contained in C in descending order.
For example, suppose that integers and "レ" marks are arranged in the following order:

(In this case, N = 5, M = 3, and a = (1, 3, 4).)
Then, the order to read the integers is determined to be 2, 1, 5, 4, and 3, as follows:
- At first, the minimum unread integer is 1, and the connected component of G containing vertex 1 has vertices \lbrace 1, 2 \rbrace, so 2 and 1 are read in this order.
- Then, the minimum unread integer is 3, and the connected component of G containing vertex 3 has vertices \lbrace 3, 4, 5 \rbrace, so 5, 4, and 3 are read in this order.
- Now that all integers are read, terminate the procedure.
Given N, M, and (a_1, a_2, \dots, a_M), print the order to read the N integers.
What is a connected component?
A subgraph of a graph is a graph obtained by choosing some vertices and edges from the original graph.A graph is said to be connected if and only if one can travel between any two vertices in the graph via edges.
A connected component is a connected subgraph that is not contained in any larger connected subgraph.
Constraints
- 1 \leq N \leq 100
- 0 \leq M \leq N - 1
- 1 \leq a_1 \lt a_2 \lt \dots \lt a_M \leq N-1
- 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 \dots a_M
Output
Print the answer in the following format, where p_i is the i-th integers to read.
p_1 p_2 \dots p_N
Sample Input 1
5 3 1 3 4
Sample Output 1
2 1 5 4 3
As described in the Problem Statement, if integers and "レ" marks are arranged in the following order:

then the integers are read in the following order: 2, 1, 5, 4, and 3.
Sample Input 2
5 0
Sample Output 2
1 2 3 4 5
There may be no "レ" mark.
Sample Input 3
10 6 1 2 3 7 8 9
Sample Output 3
4 3 2 1 5 6 10 9 8 7
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 200 点
問題文
AtCoder Land の入り口には 1 つのチケット売り場があり、来園客はこのチケット売り場の前に一列に並んで順にチケットを購入します。 チケットの購入手続きには一人当たり A 秒かかり、列の先頭の人がチケットを購入し終わると、(存在すれば)次の人がすぐさま購入手続きを開始します。
現在チケット売り場に並んでいる人はおらず、今から N 人の人が順にチケットを買いに来ます。 具体的には、i 番目の人は今から T_i 秒後にチケット売り場を訪れ、既に列が存在すればその最後尾に並び、存在しなければすぐさま購入手続きを開始します。 ここで、T_1< T_2< \dots < T_N です。
各 i\ (1\leq i\leq N) について、i 番目の人がチケットを購入し終わるのは今から何秒後か求めてください。
制約
- 1\leq N \leq 100
- 0\leq T_1< T_2< \dots < T_N\leq 10^6
- 1\leq A\leq 10^6
- 入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N A T_1 T_2 \dots T_N
出力
N 行出力せよ。 i\ (1\leq i \leq N) 行目には、i 番目の人がチケットを購入し終わるのは今から何秒後かを整数として出力せよ。
入力例 1
3 4 0 2 10
出力例 1
4 8 14
時系列順に以下のように物事が進行します。
- 0 秒後:1 番目の人がチケット売り場を訪れ、チケットの購入手続きを開始する。
- 2 秒後:2 番目の人がチケット売り場を訪れ、1 番目の人の後ろに並ぶ。
- 4 秒後:1 番目の人がチケットを購入し終え、2 番目の人が購入手続きを開始する。
- 8 秒後:2 番目の人がチケットを購入し終える。
- 10 秒後:3 番目の人がチケット売り場を訪れ、チケットの購入手続きを開始する。
- 14 秒後:3 番目の人がチケットを購入し終える。
入力例 2
3 3 1 4 7
出力例 2
4 7 10
時系列順に以下のように物事が進行します。
- 1 秒後:1 番目の人がチケット売り場を訪れ、チケットの購入手続きを開始する。
- 4 秒後:1 番目の人がチケットを購入し終えると同時に、2 番目の人がチケット売り場を訪れ、チケットの購入手続きを開始する。
- 7 秒後:2 番目の人がチケットを購入し終えると同時に、3 番目の人がチケット売り場を訪れ、チケットの購入手続きを開始する。
- 10 秒後:3 番目の人がチケットを購入し終える。
入力例 3
10 50000 120190 165111 196897 456895 540000 552614 561627 743796 757613 991216
出力例 3
170190 220190 270190 506895 590000 640000 690000 793796 843796 1041216
Score : 200 points
Problem Statement
At the entrance of AtCoder Land, there is a single ticket booth where visitors line up to purchase tickets one by one. The purchasing process takes A seconds per person. Once the person at the front of the line finishes purchasing their ticket, the next person (if any) immediately starts their purchasing process.
Currently, there is no one in line at the ticket booth, and N people will come to buy tickets one after another. Specifically, the i-th person will arrive at the ticket booth T_i seconds from now. If there is already a line, they will join the end of it; if not, they will start the purchasing process immediately. Here, T_1 < T_2 < \dots < T_N.
For each i\ (1 \leq i \leq N), determine how many seconds from now the i-th person will finish purchasing their ticket.
Constraints
- 1 \leq N \leq 100
- 0 \leq T_1 < T_2 < \dots < T_N \leq 10^6
- 1 \leq A \leq 10^6
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N A T_1 T_2 \dots T_N
Output
Print N lines. The i-th line should contain the number of seconds from now that the i-th person will finish purchasing their ticket.
Sample Input 1
3 4 0 2 10
Sample Output 1
4 8 14
The events proceed in the following order:
- At 0 seconds: The 1st person arrives at the ticket booth and starts the purchasing process.
- At 2 seconds: The 2nd person arrives at the ticket booth and joins the line behind the 1st person.
- At 4 seconds: The 1st person finishes purchasing their ticket, and the 2nd person starts the purchasing process.
- At 8 seconds: The 2nd person finishes purchasing their ticket.
- At 10 seconds: The 3rd person arrives at the ticket booth and starts the purchasing process.
- At 14 seconds: The 3rd person finishes purchasing their ticket.
Sample Input 2
3 3 1 4 7
Sample Output 2
4 7 10
The events proceed in the following order:
- At 1 second: The 1st person arrives at the ticket booth and starts the purchasing process.
- At 4 seconds: The 1st person finishes purchasing their ticket, and the 2nd person arrives at the ticket booth and starts the purchasing process.
- At 7 seconds: The 2nd person finishes purchasing their ticket, and the 3rd person arrives at the ticket booth and starts the purchasing process.
- At 10 seconds: The 3rd person finishes purchasing their ticket.
Sample Input 3
10 50000 120190 165111 196897 456895 540000 552614 561627 743796 757613 991216
Sample Output 3
170190 220190 270190 506895 590000 640000 690000 793796 843796 1041216
実行時間制限: 4 sec / メモリ制限: 1024 MiB
配点 : 300 点
問題文
高橋君は全 10^9 巻の漫画『すぬけ君』を読むことにしました。
初め、高橋君は『すぬけ君』の単行本を N 冊持っています。i 番目の単行本は a_i 巻です。
高橋君は『すぬけ君』を読み始める前に限り次の操作を 0 回以上何度でも繰り返せます。
- 現在持っている単行本が 1 冊以下の場合、何もしない。そうでない場合、現在持っている単行本から 2 冊を選んで売り、代わりに好きな巻を選んで 1 冊買う
その後、高橋君は『すぬけ君』を 1 巻、2 巻、3 巻、\ldots と順番に読みます。ただし、次に読むべき巻を持っていない状態になった場合、(他の巻を持っているかどうかに関わらず)その時点で『すぬけ君』を読むのをやめます。
高橋君が『すぬけ君』を最大で何巻まで読めるかを求めてください。ただし、1 巻を読めない場合の答えは 0 とします。
制約
- 1 \leq N \leq 3 \times 10^5
- 1 \leq a_i \leq 10^9
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N a_1 \ldots a_N
出力
答えを出力せよ。
入力例 1
6 1 2 4 6 7 271
出力例 1
4
『すぬけ君』を読み始める前に「7 巻と 271 巻を選んで売り、代わりに 3 巻を選んで 1 冊買う」という内容で操作をすると、高橋君は 1 巻、2 巻、3 巻、4 巻、6 巻を 1 冊ずつ持っている状態になります。
この状態から『すぬけ君』を読み始めると、高橋君は 1 巻、2 巻、3 巻、4 巻を読み、続いて 5 巻を読もうとしますが持っていないためこの時点で『すぬけ君』を読むのをやめます。
操作の方法を変えても 5 巻を読むことは出来ないため、4 が答えです。
入力例 2
10 1 1 1 1 1 1 1 1 1 1
出力例 2
5
高橋君は同じ巻を 2 冊以上持っているかもしれません。
この入力に対しては以下のように 4 回操作をしてから『すぬけ君』を読み始めることで 5 巻まで読むことが出来、これが最大です。
- 1 巻を 2 冊選んで売り、代わりに 2 巻を選んで 1 冊買う
- 1 巻を 2 冊選んで売り、代わりに 3 巻を選んで 1 冊買う
- 1 巻を 2 冊選んで売り、代わりに 4 巻を選んで 1 冊買う
- 1 巻を 2 冊選んで売り、代わりに 5 巻を選んで 1 冊買う
入力例 3
1 5
出力例 3
0
高橋君は 1 巻を読めません。
Score : 300 points
Problem Statement
Takahashi is going to read a manga series "Snuke-kun" in 10^9 volumes.
Initially, Takahashi has N books of this series. The i-th book is Volume a_i.
Takahashi may repeat the following operation any number of (possibly zero) times only before he begins to read:
- Do nothing if he has 1 or less books; otherwise, sell two of the books he has and buy one book of any volume instead.
Then, Takahashi reads Volume 1, Volume 2, Volume 3, \ldots, in order. However, when he does not have a book of the next volume to read, he stops reading the series (regardless of the other volumes he has).
Find the latest volume of the series that he can read up to. If he cannot read any, let the answer be 0.
Constraints
- 1 \leq N \leq 3 \times 10^5
- 1 \leq a_i \leq 10^9
- All values in the input 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
6 1 2 4 6 7 271
Sample Output 1
4
Before he begins to read the series, he may do the following operation: "sell books of Volumes 7 and 271 and buy one book of Volume 3 instead." Then, he has one book each of Volumes 1, 2, 3, 4, and 6.
If he then begins to read the series, he reads Volumes 1, 2, 3, and 4, then tries to read Volume 5. However, he does not have one, so he stops reading at this point.
Regardless of the choices in the operation, he cannot read Volume 5, so the answer is 4.
Sample Input 2
10 1 1 1 1 1 1 1 1 1 1
Sample Output 2
5
Takahashi may have multiple books of the same volume.
For this input, if he performs the following 4 operations before he begins to read the series, he can read up to Volume 5, which is the maximum:
- Sell two books of Volume 1 and buy a book of Volume 2 instead.
- Sell two books of Volume 1 and buy a book of Volume 3 instead.
- Sell two books of Volume 1 and buy a book of Volume 4 instead.
- Sell two books of Volume 1 and buy a book of Volume 5 instead.
Sample Input 3
1 5
Sample Output 3
0
Takahashi cannot read Volume 1.