実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 100 点
問題文
N 個の文字列 S_1,S_2,\ldots,S_N がこの順番で与えられます。
S_N,S_{N-1},\ldots,S_1 の順番で出力してください。
制約
- 1\leq N \leq 10
- N は整数
- S_i は英小文字、英大文字、数字からなる長さ 1 以上 10 以下の文字列
入力
入力は以下の形式で標準入力から与えられる。
N S_1 S_2 \vdots S_N
出力
N 行出力せよ。 i\ (1\leq i \leq N) 行目には、S_{N+1-i} を出力せよ。
入力例 1
3 Takahashi Aoki Snuke
出力例 1
Snuke Aoki Takahashi
N=3、S_1= Takahashi、S_2= Aoki、S_3= Snuke です。
よって、Snuke、Aoki、Takahashi の順で出力します。
入力例 2
4 2023 Year New Happy
出力例 2
Happy New Year 2023
与えられる文字列が数字を含むこともあります。
Score : 100 points
Problem Statement
You are given N strings S_1,S_2,\ldots,S_N in this order.
Print S_N,S_{N-1},\ldots,S_1 in this order.
Constraints
- 1\leq N \leq 10
- N is an integer.
- S_i is a string of length between 1 and 10, inclusive, consisting of lowercase English letters, uppercase English letters, and digits.
Input
The input is given from Standard Input in the following format:
N S_1 S_2 \vdots S_N
Output
Print N lines. The i-th (1\leq i \leq N) line should contain S_{N+1-i}.
Sample Input 1
3 Takahashi Aoki Snuke
Sample Output 1
Snuke Aoki Takahashi
We have N=3, S_1= Takahashi, S_2= Aoki, and S_3= Snuke.
Thus, you should print Snuke, Aoki, and Takahashi in this order.
Sample Input 2
4 2023 Year New Happy
Sample Output 2
Happy New Year 2023
The given strings may contain digits.
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 100 点
問題文
小数第三位までで表すことのできる実数 X が、小数第三位まで入力されます。
X を小数第一位で四捨五入した結果として得られる整数を出力してください。
制約
- 0 \leq X < 100
- X は小数第三位までで表現可能である。
- X は小数第三位まで与えられる。
入力
入力は以下の形式で標準入力から与えられる。
X
出力
X を小数第一位で四捨五入して得られる整数を出力せよ。
入力例 1
3.456
出力例 1
3
3.456 の小数第一位は 4 であるので、3.456 を小数第一位で四捨五入した値は 3 となります。
入力例 2
99.500
出力例 2
100
入力例 3
0.000
出力例 3
0
Score : 100 points
Problem Statement
You are given a real number X, which is representable using at most three decimal digits, with three decimal digits.
Round X to the nearest integer and print the result.
Constraints
- 0 \leq X < 100
- X is representable using at most three decimal digits.
- X has three decimal digits in input.
Input
Input is given from Standard Input in the following format:
X
Output
Print the integer resulting from rounding X to the nearest integer.
Sample Input 1
3.456
Sample Output 1
3
The digit in the first decimal place of 3.456 is 4, so we should round it down to 3.
Sample Input 2
99.500
Sample Output 2
100
Sample Input 3
0.000
Sample Output 3
0
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 200 点
問題文
N 人の人が総当り戦の試合をしました。
N 行 N 列からなる試合の結果の表 A が与えられます。A の i 行目 j 列目の要素を A_{i,j} と表します。
A_{i,j} は i=j のとき - であり、それ以外のとき W, L, D のいずれかです。
A_{i,j} が W, L, D であることは、人 i が人 j との試合に勝った、負けた、引き分けたことをそれぞれ表します。
与えられた表に矛盾があるかどうかを判定してください。
次のいずれかが成り立つとき、与えられた表には矛盾があるといいます。
- ある組 (i,j) が存在して、人 i が人 j に勝ったが、人 j が人 i に負けていない
- ある組 (i,j) が存在して、人 i が人 j に負けたが、人 j が人 i に勝っていない
- ある組 (i,j) が存在して、人 i が人 j に引き分けたが、人 j が人 i に引き分けていない
制約
- 2 \leq N \leq 1000
- A_{i,i} は
-である - i\neq j のとき、A_{i,j} は
W,L,Dのいずれかである
入力
入力は以下の形式で標準入力から与えられる。
N
A_{1,1}A_{1,2}\ldots A_{1,N}
A_{2,1}A_{2,2}\ldots A_{2,N}
\vdots
A_{N,1}A_{N,2}\ldots A_{N,N}
出力
与えられた表に矛盾がないとき correct、矛盾があるとき incorrect と出力せよ。
入力例 1
4 -WWW L-DD LD-W LDW-
出力例 1
incorrect
人 3 が人 4 に勝ったにもかかわらず、人 4 も人 3 に勝ったことになっており、矛盾しています。
入力例 2
2 -D D-
出力例 2
correct
矛盾はありません。
Score : 200 points
Problem Statement
N players played a round-robin tournament.
You are given an N-by-N table A containing the results of the matches. Let A_{i,j} denote the element at the i-th row and j-th column of A.
A_{i,j} is - if i=j, and W, L, or D otherwise.
A_{i,j} is W if Player i beat Player j, L if Player i lost to Player j, and D if Player i drew with Player j.
Determine whether the given table is contradictory.
The table is said to be contradictory when some of the following holds:
- There is a pair (i,j) such that Player i beat Player j, but Player j did not lose to Player i;
- There is a pair (i,j) such that Player i lost to Player j, but Player j did not beat Player i;
- There is a pair (i,j) such that Player i drew with Player j, but Player j did not draw with Player i.
Constraints
- 2 \leq N \leq 1000
- A_{i,i} is
-. - A_{i,j} is
W,L, orD, for i\neq j.
Input
Input is given from Standard Input in the following format:
N
A_{1,1}A_{1,2}\ldots A_{1,N}
A_{2,1}A_{2,2}\ldots A_{2,N}
\vdots
A_{N,1}A_{N,2}\ldots A_{N,N}
Output
If the given table is not contradictory, print correct; if it is contradictory, print incorrect.
Sample Input 1
4 -WWW L-DD LD-W LDW-
Sample Output 1
incorrect
Player 3 beat Player 4, while Player 4 also beat Player 3, which is contradictory.
Sample Input 2
2 -D D-
Sample Output 2
correct
There is no contradiction.
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 200 点
問題文
英小文字からなる文字列 S,T が与えられるので、 T が S の(連続する)部分文字列かどうか判定してください。
なお、文字列 X に以下の操作を 0 回以上施して文字列 Y が得られる時、またその時に限り Y は X の(連続する)部分文字列であると言います。
- 以下の 2 つの操作から 1 つを選択して、その操作を行う。
- X の先頭の 1 文字を削除する。
- X の末尾の 1 文字を削除する。
例えば tag は voltage の(連続する)部分文字列ですが、 ace は atcoder の(連続する)部分文字列ではありません。
制約
- S,T は英小文字からなる
- 1 \le |S|,|T| \le 100 ( |X| は文字列 X の長さ )
入力
入力は以下の形式で標準入力から与えられる。
S T
出力
T が S の(連続する)部分文字列なら Yes 、そうでないなら No と出力せよ。
入力例 1
voltage tag
出力例 1
Yes
tag は voltage の(連続する)部分文字列です。
入力例 2
atcoder ace
出力例 2
No
ace は atcoder の(連続する)部分文字列ではありません。
入力例 3
gorilla gorillagorillagorilla
出力例 3
No
入力例 4
toyotasystems toyotasystems
出力例 4
Yes
S=T である場合もあります。
Score : 200 points
Problem Statement
You are given strings S and T consisting of lowercase English letters. Determine whether T is a (contiguous) substring of S.
A string Y is said to be a (contiguous) substring of X if and only if Y can be obtained by performing the operation below on X zero or more times.
- Do one of the following.
- Delete the first character in X.
- Delete the last character in X.
For instance, tag is a (contiguous) substring of voltage, while ace is not a (contiguous) substring of atcoder.
Constraints
- S and T consist of lowercase English letters.
- 1 \le |S|,|T| \le 100 (|X| denotes the length of a string X.)
Input
The input is given from Standard Input in the following format:
S T
Output
If T is a (contiguous) substring of S, print Yes; otherwise, print No.
Sample Input 1
voltage tag
Sample Output 1
Yes
tag is a (contiguous) substring of voltage.
Sample Input 2
atcoder ace
Sample Output 2
No
ace is not a (contiguous) substring of atcoder.
Sample Input 3
gorilla gorillagorillagorilla
Sample Output 3
No
Sample Input 4
toyotasystems toyotasystems
Sample Output 4
Yes
It is possible that S=T.
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 350 点
問題文
N 個の整数の組 (L_1,R_1),(L_2,R_2),\ldots,(L_N,R_N) が与えられます。
以下の条件を満たす長さ N の整数列 X=(X_1,X_2,\ldots,X_N) が存在するか判定し、存在するならば一つ出力してください。
- 各 i=1,2,\ldots,N に対して L_i\leq X_i\leq R_i
- \displaystyle \sum_{i=1}^N X_i=0
制約
- 1\leq N\leq 2\times 10^5
- -10^9\leq L_i\leq R_i\leq 10^9
- 入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N L_1 R_1 L_2 R_2 \vdots L_N R_N
出力
存在しない場合は No を出力せよ。存在する場合は条件を満たす整数列 X を以下の形式で出力せよ。
Yes X_1 X_2 \ldots X_N
答えが複数存在する場合、どれを出力しても正解とみなされる。
入力例 1
3 3 5 -4 1 -2 3
出力例 1
Yes 4 -3 -1
数列 X=(4,-3,-1) は問題の条件をすべて満たします。ほかにも (3,-3,0) や (5,-4,-1) などが条件を満たします。
入力例 2
3 1 2 1 2 1 2
出力例 2
No
条件を満たす整数列 X は存在しません。
入力例 3
6 -87 12 -60 -54 2 38 -76 6 87 96 -17 38
出力例 3
Yes -66 -57 31 -6 89 9
Score : 350 points
Problem Statement
You are given N pairs of integers (L_1, R_1), (L_2, R_2), \ldots, (L_N, R_N).
Determine whether there exists a sequence of N integers X = (X_1, X_2, \ldots, X_N) that satisfies the following conditions, and print one such sequence if it exists.
- L_i \leq X_i \leq R_i for each i = 1, 2, \ldots, N.
- \displaystyle \sum_{i=1}^N X_i = 0.
Constraints
- 1 \leq N \leq 2 \times 10^5
- -10^9 \leq L_i \leq R_i \leq 10^9
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N L_1 R_1 L_2 R_2 \vdots L_N R_N
Output
If no solution exists, print No. Otherwise, print an integer sequence X that satisfies the conditions in the following format:
Yes X_1 X_2 \ldots X_N
If multiple solutions exist, any of them will be considered correct.
Sample Input 1
3 3 5 -4 1 -2 3
Sample Output 1
Yes 4 -3 -1
The sequence X = (4, -3, -1) satisfies all the conditions. Other valid sequences include (3, -3, 0) and (5, -4, -1).
Sample Input 2
3 1 2 1 2 1 2
Sample Output 2
No
No sequence X satisfies the conditions.
Sample Input 3
6 -87 12 -60 -54 2 38 -76 6 87 96 -17 38
Sample Output 3
Yes -66 -57 31 -6 89 9
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 300 点
問題文
N 個のドミノが数直線上に一列に並んでいます。i 番目のドミノは座標 i の位置に立っており、高さは A_i です。
i 番目のドミノが右に倒れると、座標 i 以上 i+A_i 未満の範囲にあるドミノが全て右に倒れます。
1 番目のドミノを右に倒したとき、全部でいくつのドミノが倒れますか?
制約
- 1\leq N \leq 5\times 10^5
- 1\leq A_i \leq N
- 入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N A_1 A_2 \ldots A_N
出力
1 番目のドミノを右に倒したときに倒れるドミノの個数を出力せよ。
入力例 1
4 3 1 4 1
出力例 1
4
1 番目のドミノが右に倒れると、2,3 番目のドミノも右に倒れます。3 番目のドミノが右に倒れると、4 番目のドミノも倒れます。
入力例 2
9 1 4 1 4 2 1 3 5 6
出力例 2
1
1 番目のドミノを右に倒しても、他のドミノが倒れることはありません。
入力例 3
10 5 4 3 2 1 1 2 3 4 5
出力例 3
5
Score : 300 points
Problem Statement
There are N dominoes standing in a row on a number line. The i-th domino is standing at coordinate i and has height A_i.
When the i-th domino falls to the right, all dominoes in the range between coordinates i and i+A_i-1, inclusive, fall to the right.
How many dominoes will fall in total when the first domino falls to the right?
Constraints
- 1\leq N \leq 5\times 10^5
- 1\leq A_i \leq N
- 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
Output the number of dominoes that fall when the first domino falls to the right.
Sample Input 1
4 3 1 4 1
Sample Output 1
4
When the first domino falls to the right, the second and third dominoes also fall to the right. When the third domino falls to the right, the fourth domino also falls.
Sample Input 2
9 1 4 1 4 2 1 3 5 6
Sample Output 2
1
When the first domino falls to the right, no other dominoes will fall.
Sample Input 3
10 5 4 3 2 1 1 2 3 4 5
Sample Output 3
5
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 400 点
問題文
この問題は インタラクティブな問題(あなたが作成したプログラムとジャッジプログラムが標準入出力を介して対話を行う形式の問題)です。
ジャッジが 0 と 1 のみからなる長さ N の文字列 S = S_1S_2\ldots S_N を持っています。 文字列 S は、S_1 = 0 および S_N = 1 を満たします。
あなたには S の長さ N が与えられますが、S 自体は与えられません。 その代わり、あなたはジャッジに対して以下の質問を 20 回まで行うことができます。
- 1 \leq i \leq N を満たす整数 i を選び、S_i の値を尋ねる。
1 \leq p \leq N-1 かつ S_p \neq S_{p+1} を満たす整数 p を 1 個出力してください。
なお、本問題の条件下でそのような整数 p が必ず存在することが示せます。
制約
- 2 \leq N \leq 2 \times 10^5
入出力
最初に、文字列 S の長さ N を標準入力から受け取ってください。
N
次に、あなたはジャッジに対して問題文中の質問を 20 回まで繰り返すことができます。
質問は、以下の形式で標準出力に出力してください。 ここで、i は 1 \leq i \leq N を満たす整数でなければなりません。
? i
これに対する応答として、S_i の値が次の形式で標準入力から与えられます。
S_i
ここで、S_i は 0 または 1 です。
問題文中の条件を満たす整数 p を見つけたら、解答を以下の形式で出力してください。 その後、ただちにプログラムを終了してください。
! p
答えが複数ある場合、どれを出力しても正解とみなされます。
注意点
- 出力を行うたびに、末尾に改行を入れて標準出力を flush してください。そうしなかった場合、ジャッジ結果が TLE となる可能性があります。
- 対話の途中で不正な出力を行った、あるいはプログラムが途中で終了した場合のジャッジ結果は不定です。
- 解答を出力したらただちにプログラムを終了してください。そうしない場合、ジャッジ結果は不定です。
- 文字列 S はあなたとジャッジの対話の開始時に固定され、あなたが行った質問などに応じて変更されることはありません。
入出力例
以下は、N = 7, S = 0010011 の場合の入出力例です。
| 入力 | 出力 | 説明 |
|---|---|---|
7 |
N が与えられます。 | |
? 1 |
S_1 が何かをジャッジに質問します。 | |
0 |
質問に対する答えとして S_1 = 0 がジャッジから返されます。 | |
? 6 |
S_6 が何かをジャッジに質問します。 | |
1 |
質問に対する答えとして S_6 = 1 がジャッジから返されます。 | |
? 5 |
S_5 が何かをジャッジに質問します。 | |
0 |
質問に対する答えとして S_5 = 0 がジャッジから返されます。 | |
! 5 |
問題文中の条件を満たす整数 p として、p = 5 を解答します。 | |
解答した p = 5 について、1 \leq p \leq N-1 かつ S_p \neq S_{p+1} が成り立ちます。 よって、この後ただちにプログラムを終了することで、正解と判定されます。
Score : 400 points
Problem Statement
This is an interactive task, where your program and the judge interact via Standard Input and Output.
The judge has a string of length N consisting of 0 and 1: S = S_1S_2\ldots S_N. Here, S_1 = 0 and S_N = 1.
You are given the length N of S, but not the contents of S. Instead, you can ask the judge at most 20 questions as follows.
- Choose an integer i such that 1 \leq i \leq N and ask the value of S_i.
Print an integer p such that 1 \leq p \leq N-1 and S_p \neq S_{p+1}.
It can be shown that such p always exists under the settings of this problem.
Constraints
- 2 \leq N \leq 2 \times 10^5
Input and Output
First, receive the length N of the string S from Standard Input:
N
Then, you get to ask the judge at most 20 questions as described in the problem statement.
Print each question to Standard Output in the following format, where i is an integer satisfying 1 \leq i \leq N:
? i
In response to this, the value of S_i will be given from Standard Input in the following format:
S_i
Here, S_i is 0 or 1.
When you find an integer p satisfying the condition in the problem statement, print it in the following format, and immediately quit the program:
! p
If multiple solutions exist, you may print any of them.
Notes
- Print a newline and flush Standard Output at the end of each message. Otherwise, you may get a TLE verdict.
- If there is malformed output during the interaction or your program quits prematurely, the verdict will be indeterminate.
- After printing the answer, immediately quit the program. Otherwise, the verdict will be indeterminate.
- The string S will be fixed at the start of the interaction and will not be changed according to your questions or other factors.
Sample Input and Output
In the following interaction, N = 7 and S = 0010011.
| Input | Output | Description |
|---|---|---|
7 |
N is given. | |
? 1 |
Ask the value of S_1. | |
0 |
The judge responds with S_1 = 0. | |
? 6 |
Ask the value of S_6. | |
1 |
The judge responds with S_6 = 1. | |
? 5 |
Ask the value of S_5. | |
0 |
The judge responds with S_5 = 0. | |
! 5 |
Present p = 5 as an integer satisfying the condition. | |
For the presented p = 5, we have 1 \leq p \leq N-1 and S_p \neq S_{p+1}. Thus, if the program immediately quits here, this case will be judged as correctly solved.
実行時間制限: 4 sec / メモリ制限: 1024 MiB
配点 : 500 点
問題文
N 頂点 M 辺の重み付き無向連結グラフ G が与えられます。G には自己ループや多重辺が含まれている可能性があります。
頂点には頂点 1, 頂点 2, \dots, 頂点 N と番号がついています。
辺には辺 1, 辺 2, \dots, 辺 M と番号がついています。辺 i は頂点 a_i と頂点 b_i を結ぶ重み c_i の辺です。ここで、1 \leq i \lt j \leq M を満たすすべての整数の組 (i, j) について c_i \neq c_j が成り立ちます。
以下で説明される Q 個のクエリに答えてください。
i 番目のクエリでは整数の組 (u_i, v_i, w_i) が与えられます。ここで、1 \leq j \leq M を満たすすべての整数 j について w_i \neq c_j が成り立ちます。
頂点 u_i と頂点 v_i を結ぶ重み w_i の無向辺を e_i として、G に e_i を追加してできるグラフ G_i を考えます。
このとき G_i の最小全域木 T_i は一意に定まることが証明できますが、T_i に e_i は含まれるでしょうか?答えを Yes あるいは No で出力してください。
ここで、クエリの前後で G は変化しないことに注意してください。言い換えると、クエリ i で G に e_i を追加したグラフを考えたとしても、他のクエリで出てくる G に e_i が追加されていることはありません。
最小全域木とは?
G の 全域木 とは、G に含まれるすべての頂点と G に含まれる辺の一部からなる木のことを言います。G の 最小全域木 とは、G の全域木の中で辺の重みの和が最小である木のことを言います。
制約
- 2 \leq N \leq 2 \times 10^5
- N - 1 \leq M \leq 2 \times 10^5
- 1 \leq a_i \leq N (1 \leq i \leq M)
- 1 \leq b_i \leq N (1 \leq i \leq M)
- 1 \leq c_i \leq 10^9 (1 \leq i \leq M)
- c_i \neq c_j (1 \leq i \lt j \leq M)
- グラフ G は連結である。
- 1 \leq Q \leq 2 \times 10^5
- 1 \leq u_i \leq N (1 \leq i \leq Q)
- 1 \leq v_i \leq N (1 \leq i \leq Q)
- 1 \leq w_i \leq 10^9 (1 \leq i \leq Q)
- w_i \neq c_j (1 \leq i \leq Q, 1 \leq j \leq M)
- 入力はすべて整数である。
入力
入力は以下の形式で標準入力から与えられる。
N M Q a_1 b_1 c_1 a_2 b_2 c_2 \vdots a_M b_M c_M u_1 v_1 w_1 u_2 v_2 w_2 \vdots u_Q v_Q w_Q
出力
Q 行出力せよ。i 行目ではクエリ i への答えを Yes または No で出力せよ。
入力例 1
5 6 3 1 2 2 2 3 3 1 3 6 2 4 5 4 5 9 3 5 8 1 3 1 3 4 7 3 5 7
出力例 1
Yes No Yes
以下では頂点 u と頂点 v を結ぶ重み w の無向辺を (u,v,w) と表します。 G を図に表したものを以下に挙げます。

