実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 100 点
問題文
英小文字のみからなる文字列 S が与えられます。
S の各文字を英大文字に変換して得られる文字列 T を出力してください。
制約
- S は英小文字のみからなる、長さが 1 以上 100 以下の文字列
入力
入力は以下の形式で標準入力から与えられる。
S
出力
T を出力せよ。
入力例 1
abc
出力例 1
ABC
abc の各文字を英大文字に変換すると ABC になります。
入力例 2
a
出力例 2
A
入力例 3
abcdefghjiklnmoqprstvuwxyz
出力例 3
ABCDEFGHJIKLNMOQPRSTVUWXYZ
Score : 100 points
Problem Statement
You are given a string S consisting of lowercase English letters.
Uppercase each character of S and print the resulting string T.
Constraints
- S is a string consisting of lowercase English letters whose length is between 1 and 100, inclusive.
Input
The input is given from Standard Input in the following format:
S
Output
Print T.
Sample Input 1
abc
Sample Output 1
ABC
Uppercase each character of abc, and you have ABC.
Sample Input 2
a
Sample Output 2
A
Sample Input 3
abcdefghjiklnmoqprstvuwxyz
Sample Output 3
ABCDEFGHJIKLNMOQPRSTVUWXYZ
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 100 点
問題文
数直線があり、高橋君はこれを赤色と青色で次のように塗りました。
- X=L_1 から X=R_1 までをすべて赤色で塗る。
- X=L_2 から X=R_2 までをすべて青色で塗る。
数直線のうち、赤色と青色の両方で塗られている部分の長さを求めてください。
制約
- 0\leq L_1<R_1\leq 100
- 0\leq L_2<R_2\leq 100
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
L_1 R_1 L_2 R_2
出力
両方の色で塗られている部分の長さを整数で出力せよ。
入力例 1
0 3 1 5
出力例 1
2
X=0 から X=3 までが赤く、 X=1 から X=5 までが青く塗られています。
よって、両方の色で塗られている部分は X=1 から X=3 までであり、その長さは 2 となります。
入力例 2
0 1 4 5
出力例 2
0
両方の色で塗られている部分はありません。
入力例 3
0 3 3 7
出力例 3
0
赤色と青色で塗られている部分が接している場合でも、 両方の色で塗られている部分の長さは 0 となります。
Score : 100 points
Problem Statement
We have a number line. Takahashi painted some parts of this line, as follows:
- First, he painted the part from X=L_1 to X=R_1 red.
- Next, he painted the part from X=L_2 to X=R_2 blue.
Find the length of the part of the line painted both red and blue.
Constraints
- 0\leq L_1<R_1\leq 100
- 0\leq L_2<R_2\leq 100
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
L_1 R_1 L_2 R_2
Output
Print the length of the part of the line painted both red and blue, as an integer.
Sample Input 1
0 3 1 5
Sample Output 1
2
The part from X=0 to X=3 is painted red, and the part from X=1 to X=5 is painted blue.
Thus, the part from X=1 to X=3 is painted both red and blue, and its length is 2.
Sample Input 2
0 1 4 5
Sample Output 2
0
No part is painted both red and blue.
Sample Input 3
0 3 3 7
Sample Output 3
0
If the part painted red and the part painted blue are adjacent to each other, the length of the part painted both red and blue is 0.
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 200 点
問題文
座標平面上に N 枚の長方形のシートが張られています。
各シートが覆う長方形領域の各辺はそれぞれ x 軸または y 軸と平行であり、
具体的には、i 枚目のシートはちょうど A_i \leq x\leq B_i かつ C_i \leq y\leq D_i をみたす領域全体を覆っています。
1 枚以上のシートによって覆われている領域 の面積を S とすると、
S は制約の条件下で整数となる事が証明できます。
S を整数の形で出力してください。
制約
- 2\leq N\leq 100
- 0\leq A_i<B_i\leq 100
- 0\leq C_i<D_i\leq 100
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N A_1 B_1 C_1 D_1 A_2 B_2 C_2 D_2 \vdots A_N B_N C_N D_N
出力
1 枚以上のシートによって覆われている領域の面積 S を整数で出力せよ。
入力例 1
3 0 5 1 3 1 4 0 5 2 5 2 4
出力例 1
20
3 枚のシートによって覆われている領域は次のようになります。
ここで、赤色・黄色・青色はそれぞれ 1 枚目・ 2 枚目・ 3 枚目のシートによって覆われている領域を表しています。

