実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 100 点
問題文
英小文字からなる文字列 S が与えられます。 S の長さは 1 以上かつ 3 以下です。
S を繰り返して得られる文字列であって、長さが 6 のものを出力してください。
本問題の制約下で、そのような文字列はただ一つ存在することが示せます。
制約
- S は英小文字からなる長さ 1 以上 3 以下の文字列
入力
入力は以下の形式で標準入力から与えられる。
S
出力
答えとなる長さ 6 の文字列を出力せよ。
入力例 1
abc
出力例 1
abcabc
S = abc
を繰り返してできる文字列として、abc
、abcabc
、abcabcabc
、abcabcabcabc
などがあります。
そのうち、長さが 6 のものは abcabc
です。よって、abcabc
と出力します。
入力例 2
zz
出力例 2
zzzzzz
Score : 100 points
Problem Statement
You are given a string S consisting of lowercase English characters. The length of S is between 1 and 3, inclusive.
Print the string of length 6 that is a repetition of S.
It can be shown that there uniquely exists such a string under the Constraints of this problem.
Constraints
- S is a string consisting of lowercase English characters of length between 1 and 3, inclusive.
Input
Input is given from Standard Input in the following format:
S
Output
Print the answer string, which is of length 6.
Sample Input 1
abc
Sample Output 1
abcabc
These are strings that are repetitions of S = abc
: abc
, abcabc
, abcabcabc
, abcabcabcabc
, and so on.
Among them, abcabc
has the length of 6, so abcabc
should be printed.
Sample Input 2
zz
Sample Output 2
zzzzzz
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 100 点
問題文
N が与えられます。2^N を出力してください。
制約
- 0 \leq N \leq 30
- N は整数である
入力
入力は以下の形式で標準入力から与えられる。
N
出力
答えを出力せよ。
入力例 1
3
出力例 1
8
2^3=8 です。
入力例 2
30
出力例 2
1073741824
Score : 100 points
Problem Statement
Given N, print 2^N.
Constraints
- 0 \leq N \leq 30
- N is an integer.
Input
Input is given from Standard Input in the following format:
N
Output
Print the answer.
Sample Input 1
3
Sample Output 1
8
We have 2^3=8.
Sample Input 2
30
Sample Output 2
1073741824
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 200 点
問題文
長さ N の整数列 A=(A_1,\ldots,A_N) が与えられます。ここで A_1,A_2,\ldots,A_N は相異なります。
A の中で二番目に大きい要素は A の何番目の要素でしょうか。
制約
- 2\leq N\leq 100
- 1\leq A_i \leq 10^9
- A_1,A_2,\ldots,A_N は相異なる
- 入力される数値は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N A_1 A_2 \ldots A_{N}
出力
A の中で二番目に大きい要素が A の X 番目であるとき、X を整数として出力せよ。
入力例 1
4 8 2 5 1
出力例 1
3
A の中で二番目に大きい要素は A_3 なので 3 を出力してください。
入力例 2
8 1 2 3 4 5 10 9 11
出力例 2
6
Score : 200 points
Problem Statement
You are given an integer sequence A=(A_1,\ldots,A_N) of length N. Here, A_1, A_2, \ldots, A_N are all distinct.
Which element in A is the second largest?
Constraints
- 2 \leq N \leq 100
- 1 \leq A_i \leq 10^9
- A_1, A_2, \ldots, A_N are all distinct.
- 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 integer X such that the X-th element in A is the second largest.
Sample Input 1
4 8 2 5 1
Sample Output 1
3
The second largest element in A is A_3, so print 3.
Sample Input 2
8 1 2 3 4 5 10 9 11
Sample Output 2
6
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 200 点
問題文
xy 平面上に N 人の人 1,2,\dots,N がおり、人 i は座標 (X_i,Y_i) にいます。
このうち、 K 人の人 A_1,A_2,\dots,A_K に同じ強さの明かりを持たせます。
座標 (x,y) にいる人が強さ R の明かりを持っている時、その明かりによって中心 (x,y) 、半径 R の円の内部全体(境界を含む)が照らされます。
すべての人が少なくとも 1 つの明かりによって照らされるために必要な明かりの強さの最小値を求めてください。
制約
- 入力は全て整数
- 1 \le K < N \le 1000
- 1 \le A_1 < A_2 < \dots < A_K \le N
- |X_i|,|Y_i| \le 10^5
- i \neq j ならば (X_i,Y_i) \neq (X_j,Y_j)
入力
入力は以下の形式で標準入力から与えられる。
N K A_1 A_2 \dots A_K X_1 Y_1 X_2 Y_2 \vdots X_N Y_N
出力
答えを実数として出力せよ。
出力された解と想定解との絶対誤差または相対誤差が 10^{-5} 以下であるならば、出力は正しいと見なされる。
入力例 1
4 2 2 3 0 0 0 1 1 2 2 0
出力例 1
2.23606797749978969
この入力では人が 4 人おり、そのうち人 2,3 が明かりを持ちます。
R \ge \sqrt{5} \approx 2.236068 である時、すべての人が少なくとも 1 つの明かりによって照らされます。
入力例 2
2 1 2 -100000 -100000 100000 100000
出力例 2
282842.712474619009
入力例 3
8 3 2 6 8 -17683 17993 93038 47074 58079 -57520 -41515 -89802 -72739 68805 24324 -73073 71049 72103 47863 19268
出力例 3
130379.280458974768
Score : 200 points
Problem Statement
There are N people numbered 1, 2, \dots, N in the xy-plane. Person i is at the coordinates (X_i, Y_i).
K of these people, Persons A_1, A_2, \dots, A_K, will receive lights of the same strength.
When a person at coordinates (x, y) has a light of strength R, it lights up the interior of a circle of radius R centered at (x, y) (including the boundary).
Find the minimum strength of the lights needed for every person to be lit by at least one light.
Constraints
- All values in input are integers.
- 1 \le K < N \le 1000
- 1 \le A_1 < A_2 < \dots < A_K \le N
- |X_i|,|Y_i| \le 10^5
- (X_i,Y_i) \neq (X_j,Y_j), if i \neq j.
Input
Input is given from Standard Input in the following format:
N K A_1 A_2 \dots A_K X_1 Y_1 X_2 Y_2 \vdots X_N Y_N
Output
Print the answer as a real number.
Your output will be considered correct if its absolute or relative error from the judge's output is at most 10^{-5}.
Sample Input 1
4 2 2 3 0 0 0 1 1 2 2 0
Sample Output 1
2.23606797749978969
This input contains four people. Among them, Persons 2 and 3 will have lights.
Every person will be lit by at least one light if R \ge \sqrt{5} \approx 2.236068.
Sample Input 2
2 1 2 -100000 -100000 100000 100000
Sample Output 2
282842.712474619009
Sample Input 3
8 3 2 6 8 -17683 17993 93038 47074 58079 -57520 -41515 -89802 -72739 68805 24324 -73073 71049 72103 47863 19268
Sample Output 3
130379.280458974768
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 300 点
問題文
3\times3 のマス目に 1 から 9 までの数字が書き込まれており、上から i 行目、左から j 列目 (1\leq i\leq3,1\leq j\leq3) に書き込まれている数字は c _ {i,j} です。
異なるマスに同じ数字が書き込まれている場合もありますが、同じ数字が縦・横・斜めに 3 つ連続して書き込まれていることはありません。 より厳密には、c _ {i,j} について次の条件のすべてが成り立っていることが保証されます。
- どの 1\leq i\leq3 についても、c _ {i,1}=c _ {i,2}=c _ {i,3} ではない
- どの 1\leq j\leq3 についても、c _ {1,j}=c _ {2,j}=c _ {3,j} ではない
- c _ {1,1}=c _ {2,2}=c _ {3,3} ではない
- c _ {3,1}=c _ {2,2}=c _ {1,3} ではない
高橋くんは、それぞれのマスに書かれている数字をランダムな順番で知ります。 高橋くんは、縦・横・斜めの列のうちの 1 つでも次の条件を満たしたときがっかりします。
- はじめに知ったほうの 2 マスに書かれた数字が同じであり、最後に知ったマスに書かれた数字がそれと異なる。
高橋くんががっかりせずにすべてのマスに書かれた数字を知る確率を求めてください。
制約
- c _ {i,j}\in\lbrace1,2,3,4,5,6,7,8,9\rbrace\ (1\leq i\leq3,1\leq j\leq3)
- c _ {i,1}=c _ {i,2}=c _ {i,3} ではない (1\leq i\leq3)
- c _ {1,j}=c _ {2,j}=c _ {3,j} ではない (1\leq j\leq3)
- c _ {1,1}=c _ {2,2}=c _ {3,3} ではない
- c _ {1,3}=c _ {2,2}=c _ {3,1} ではない
入力
入力は以下の形式で標準入力から与えられる。
c _ {1,1} c _ {1,2} c _ {1,3} c _ {2,1} c _ {2,2} c _ {2,3} c _ {3,1} c _ {3,2} c _ {3,3}
出力
高橋くんががっかりせずにすべてのマスに書かれた数字を知る確率を 1 行で出力せよ。 真の値からの絶対誤差が 10 ^ {-8} 以下であるとき、正答と判定される。
入力例 1
3 1 9 2 5 6 2 7 1
出力例 1
0.666666666666666666666666666667
例えば、高橋くんが c _ {3,1}=2,c _ {2,1}=2,c _ {1,1}=3 の順に知った場合、高橋くんはがっかりしてしまいます。
対して、高橋くんが c _ {1,1},c _ {1,2},c _ {1,3},c _ {2,1},c _ {2,2},c _ {2,3},c _ {3,1},c _ {3,2},c _ {3,3} の順に数字を知った場合、がっかりすることなくすべての数字を知ることができます。
高橋くんががっかりすることなくすべての数字を知ることができる確率は \dfrac 23 です。 絶対誤差が 10 ^ {-8} 以下であれば正答と判定されるため、0.666666657 や 0.666666676 のように出力しても正解になります。
入力例 2
7 7 6 8 6 8 7 7 6
出力例 2
0.004982363315696649029982363316
入力例 3
3 6 7 1 9 7 5 7 5
出力例 3
0.4
Score : 300 points
Problem Statement
There is a 3\times3 grid with numbers between 1 and 9, inclusive, written in each square. The square at the i-th row from the top and j-th column from the left (1\leq i\leq3,1\leq j\leq3) contains the number c _ {i,j}.
The same number may be written in different squares, but not in three consecutive cells vertically, horizontally, or diagonally. More precisely, it is guaranteed that c _ {i,j} satisfies all of the following conditions.
- c _ {i,1}=c _ {i,2}=c _ {i,3} does not hold for any 1\leq i\leq3.
- c _ {1,j}=c _ {2,j}=c _ {3,j} does not hold for any 1\leq j\leq3.
- c _ {1,1}=c _ {2,2}=c _ {3,3} does not hold.
- c _ {3,1}=c _ {2,2}=c _ {1,3} does not hold.
Takahashi will see the numbers written in each cell in random order. He will get disappointed when there is a line (vertical, horizontal, or diagonal) that satisfies the following condition.
- The first two squares he sees contain the same number, but the last square contains a different number.
Find the probability that Takahashi sees the numbers in all the squares without getting disappointed.
Constraints
- c _ {i,j}\in\lbrace1,2,3,4,5,6,7,8,9\rbrace\ (1\leq i\leq3,1\leq j\leq3)
- c _ {i,1}=c _ {i,2}=c _ {i,3} does not hold for any 1\leq i\leq3.
- c _ {1,j}=c _ {2,j}=c _ {3,j} does not hold for any 1\leq j\leq3.
- c _ {1,1}=c _ {2,2}=c _ {3,3} does not hold.
- c _ {3,1}=c _ {2,2}=c _ {1,3} does not hold.
Input
The input is given from Standard Input in the following format:
c _ {1,1} c _ {1,2} c _ {1,3} c _ {2,1} c _ {2,2} c _ {2,3} c _ {3,1} c _ {3,2} c _ {3,3}
Output
Print one line containing the probability that Takahashi sees the numbers in all the squares without getting disappointed. Your answer will be considered correct if the absolute error from the true value is at most 10 ^ {-8}.
Sample Input 1
3 1 9 2 5 6 2 7 1
Sample Output 1
0.666666666666666666666666666667
For example, if Takahashi sees c _ {3,1}=2,c _ {2,1}=2,c _ {1,1}=3 in this order, he will get disappointed.
On the other hand, if Takahashi sees c _ {1,1},c _ {1,2},c _ {1,3},c _ {2,1},c _ {2,2},c _ {2,3},c _ {3,1},c _ {3,2},c _ {3,3} in this order, he will see all numbers without getting disappointed.
The probability that Takahashi sees all the numbers without getting disappointed is \dfrac 23. Your answer will be considered correct if the absolute error from the true value is at most 10 ^ {-8}, so outputs such as 0.666666657 and 0.666666676 would also be accepted.
Sample Input 2
7 7 6 8 6 8 7 7 6
Sample Output 2
0.004982363315696649029982363316
Sample Input 3
3 6 7 1 9 7 5 7 5
Sample Output 3
0.4
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 300 点
問題文
非負整数 n が次の条件を満たすとき、n を 良い整数 と呼びます。
- n を 10 進法で表したときに、偶数の数字 (0, 2, 4, 6, 8) のみが登場する。
例えば 0、68 および 2024 は良い整数です。
整数 N が与えられます。良い整数のうち小さい方から N 番目の整数を求めてください。
制約
- 1 \leq N \leq 10^{12}
- N は整数
入力
入力は以下の形式で標準入力から与えられる。
N
出力
小さい方から N 番目の良い整数を出力せよ。
入力例 1
8
出力例 1
24
良い整数を小さい方から順に並べると 0, 2, 4, 6, 8, 20, 22, 24, 26, 28, \dots となります。
小さい方から 8 番目の良い整数は 24 なので、これを出力します。
入力例 2
133
出力例 2
2024
入力例 3
31415926535
出力例 3
2006628868244228
Score: 300 points
Problem Statement
A non-negative integer n is called a good integer when it satisfies the following condition:
- All digits in the decimal notation of n are even numbers (0, 2, 4, 6, and 8).
For example, 0, 68, and 2024 are good integers.
You are given an integer N. Find the N-th smallest good integer.
Constraints
- 1 \leq N \leq 10^{12}
- N is an integer.
Input
The input is given from Standard Input in the following format:
N
Output
Print the N-th smallest good integer.
Sample Input 1
8
Sample Output 1
24
The good integers in ascending order are 0, 2, 4, 6, 8, 20, 22, 24, 26, 28, \dots.
The eighth smallest is 24, which should be printed.
Sample Input 2
133
Sample Output 2
2024
Sample Input 3
31415926535
Sample Output 3
2006628868244228
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 400 点
問題文
1 から N が書かれた N 枚のカードが裏向きで積まれた山札があり、上から i 枚目のカードには整数 P_i が書かれています。
この山札を使って、以下の行動を N ターン繰り返します。
- 山札の一番上のカードを引いて、そこに書かれた整数を X とする。
- 場に見えている表向きのカードであって書かれた整数が X 以上であるもののうち、書かれた整数が最小のものの上に、引いたカードを表向きで重ねる。もし場にそのようなカードがなければ、引いたカードをどれにも重ねずに表向きで場に置く。
- その後、表向きのカードが K 枚重ねられた山が場にあればその山のカードを全て食べる。食べられたカードは全て場から消滅する。
各カードについて、何ターン目に食べられるか、あるいは最後まで食べられないかを求めてください。
制約
- 入力は全て整数
- 1 \le K \le N \le 2 \times 10^5
- P は (1,2,\dots,N) の順列 ( (1,2,\dots,N) を並べ替えて得られる列 ) である
入力
入力は以下の形式で標準入力から与えられる。
N K P_1 P_2 \dots P_N
出力
N 行出力せよ。
そのうち i (1 \le i \le N) 行目には、整数 i が書かれたカードについて、以下のように出力せよ。
- もし i が書かれたカードが食べられるなら、それが何ターン目であるかを整数として出力せよ。
- そうでないなら -1 と出力せよ。
入力例 1
5 2 3 5 2 1 4
出力例 1
4 3 3 -1 4
この入力では、 P=(3,5,2,1,4),K=2 です。
- 1 ターン目に、 3 が書かれたカードが他のカードに重ねられずに表向きで場に置かれます。
- 2 ターン目に、 5 が書かれたカードが他のカードに重ねられずに表向きで場に置かれます。
- 3 ターン目に、 2 が書かれたカードが 3 が書かれたカードの上に表向きで重ねられます。
- この時点で上から 2,3 が書かれたカードが表向きで重ねられた山が K=2 枚に達したので、両カードは食べられます。
- 4 ターン目に、 1 が書かれたカードが 5 が書かれたカードの上に表向きで重ねられます。
- この時点で上から 1,5 が書かれたカードが表向きで重ねられた山が K=2 枚に達したので、両カードは食べられます。
- 5 ターン目に、 4 が書かれたカードが他のカードに重ねられずに表向きで場に置かれます。
- 4 が書かれたカードは、最後まで食べられませんでした。
入力例 2
5 1 1 2 3 4 5
出力例 2
1 2 3 4 5
K=1 である場合、全てのカードは場に置かれたターンに食べられます。
入力例 3
15 3 3 14 15 9 2 6 5 13 1 7 10 11 8 12 4
出力例 3
9 9 9 15 15 6 -1 -1 6 -1 -1 -1 -1 6 15
Score : 400 points
Problem Statement
There is a deck consisting of N face-down cards with an integer from 1 through N written on them. The integer on the i-th card from the top is P_i.
Using this deck, you will perform N moves, each consisting of the following steps:
- Draw the topmost card from the deck. Let X be the integer written on it.
- Stack the drawn card, face up, onto the card with the smallest integer among the face-up topmost cards on the table with an integer greater than or equal to X written on them. If there is no such card on the table, put the drawn card on the table, face up, without stacking it onto any card.
- Then, if there is a pile consisting of K face-up cards on the table, eat all those cards. The eaten cards all disappear from the table.
For each card, find which of the N moves eats it. If the card is not eaten until the end, report that fact.
Constraints
- All values in input are integers.
- 1 \le K \le N \le 2 \times 10^5
- P is a permutation of (1,2,\dots,N) (i.e. a sequence obtained by rearranging (1,2,\dots,N)).
Input
Input is given from Standard Input in the following format:
N K P_1 P_2 \dots P_N
Output
Print N lines.
The i-th line (1 \le i \le N) should describe the card with the integer i written on it. Specifically,
- if the card with i written on it is eaten in the x-th move, print x;
- if that card is not eaten in any move, print -1.
Sample Input 1
5 2 3 5 2 1 4
Sample Output 1
4 3 3 -1 4
In this input, P=(3,5,2,1,4) and K=2.
- In the 1-st move, the card with 3 written on it is put on the table, face up, without stacked onto any card.
- In the 2-nd move, the card with 5 written on it is put on the table, face up, without stacked onto any card.
- In the 3-rd move, the card with 2 written on it is stacked, face up, onto the card with 3 written on it.
- Now there is a pile consisting of K=2 face-up cards, on which 2 and 3 from the top are written, so these cards are eaten.
- In the 4-th move, the card with 1 written on it is stacked, face up, onto the card with 5 written on it.
- Now there is a pile consisting of K=2 face-up cards, on which 1 and 5 from the top are written, so these cards are eaten.
- In the 5-th move, the card with 4 written on it is put on the table, face up, without stacked onto any card.
- The card with 4 written on it was not eaten until the end.
Sample Input 2
5 1 1 2 3 4 5
Sample Output 2
1 2 3 4 5
If K=1, every card is eaten immediately after put on the table within a single move.
Sample Input 3
15 3 3 14 15 9 2 6 5 13 1 7 10 11 8 12 4
Sample Output 3
9 9 9 15 15 6 -1 -1 6 -1 -1 -1 -1 6 15
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 500 点
問題文
以下の条件を満たす正の整数 n を、 等差数 と呼びます。
- (n を先頭に余計な 0 を付けずに 10 進法で表記した際、) n の上から i 桁目を d_i とする。このとき、 n が k 桁の整数であったとすると、 (d_2-d_1)=(d_3-d_2)=\dots=(d_k-d_{k-1}) が成立する。
- この条件は、「 数列 (d_1,d_2,\dots,d_k) が等差数列である」と言い換えることができる。
- 但し、 n が 1 桁の整数である時、 n は等差数であるものとする。
たとえば、 234,369,86420,17,95,8,11,777 は等差数ですが、 751,919,2022,246810,2356 は等差数ではありません。
等差数のうち、 X 以上で最小のものを求めてください。
制約
- X は 1 以上 10^{17} 以下の整数である
入力
入力は以下の形式で標準入力から与えられる。
X
出力
答えを整数として出力せよ。
入力例 1
152
出力例 1
159
152 以上で最小の等差数は 159 です。
入力例 2
88
出力例 2
88
X 自身が等差数である場合もあります。
入力例 3
8989898989
出力例 3
9876543210
Score : 500 points
Problem Statement
Let us call a positive integer n that satisfies the following condition an arithmetic number.
- Let d_i be the i-th digit of n from the top (when n is written in base 10 without unnecessary leading zeros.) Then, (d_2-d_1)=(d_3-d_2)=\dots=(d_k-d_{k-1}) holds, where k is the number of digits in n.
- This condition can be rephrased into the sequence (d_1,d_2,\dots,d_k) being arithmetic.
- If n is a 1-digit integer, it is assumed to be an arithmetic number.
For example, 234,369,86420,17,95,8,11,777 are arithmetic numbers, while 751,919,2022,246810,2356 are not.
Find the smallest arithmetic number not less than X.
Constraints
- X is an integer between 1 and 10^{17} (inclusive).
Input
Input is given from Standard Input in the following format:
X
Output
Print the answer as an integer.
Sample Input 1
152
Sample Output 1
159
The smallest arithmetic number not less than 152 is 159.
Sample Input 2
88
Sample Output 2
88
X itself may be an arithmetic number.
Sample Input 3
8989898989
Sample Output 3
9876543210
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 500 点
問題文
S を接頭辞に持つ最短の回文を 1 つ求めてください。
制約
- S は英大文字からなる長さ 1 以上 500000 以下の文字列
入力
入力は以下の形式で標準入力から与えられる。
S
出力
答えを出力せよ。
解が複数存在する場合、どれを出力しても正解とみなされる。
入力例 1
ABC
出力例 1
ABCBA
ABCBA
は S= ABC
を接頭辞に持つ最短の回文です。
入力例 2
Z
出力例 2
Z
Z
は S= Z
を接頭辞に持つ最短の回文です。
入力例 3
TREE
出力例 3
TREERT
TREERT
は S= TREE
を接頭辞に持つ最短の回文です。
Score : 500 points
Problem Statement
Find one shortest palindrome that has S as its prefix.
Constraints
- S is a string of length between 1 and 500000, inclusive, consisting of uppercase English letters.
Input
The input is given from Standard Input in the following format:
S
Output
Print the answer.
If multiple solutions exist, any of them is accepted.
Sample Input 1
ABC
Sample Output 1
ABCBA
ABCBA
is a shortest palindrome that has S= ABC
as its prefix.
Sample Input 2
Z
Sample Output 2
Z
Z
is a shortest palindrome that has S= Z
as its prefix.
Sample Input 3
TREE
Sample Output 3
TREERT
TREERT
is a shortest palindrome that has S= TREE
as its prefix.