たとえばクエリ 1 では G に e_1 = (1,3,1) を追加したグラフ G_1 を考えます。G_1 の最小全域木 T_1 の辺集合は \lbrace (1,2,2),(1,3,1),(2,4,5),(3,5,8) \rbrace であり e_1 を含みます。よって Yes を出力します。
入力例 2
2 3 2 1 2 100 1 2 1000000000 1 1 1 1 2 2 1 1 5
出力例 2
Yes No
Score : 500 points
Problem Statement
Given is a weighted undirected connected graph G with N vertices and M edges, which may contain self-loops and multi-edges.
The vertices are labeled as Vertex 1, Vertex 2, \dots, Vertex N.
The edges are labeled as Edge 1, Edge 2, \ldots, Edge M. Edge i connects Vertex a_i and Vertex b_i and has a weight of c_i. Here, for every pair of integers (i, j) such that 1 \leq i \lt j \leq M, c_i \neq c_j holds.
Process the Q queries explained below.
The i-th query gives a triple of integers (u_i, v_i, w_i). Here, for every integer j such that 1 \leq j \leq M, w_i \neq c_j holds.
Let e_i be an undirected edge that connects Vertex u_i and Vertex v_i and has a weight of w_i. Consider the graph G_i obtained by adding e_i to G.
It can be proved that the minimum spanning tree T_i of G_i is uniquely determined. Does T_i contain e_i? Print the answer as Yes or No.
Note that the queries do not change T. In other words, even though Query i considers the graph obtained by adding e_i to G, the G in other queries does not have e_i.
What is minimum spanning tree?
The spanning tree of G is a tree with all of the vertices in G and some of the edges in G.The minimum spanning tree of G is the tree with the minimum total weight of edges among the spanning trees of G.
Constraints
- 2 \leq N \leq 2 \times 10^5
- N - 1 \leq M \leq 2 \times 10^5
- 1 \leq a_i \leq N (1 \leq i \leq M)
- 1 \leq b_i \leq N (1 \leq i \leq M)
- 1 \leq c_i \leq 10^9 (1 \leq i \leq M)
- c_i \neq c_j (1 \leq i \lt j \leq M)
- The graph G is connected.
- 1 \leq Q \leq 2 \times 10^5
- 1 \leq u_i \leq N (1 \leq i \leq Q)
- 1 \leq v_i \leq N (1 \leq i \leq Q)
- 1 \leq w_i \leq 10^9 (1 \leq i \leq Q)
- w_i \neq c_j (1 \leq i \leq Q, 1 \leq j \leq M)
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N M Q a_1 b_1 c_1 a_2 b_2 c_2 \vdots a_M b_M c_M u_1 v_1 w_1 u_2 v_2 w_2 \vdots u_Q v_Q w_Q
Output
Print Q lines. The i-th line should contain the answer to Query i: Yes or No.
Sample Input 1
5 6 3 1 2 2 2 3 3 1 3 6 2 4 5 4 5 9 3 5 8 1 3 1 3 4 7 3 5 7
Sample Output 1
Yes No Yes
Below, let (u,v,w) denote an undirected edge that connects Vertex u and Vertex v and has the weight of w. Here is an illustration of G:

For example, Query 1 considers the graph G_1 obtained by adding e_1 = (1,3,1) to G. The minimum spanning tree T_1 of G_1 has the edge set \lbrace (1,2,2),(1,3,1),(2,4,5),(3,5,8) \rbrace, which contains e_1, so Yes should be printed.
Sample Input 2
2 3 2 1 2 100 1 2 1000000000 1 1 1 1 2 2 1 1 5
Sample Output 2
Yes No
実行時間制限: 4 sec / メモリ制限: 1024 MiB
配点 : 525 点
問題文
右向きを x 軸正方向、上向きを y 軸正方向とする座標平面の原点にロボットがいます。ロボットは最初、x 軸正方向を向いています。
i=1,\ldots,N の順に以下の操作を行います:
- ロボットを右回りまたは左回りに 90 度回転させる。その後、ロボットは向いている方向に A_i 進む
回転方向を適切に選ぶことで、N 回の操作後にロボットがいる座標を (X,Y) にすることはできますか?
できるならば、各操作において、右回りと左回りのどちらを選べばよいか求めてください。
制約
- 1 \leq N \leq 80
- 1 \leq A_i \leq 10^7
- -10^9\leq X,Y \leq 10^9
- 入力は全て整数である
入力
入力は以下の形式で標準入力から与えられる。
N X Y A_1 \ldots A_N
出力
N 回の操作後にロボットがいる座標を (X,Y) にできないとき、No と出力せよ。
N 回の操作後にロボットがいる座標を (X,Y) にできるとき、1行目に Yes と出力し、2行目に次の条件を満たす長さ N の文字列 S を出力せよ。
条件: S は L または R のみからなり、S の i 番目の文字が L ならば i 回目の操作においてロボットを左回りに、R ならばロボットを右回りに回転させることで、N 回の操作後にロボットがいる座標を (X,Y) にできる。
答えが複数ある場合はどれを出力しても正解となる。
入力例 1
3 -2 4 3 2 1
出力例 1
Yes LLR
最初ロボットは (0,0) にいて、x 軸正方向を向いています。次の手順により、N 回の操作後にロボットがいる座標を (X,Y) にできます。
- 1 回目の操作:ロボットを左に 90 度回転させ、y 軸正方向を向かせる。ロボットは向いている方向に A_1=3 進み、ロボットのいる座標は (0,3) となる。
- 2 回目の操作:ロボットを左に 90 度回転させ、x 軸負方向を向かせる。ロボットは向いている方向に A_2=2 進み、ロボットのいる座標は (-2,3) となる。
- 3 回目の操作:ロボットを右に 90 度回転させ、y 軸正方向を向かせる。ロボットは向いている方向に A_3=1 進み、ロボットのいる座標は (-2,4) となる。