よって、1 枚以上のシートによって覆われている領域の面積は S=20 となります。
入力例 2
2 0 100 0 100 0 100 0 100
出力例 2
10000
異なるシートが同じ領域を覆っている事があることに注意してください。
入力例 3
3 0 1 0 1 0 3 0 5 5 10 0 10
出力例 3
65
Score : 200 points
Problem Statement
There are N rectangular sheets spread out on a coordinate plane.
Each side of the rectangular region covered by each sheet is parallel to the x- or y-axis.
Specifically, the i-th sheet covers exactly the region satisfying A_i \leq x\leq B_i and C_i \leq y\leq D_i.
Let S be the area of the region covered by one or more sheets. It can be proved that S is an integer under the constraints.
Print S as an integer.
Constraints
- 2\leq N\leq 100
- 0\leq A_i<B_i\leq 100
- 0\leq C_i<D_i\leq 100
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N A_1 B_1 C_1 D_1 A_2 B_2 C_2 D_2 \vdots A_N B_N C_N D_N
Output
Print the area S of the region covered by one or more sheets as an integer.
Sample Input 1
3 0 5 1 3 1 4 0 5 2 5 2 4
Sample Output 1
20
The three sheets cover the following regions.
Here, red, yellow, and blue represent the regions covered by the first, second, and third sheets, respectively.

Therefore, the area of the region covered by one or more sheets is S=20.
Sample Input 2
2 0 100 0 100 0 100 0 100
Sample Output 2
10000
Note that different sheets may cover the same region.
Sample Input 3
3 0 1 0 1 0 3 0 5 5 10 0 10
Sample Output 3
65
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 200 点
問題文
ボウリングのピンは 1 から 10 の番号が付けられており、上から見ると下図のように配置されます。

この図の二つの点線に挟まれた部分を列と呼ぶことにします。
例えば、ピン 1, 5 とピン 3, 9 はそれぞれ同じ列に存在します。
いくつかのピンが倒れた状態のうち、特殊なものはスプリットと呼ばれます。
ピンの配置がスプリットであるとは、以下の条件が全て成り立つことを言います。
- ピン 1 が倒れている。
- ある二つの異なる列であって、次の条件を満たすものが存在する。
- それぞれの列には、立っているピンが 1 本以上存在する。
- それらの列の間に、ピンが全て倒れている列が存在する。
具体例は入出力例を参考にしてください。
さて、あるピンの配置が長さ 10 の文字列 S として与えられます。
i = 1, \dots, 10 について、ピン i が倒れているとき S の i 文字目は 0 であり、ピン i が立っているとき S の i 文字目は 1 です。
S で表されるピンの配置がスプリットかどうか判定してください。
制約
- S は
0と1からなる長さ 10 の文字列
入力
入力は以下の形式で標準入力から与えられる。
S
出力
S で表されるピンの配置がスプリットなら Yes を、そうでないなら No を出力せよ。
入力例 1
0101110101
出力例 1
Yes
倒れているピンを灰色で、立っているピンを白色で示すと下図のようになります。

ピン 5 が立っている列とピン 6 が立っている列の間にはピン 3, 9 が置かれている列が存在しますが、ピン 3, 9 はいずれも倒れているので、この配置はスプリットです。
入力例 2
0100101001
出力例 2
Yes

入力例 3
0000100110
出力例 3
No

この配置はスプリットではありません。
入力例 4
1101110101
出力例 4
No

ピン 1 が倒れていないので、スプリットではありません。
Score : 200 points
Problem Statement
Bowling pins are numbered 1 through 10. The following figure is a top view of the arrangement of the pins:

Let us call each part between two dotted lines in the figure a column.
For example, Pins 1 and 5 belong to the same column, and so do Pin 3 and 9.
When some of the pins are knocked down, a special situation called split may occur.
A placement of the pins is a split if both of the following conditions are satisfied:
- Pin 1 is knocked down.
- There are two different columns that satisfy both of the following conditions:
- Each of the columns has one or more standing pins.
- There exists a column between these columns such that all pins in the column are knocked down.
See also Sample Inputs and Outputs for examples.
Now, you are given a placement of the pins as a string S of length 10.
For i = 1, \dots, 10, the i-th character of S is 0 if Pin i is knocked down, and is 1 if it is standing.
Determine if the placement of the pins represented by S is a split.
Constraints
- S is a string of length 10 consisting of
0and1.
Input
Input is given from Standard Input in the following format:
S
Output
If the placement of the pins represented by S is a split, print Yes; otherwise, print No.
Sample Input 1
0101110101
Sample Output 1
Yes
In the figure below, the knocked-down pins are painted gray, and the standing pins are painted white:

Between the column containing a standing pin 5 and the column containing a standing pin 6 is a column containing Pins 3 and 9. Since Pins 3 and 9 are both knocked down, the placement is a split.
Sample Input 2
0100101001
Sample Output 2
Yes

Sample Input 3
0000100110
Sample Output 3
No

This placement is not a split.
Sample Input 4
1101110101
Sample Output 4
No

This is not a split because Pin 1 is not knocked down.
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 300 点
問題文
ポエムオンラインジャッジ (Poem Online Judge, 以下 POJ と表記) は提出された文字列に得点をつけるオンラインジャッジです。
POJ に N 回の提出がありました。早い方から i 番目の提出では文字列 S_i が提出されて、得点は T_i でした。(同じ文字列が複数回提出される場合もあります)
ただし、POJ では 同じ文字列を提出しても得点が等しいとは限らない のに注意してください。
N 回の提出のうち、その提出よりも早い提出であって文字列が一致するものが存在しないような提出を オリジナル であると呼びます。
また、オリジナルな提出の中で最も得点が高いものを 最優秀賞 と呼びます。ただし、そのような提出が複数ある場合は、最も提出が早いものを最優秀賞とします。
最優秀賞は早い方から何番目の提出ですか?
制約
- 1 \leq N \leq 10^5
- S_i は英小文字からなる文字列
- S_i の長さは 1 以上 10 以下
- 0 \leq T_i \leq 10^9
- N, T_i は整数
入力
入力は以下の形式で標準入力から与えられる。
N S_1 T_1 S_2 T_2 \vdots S_N T_N
出力
答えを出力せよ。
入力例 1
3 aaa 10 bbb 20 aaa 30
出力例 1
2
以下では早い方から i 番目の提出を提出 i と呼びます。
オリジナルな提出は提出 1 と 提出 2 です。提出 3 は提出 1 と文字列が一致しているためオリジナルではありません。
オリジナルな提出のうち最も得点が高い提出は提出 2 です。よってこれが最優秀賞になります。
入力例 2
5 aaa 9 bbb 10 ccc 10 ddd 10 bbb 11
出力例 2
2
オリジナルな提出は提出 1・提出 2・提出 3・提出 4 です。
その中で最も得点が高い提出は提出 2・提出 3・提出 4 です。この場合はこの中でもっとも提出の早い提出 2 を最優秀賞とします。
このように、オリジナルな提出の中で最も得点が高い提出が複数ある場合は、さらにその中で最も提出が早いものを最優秀賞とするのに注意してください。
入力例 3
10 bb 3 ba 1 aa 4 bb 1 ba 5 aa 9 aa 2 ab 6 bb 5 ab 3
出力例 3
8
Score : 300 points
Problem Statement
Poem Online Judge (POJ) is an online judge that gives scores to submitted strings.
There were N submissions to POJ. In the i-th earliest submission, string S_i was submitted, and a score of T_i was given. (The same string may have been submitted multiple times.)
Note that POJ may not necessarily give the same score to submissions with the same string.
A submission is said to be an original submission if the string in the submission is never submitted in any earlier submission.
A submission is said to be the best submission if it is an original submission with the highest score. If there are multiple such submissions, only the earliest one is considered the best submission.
Find the index of the best submission.
Constraints
- 1 \leq N \leq 10^5
- S_i is a string consisting of lowercase English characters.
- S_i has a length between 1 and 10, inclusive.
- 0 \leq T_i \leq 10^9
- N and T_i are integers.
Input
Input is given from Standard Input in the following format:
N S_1 T_1 S_2 T_2 \vdots S_N T_N
Output
Print the answer.
Sample Input 1
3 aaa 10 bbb 20 aaa 30
Sample Output 1
2
We will refer to the i-th earliest submission as Submission i.
Original submissions are Submissions 1 and 2. Submission 3 is not original because it has the same string as that in Submission 1.
Among the original submissions, Submission 2 has the highest score. Therefore, this is the best submission.
Sample Input 2
5 aaa 9 bbb 10 ccc 10 ddd 10 bbb 11
Sample Output 2
2
Original submissions are Submissions 1, 2, 3, and 4.
Among them, Submissions 2, 3, and 4 have the highest scores. In this case, the earliest submission among them, Submission 2, is the best.
As in this sample, beware that if multiple original submissions have the highest scores, only the one with the earliest among them is considered the best submission.
Sample Input 3
10 bb 3 ba 1 aa 4 bb 1 ba 5 aa 9 aa 2 ab 6 bb 5 ab 3
Sample Output 3
8
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 300 点
問題文
この問題は G 問題の簡易版です。
3 個のリールからなるスロットがあります。
i 番目のリールの配列は文字列 S_i によって表されます。ここで、S_i は数字のみからなる長さ M の文字列です。
それぞれのリールには対応するボタンがついています。高橋君は各非負整数 t について、スロットが回り始めてからちょうど t 秒後にボタンを 1 つ選んで押す、または何もしないことができます。
スロットが回り始めてから t 秒後に i 番目のリールに対応するボタンを押すと、i 番目のリールは S_i の (t \bmod M)+1 文字目を表示して止まります。
ただし、t \bmod M で t を M で割ったあまりを表します。
高橋君は全てのリールを止めた上で、表示されている文字が全て同じであるようにしたいです。
高橋君が目標を達成できるように全てのリールを止めるまでに、スロットが回り始めてから最小で何秒かかるかを求めてください。
そのようなことが不可能であればそのことを報告してください。
制約
- 1 \leq M \leq 100
- M は整数
- S_i は数字のみからなる長さ M の文字列
入力
入力は以下の形式で標準入力から与えられる。
M S_1 S_2 S_3
出力
全てのリールを止めた上で、表示されている文字が全て同じであるようにすることができないなら -1 を出力せよ。
できるなら、スロットが回り始めてからそのような状態にするまでに最小で何秒かかるか出力せよ。
入力例 1
10 1937458062 8124690357 2385760149
出力例 1
6
高橋君は次のようにそれぞれのリールを止めることでスロットが回り始めてから 6 秒後にリールに表示される文字を 8 で揃えることができます。
- スロットの回転開始から 0 秒後に 2 番目のリールに対応するボタンを押します。2 番目のリールは S_2 の (0 \bmod 10)+1=1 文字目である
8を表示して止まります。 - スロットの回転開始から 2 秒後に 3 番目のリールに対応するボタンを押します。3 番目のリールは S_3 の (2 \bmod 10)+1=3 文字目である
8を表示して止まります。 - スロットの回転開始から 6 秒後に 1 番目のリールに対応するボタンを押します。1 番目のリールは S_1 の (6 \bmod 10)+1=7 文字目である
8を表示して止まります。
5 秒以下で全てのリールに表示されている文字を揃える方法はないため、6 を出力します。
入力例 2
20 01234567890123456789 01234567890123456789 01234567890123456789
出力例 2
20
全てのリールを止めた上で、表示されている文字を揃える必要がある事に注意してください。
入力例 3
5 11111 22222 33333
出力例 3
-1
表示されている文字が全て同じであるようにリールを止めることはできません。
このとき -1 を出力してください。
Score : 300 points
Problem Statement
This problem is an easier version of Problem G.
There is a slot machine with three reels.
The arrangement of symbols on the i-th reel is represented by the string S_i. Here, S_i is a string of length M consisting of digits.
Each reel has a corresponding button. For each non-negative integer t, Takahashi can either choose and press one button or do nothing exactly t seconds after the reels start spinning.
If he presses the button corresponding to the i-th reel exactly t seconds after the reels start spinning, the i-th reel will stop and display the ((t \bmod M)+1)-th character of S_i.
Here, t \bmod M denotes the remainder when t is divided by M.
Takahashi wants to stop all the reels so that all the displayed characters are the same.
Find the minimum possible number of seconds from the start of the spin until all the reels are stopped so that his goal is achieved.
If this is impossible, report that fact.
Constraints
- 1 \leq M \leq 100
- M is an integer.
- S_i is a string of length M consisting of digits.
Input
The input is given from Standard Input in the following format:
M S_1 S_2 S_3
Output
If it is impossible to stop all the reels so that all the displayed characters are the same, print -1.
Otherwise, print the minimum possible number of seconds from the start of the spin until such a state is achieved.
Sample Input 1
10 1937458062 8124690357 2385760149
Sample Output 1
6
Takahashi can stop each reel as follows so that 6 seconds after the reels start spinning, all the reels display 8.
- Press the button corresponding to the second reel 0 seconds after the reels start spinning. The second reel stops and displays
8, the ((0 \bmod 10)+1=1)-st character of S_2. - Press the button corresponding to the third reel 2 seconds after the reels start spinning. The third reel stops and displays
8, the ((2 \bmod 10)+1=3)-rd character of S_3. - Press the button corresponding to the first reel 6 seconds after the reels start spinning. The first reel stops and displays
8, the ((6 \bmod 10)+1=7)-th character of S_1.
There is no way to make the reels display the same character in 5 or fewer seconds, so print 6.
Sample Input 2
20 01234567890123456789 01234567890123456789 01234567890123456789
Sample Output 2
20
Note that he must stop all the reels and make them display the same character.
Sample Input 3
5 11111 22222 33333
Sample Output 3
-1
It is impossible to stop the reels so that all the displayed characters are the same.
In this case, print -1.
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 425 点
問題文
無限に広い 2 次元グリッドがあり、このグリッドの座標 (0,0) に焚き火があります。
時刻 t=0 では、マス (0,0) にのみ煙が存在します。
N, W, S, E からなる長さ N の文字列 S が与えられ、時刻 t=1,2,\dots,N では次の現象が順番に発生します。
- 風が吹き、現時点で存在する全ての煙が以下の通りに移動する。
- S の t 文字目が
Nであるとき、マス (r,c) にある煙がマス (r-1,c) に移動する。 - S の t 文字目が
Wであるとき、マス (r,c) にある煙がマス (r,c-1) に移動する。 - S の t 文字目が
Sであるとき、マス (r,c) にある煙がマス (r+1,c) に移動する。 - S の t 文字目が
Eであるとき、マス (r,c) にある煙がマス (r,c+1) に移動する。
- S の t 文字目が
- マス (0,0) に煙が存在しない場合、新たな煙がマス (0,0) に生成される。
高橋君はマス (R,C) に立っています。
整数 1 \le t \le N について、時刻 t+0.5 においてマス (R,C) に煙が存在するか判定し、出力欄の形式に従って出力してください。
制約
- N は 1 以上 200000 以下の整数
- S は
N,W,S,Eからなる長さ N の文字列 - R,C は -N 以上 N 以下の整数
- (R,C) \neq (0,0)
入力
入力は以下の形式で標準入力から与えられる。
N R C S
出力
答えを N 文字の 0, 1 からなる文字列として出力せよ。
出力する文字列のうち t 文字目 (1 \le t \le N) は次の通りにせよ。
- 時刻 t+0.5 においてマス (R,C) に煙が存在するなら
1 - 時刻 t+0.5 においてマス (R,C) に煙が存在しないなら
0
入力例 1
6 -2 1 NNEEWS
出力例 1
001010
時刻 1.5,2.5,4.5,6.5 ではマス (-2,1) には煙が存在せず、時刻 3.5,5.5 ではマス (-2,1) に煙が存在します。
よって、 001010 と出力します。
図では焚き火のあるマス (0,0) を基準として、マス (r,c) を
- r < 0 なら -r マス上に
- r \ge 0 なら r マス下に
- c < 0 なら -c マス左に
- c \ge 0 なら c マス右に
描画します。
時刻 0.5 でのグリッドの状態は次の通りです。