入力例 2
1 0 0 1
出力例 2
No
入力例 3
4 0 0 1 1 1 1
出力例 3
Yes LRRR
LLLL や RRRR などでも正解となります。
入力例 4
14 2543269 -1705099 3 14 159 2653 58979 323846 2643383 2795028 841971 69399 37510 58 20 9
出力例 4
Yes LLLLLLLLLRLRRR
Score : 525 points
Problem Statement
A robot is at the origin of a coordinate plane where the positive x-axis points to the right and the positive y-axis points upwards. Initially, the robot is facing the positive x-direction.
You will perform the following operation for i=1,\ldots,N in this order.
- Rotate the robot 90 degrees clockwise or counterclockwise. Then, the robot moves forward A_i units in the direction it is facing.
Can the direction of rotation be chosen so that the robot will be at the coordinates (X,Y) after the N operations?
If it is possible, determine which direction, clockwise or counterclockwise, should be chosen for each operation.
Constraints
- 1 \leq N \leq 80
- 1 \leq A_i \leq 10^7
- -10^9\leq X,Y \leq 10^9
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N X Y A_1 \ldots A_N
Output
If the robot cannot be at the coordinates (X,Y) after the N operations, print No.
If the robot can be at the coordinates (X,Y) after the N operations, the first line should contain Yes, and the second line should contain a string S of length N that satisfies the following condition.
Condition: S consists of L and R, and the following choices can put the robot at the coordinates (X,Y) after the N operations: in the i-th operation, rotate the robot counterclockwise if the i-th character of S is L, and rotate it clockwise if it is R.
If there are multiple solutions, you may print any of them.
Sample Input 1
3 -2 4 3 2 1
Sample Output 1
Yes LLR
Initially, the robot is at (0,0) and facing the positive x-direction. The following choices can put the robot at the coordinates (X,Y) after the N operations.
- First operation: Rotate the robot 90 degrees counterclockwise to face the positive y-direction. The robot moves forward A_1=3 units in the direction it is facing, and moves to (0,3).
- Second operation: Rotate the robot 90 degrees counterclockwise to face the negative x-direction. The robot moves forward A_2=2 units in the direction it is facing, and moves to (-2,3).
- Third operation: Rotate the robot 90 degrees clockwise to face the positive y-direction. The robot moves forward A_3=1 unit in the direction it is facing, and moves to (-2,4).

Sample Input 2
1 0 0 1
Sample Output 2
No
Sample Input 3
4 0 0 1 1 1 1
Sample Output 3
Yes LRRR
Outputs such as LLLL and RRRR are also accepted.
Sample Input 4
14 2543269 -1705099 3 14 159 2653 58979 323846 2643383 2795028 841971 69399 37510 58 20 9
Sample Output 4
Yes LLLLLLLLLRLRRR