時刻 1.5 でのグリッドの状態は次の通りです。

時刻 2.5 でのグリッドの状態は次の通りです。

時刻 3.5 でのグリッドの状態は次の通りです。

時刻 4.5 でのグリッドの状態は次の通りです。

時刻 5.5 でのグリッドの状態は次の通りです。

時刻 6.5 でのグリッドの状態は次の通りです。

入力例 2
10 1 2 NEESESWEES
出力例 2
0001101011
入力例 3
20 -1 -2 WWNNWSWEWNSWWENSNWWN
出力例 3
00100111111000101111
Score : 425 points
Problem Statement
There is an infinitely large two-dimensional grid, with a campfire at coordinate (0,0).
At time t=0, smoke exists only at cell (0,0).
You are given a length-N string S consisting of N, W, S, E. At times t=1,2,\dots,N, the following happen in order:
- Wind blows, and all the smoke present at that time moves as follows:
- If the t-th character of S is
N, smoke in cell (r,c) moves to cell (r-1,c). - If it is
W, smoke in cell (r,c) moves to cell (r,c-1). - If it is
S, smoke in cell (r,c) moves to cell (r+1,c). - If it is
E, smoke in cell (r,c) moves to cell (r,c+1).
- If the t-th character of S is
- If there is no smoke in cell (0,0), new smoke is generated at cell (0,0).
Takahashi is standing at cell (R,C).
For each integer 1 \le t \le N, determine if smoke exists at cell (R,C) at time t+0.5, and print the response according to the required format.
Constraints
- N is an integer between 1 and 200000, inclusive.
- S is a length N string consisting of
N,W,S,E. - R and C are integers between -N and N, inclusive.
- (R,C) \neq (0,0)
Input
The input is given from Standard Input in the following format:
N R C S
Output
Print an N-character string consisting of 0 and 1.
The t-th character (1 \le t \le N) should be:
1if smoke exists at cell (R,C) at time t+0.5, and0otherwise.
Sample Input 1
6 -2 1 NNEEWS
Sample Output 1
001010
At times 1.5,2.5,4.5,6.5, there is no smoke at cell (-2,1). At times 3.5,5.5, there is smoke at cell (-2,1).
Hence, output 001010.
In the figures below, taking cell (0,0) with the campfire as a reference, cell (r,c) is drawn:
- -r cells up if r < 0,
- r cells down if r \ge 0,
- -c cells left if c < 0,
- c cells right if c \ge 0.
The grid at time 0.5 looks like:

The grid at time 1.5 looks like:

The grid at time 2.5 looks like:

The grid at time 3.5 looks like:

The grid at time 4.5 looks like:

The grid at time 5.5 looks like:

The grid at time 6.5 looks like:

Sample Input 2
10 1 2 NEESESWEES
Sample Output 2
0001101011
Sample Input 3
20 -1 -2 WWNNWSWEWNSWWENSNWWN
Sample Output 3
00100111111000101111
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 475 点
問題文
N 頂点 M 辺の単純連結無向グラフ G が与えられます。
G の頂点は頂点 1, 頂点 2, \ldots, 頂点 N と番号付けられており、
i (1\leq i\leq M) 本目の辺は頂点 U_i と頂点 V_i を結んでいます。
G における頂点 X から頂点 Y への単純パスのうち辞書順最小のものを求めてください。
すなわち、以下の条件をみたす整数列 P=(P_1,P_2,\ldots,P_{\lvert P\rvert}) の中で辞書順最小のものを求めてください。
- 1\leq P_i\leq N
- i\neq j ならば P_i\neq P_j
- P_1=X かつ P_{\lvert P\rvert}=Y
- 1\leq i\leq \lvert P\rvert-1 について、頂点 P_i と頂点 P_{i+1} を結ぶ辺が存在する。
なお、本問題の制約下で条件をみたすようなものが必ず存在することが証明できます。
T 個のテストケースが与えられるので、それぞれについて答えを求めてください。
整数列の辞書順 とは
整数列 S=(S_1,S_2,\ldots,S_{\lvert S\rvert}) が整数列 T=(T_1,T_2,\ldots,T_{\lvert T\rvert}) より辞書順で小さいとは、下記の 1. と 2. のどちらかが成り立つことを言います。 ここで、\lvert S\rvert, \lvert T\rvert はそれぞれ S,T の長さを表します。- \lvert S\rvert<\lvert T\rvert かつ (S_1,S_2,\ldots,S_{\lvert S\rvert})=(T_1,T_2,\ldots,T_{\lvert S\rvert})。
- ある 1\leq i\leq \min(\lvert S\rvert,\lvert T\rvert) が存在して (S_1,S_2,\ldots,S_{i-1})=(T_1,T_2,\ldots,T_{i-1}) かつ S_i< T_i。
制約
- 1\leq T\leq 500
- 2\leq N\leq 1000
- N-1\leq M\leq \min\left( \frac{N(N-1)}{2},5\times 10^4\right)
- 1\leq X,Y \leq N
- X\neq Y
- 1\leq U_i<V_i \leq N
- i\neq j ならば (U_i,V_i)\neq (U_j,V_j)
- 与えられるグラフは連結である。
- 1 つの入力における N の総和は 1000 以下である。
- 1 つの入力における M の総和は 5\times 10^4 以下である。
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
T
\mathrm{case}_1
\mathrm{case}_2
\vdots
\mathrm{case}_T
\mathrm{case}_i は i 番目のテストケースを表す。 各テストケースは以下の形式で与えられる。
N M X Y U_1 V_1 U_2 V_2 \vdots U_M V_M
出力
T 行出力せよ。
i 行目 (1\leq i\leq T) には、i 個目のテストケースの答えとなる単純パス上の頂点番号を、順に空白区切りで出力せよ。
すなわち i 個目のテストケースに対する答えが P=(P_1,P_2,\ldots,P_{\lvert P\rvert}) であるとき、
P_1, P_2, \ldots, P_{\lvert P\rvert} を i 行目にこの順に空白区切りで出力せよ。
入力例 1
2 6 10 3 5 1 2 1 3 1 5 1 6 2 4 2 5 2 6 3 4 3 5 5 6 3 2 3 2 1 3 2 3
出力例 1
3 1 2 5 3 2
1 つめのテストケースについて、グラフ G は次のようになっています。

G 上の頂点 3 から頂点 5 への単純パスを辞書順に列挙すると、次のとおりになります。
- (3,1,2,5)
- (3,1,2,6,5)
- (3,1,5)
- (3,1,6,2,5)
- (3,1,6,5)
- (3,4,2,1,5)
- (3,4,2,1,6,5)
- (3,4,2,5)
- (3,4,2,6,1,5)
- (3,4,2,6,5)
- (3,5)
このうち、辞書順最小のものは (3,1,2,5) であるため、1 行目には 3,1,2,5 を空白区切りで出力します。
2 つめのテストケースにおいては、(3,2) が頂点 3 から頂点 2 への唯一の単純パスです。
Score : 475 points
Problem Statement
You are given a simple connected undirected graph G with N vertices and M edges.
The vertices of G are numbered vertex 1, vertex 2, \ldots, vertex N, and
the i-th (1\leq i\leq M) edge connects vertices U_i and V_i.
Find the lexicographically smallest simple path from vertex X to vertex Y in G.
That is, find the lexicographically smallest among the integer sequences P=(P_1,P_2,\ldots,P_{\lvert P\rvert}) that satisfy the following conditions:
- 1\leq P_i\leq N
- If i\neq j, then P_i\neq P_j.
- P_1=X and P_{\lvert P\rvert}=Y.
- For 1\leq i\leq \lvert P\rvert-1, there exists an edge connecting vertices P_i and P_{i+1}.
One can prove that such a path always exists under the constraints of this problem.
You are given T test cases, so find the answer for each.
Lexicographic order on integer sequences
An integer sequence S=(S_1,S_2,\ldots,S_{\lvert S\rvert}) is lexicographically smaller than an integer sequence T=(T_1,T_2,\ldots,T_{\lvert T\rvert}) if either of the following 1. or 2. holds. Here, \lvert S\rvert and \lvert T\rvert represent the lengths of S and T, respectively.- \lvert S\rvert<\lvert T\rvert and (S_1,S_2,\ldots,S_{\lvert S\rvert})=(T_1,T_2,\ldots,T_{\lvert S\rvert}).
- There exists some 1\leq i\leq \min(\lvert S\rvert,\lvert T\rvert) such that (S_1,S_2,\ldots,S_{i-1})=(T_1,T_2,\ldots,T_{i-1}) and S_i< T_i.
Constraints
- 1\leq T\leq 500
- 2\leq N\leq 1000
- N-1\leq M\leq \min\left( \frac{N(N-1)}{2},5\times 10^4\right)
- 1\leq X,Y \leq N
- X\neq Y
- 1\leq U_i<V_i \leq N
- If i\neq j, then (U_i,V_i)\neq (U_j,V_j).
- The given graph is connected.
- The sum of N over all test cases in each input is at most 1000.
- The sum of M over all test cases in each input is at most 5\times 10^4.
- All input values are integers.
Input
The input is given from Standard Input in the following format:
T
\mathrm{case}_1
\mathrm{case}_2
\vdots
\mathrm{case}_T
\mathrm{case}_i represents the i-th test case. Each test case is given in the following format:
N M X Y U_1 V_1 U_2 V_2 \vdots U_M V_M
Output
Output T lines.
The i-th line (1\leq i\leq T) should contain the vertex numbers on the simple path that is the answer to the i-th test case, in order, separated by spaces.
That is, when the answer to the i-th test case is P=(P_1,P_2,\ldots,P_{\lvert P\rvert}),
output P_1, P_2, \ldots, P_{\lvert P\rvert} on the i-th line in this order, separated by spaces.
Sample Input 1
2 6 10 3 5 1 2 1 3 1 5 1 6 2 4 2 5 2 6 3 4 3 5 5 6 3 2 3 2 1 3 2 3
Sample Output 1
3 1 2 5 3 2
For the first test case, graph G is as follows:

The simple paths from vertex 3 to vertex 5 on G, listed in lexicographic order, are as follows:
- (3,1,2,5)
- (3,1,2,6,5)
- (3,1,5)
- (3,1,6,2,5)
- (3,1,6,5)
- (3,4,2,1,5)
- (3,4,2,1,6,5)
- (3,4,2,5)
- (3,4,2,6,1,5)
- (3,4,2,6,5)
- (3,5)
Among these, the lexicographically smallest is (3,1,2,5), so output 3,1,2,5 separated by spaces on the first line.
For the second test case, (3,2) is the only simple path from vertex 3 to vertex 2.
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 550 点
問題文
N 個の押しボタンがあります。このうち 1 個が当たりで、残りの N-1 個はハズレです。
青木君はどのボタンが当たりであるか知っており、高橋君は知りません。また高橋君には N 個のボタンの区別はつきません。
このボタンを使って青木君と高橋君がゲームを行います。ゲームは以下の一連の流れの T 回の繰り返しからなります。
- 青木君が N 個のボタンをランダムな順序に並べる
- 高橋君が「ボタンを 1 つ選び、そのボタンを押す」という操作を M 回行う。同じボタンを複数回選んでもよい
- ゲーム開始時からこれまでに当たりのボタンが何回押されたかを青木君が高橋君に教える
T 回の繰り返しで、当たりのボタンを合計 K 回以上押すことができたとき、かつ、そのときに限り高橋君の勝ちです。
勝つ確率が最大になるように高橋君が行動したときの、高橋君の勝率を求めてください。
制約
- 1 \leq N \leq 2\times 10^5
- 1 \leq T \leq 30
- 1 \leq M \leq 30
- 1 \leq K \leq 30
- 入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N T M K
出力
答えを出力せよ。 真の解との絶対誤差または相対誤差が 10^{-6} 以下のとき正解と判定される。
入力例 1
3 2 2 3
出力例 1
0.222222222222222
ゲームは例えば次のように進行します。(最適な行動とは限りません)
- 1回目の繰り返し
- 青木君がボタンをランダムに並び替え、当たりのボタンが 1 番目 、ハズレのボタンが 2,3 番目となる
- 高橋君が 1 番目のボタンを押す
- 高橋君が 2 番目のボタンを押す
- 当たりのボタンが 1 度押されたことを青木君が高橋君に伝える
- 2回目の繰り返し
- 青木君がボタンをランダムに並び替え、当たりのボタンが 3 番目 、ハズレのボタンが 1,2 番目となる
- 高橋君が 3 番目のボタンを押す
- 高橋君が 3 番目のボタンを押す
- 当たりのボタンが 3 度押されたことを青木君が高橋君に伝える
- 当たりのボタンを 3 回以上押したため、高橋君の勝ちです
なお、このケースの真の解は \frac{2}{9} であるため、0.222222 や 0.222223141592 などの出力でも正解と判定されます。
入力例 2
10 1 10 1
出力例 2
1.000000000000000
入力例 3
100 10 10 2
出力例 3
0.401263060761621
Score : 550 points
Problem Statement
There are N push buttons. One of them is the winning button, and the other N-1 are losing buttons.
Aoki knows which button is winning, but Takahashi does not. Also, Takahashi cannot distinguish the N buttons.
They play a game using these buttons. The game consists of repeating the following sequence T times:
- Aoki arranges the N buttons in a random order.
- Takahashi performs the operation “choose a button and press it” M times. He may choose the same button multiple times.
- Aoki tells Takahashi the number of times the winning button has been pressed so far since the start of the game.
Takahashi wins if and only if the winning button has been pressed a total of at least K times throughout the T repetitions.
Find Takahashi’s probability of winning when he plays to maximize his win probability.
Constraints
- 1 \le N \le 2\times 10^5
- 1 \le T \le 30
- 1 \le M \le 30
- 1 \le K \le 30
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N T M K
Output
Output the answer. Your output is considered correct if its absolute or relative error from the true answer is at most 10^{-6}.
Sample Input 1
3 2 2 3
Sample Output 1
0.222222222222222
The game can proceed as follows (not necessarily optimally):
- 1st repetition
- Aoki randomly arranges the buttons so that the winning button is at position 1, and the losing buttons are at positions 2 and 3.
- Takahashi presses button 1.
- Takahashi presses button 2.
- Aoki tells him the winning button has been pressed 1 time.
- 2nd repetition
- Aoki randomly arranges the buttons so that the winning button is at position 3, and the losing buttons are at positions 1 and 2.
- Takahashi presses button 3.
- Takahashi presses button 3.
- Aoki tells him the winning button has been pressed 3 times.
- Since the winning button has been pressed not less than 3 times, Takahashi wins.
The true answer in this case is \tfrac{2}{9}, so outputs like 0.222222 or 0.222223141592 are also accepted.
Sample Input 2
10 1 10 1
Sample Output 2
1.000000000000000
Sample Input 3
100 10 10 2
Sample Output 3
0.401263060761621