実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 100 点
問題文
ある都にて、東軍と西軍が戦っています。
高橋君は戦っている軍勢の情報を文字列 S として記録しました。
S には文字 E と W のみが含まれており、 S に含まれる文字 E の数と東軍の人数、 W の数と西軍の人数がそれぞれ一致します。
高橋君が記録した S が与えられるので、東軍の人数が西軍の人数より多いなら East 、西軍の人数が東軍の人数より多いなら West と出力してください。
なお、 S の長さは奇数であることが保証されます。そのため、東軍と西軍のどちらか一方がもう一方に比べて真に人数が多い (つまり、両方の軍勢の人数が同じであることはない) ことが証明できます。
制約
- S は長さ 1 以上 99 以下の
EとWからなる文字列 - S の長さは奇数
入力
入力は以下の形式で標準入力から与えられる。
S
出力
答えを出力せよ。
入力例 1
EEWEW
出力例 1
East
S に E が 3 個、 W が 2 個含まれるため、東軍 3 人に対して西軍 2 人です。
東軍の人数が西軍の人数より多いので East と出力してください。
入力例 2
WWWWWWW
出力例 2
West
S に E が 0 個、 W が 7 個含まれるため、東軍 0 人に対して西軍 7 人です。
西軍の人数が東軍の人数より多いので West と出力してください。
Score : 100 points
Problem Statement
The Eastern Army and the Western Army are at war in a certain capital.
Takahashi recorded information about the fighting forces as a string S.
S contains only the characters E and W, and the number of Es in S equals the number of soldiers in the Eastern Army, and the number of Ws equals the number of soldiers in the Western Army.
Given the string S that Takahashi recorded, output East if the Eastern Army has more soldiers than the Western Army, or West if the Western Army has more soldiers than the Eastern Army.
The length of S is guaranteed to be odd. Thus, it can be proved that exactly one of the two armies strictly outnumbers the other (that is, the two armies cannot have the same number of soldiers).
Constraints
- S is a string of length between 1 and 99, inclusive, consisting of
EandW. - The length of S is odd.
Input
The input is given from Standard Input in the following format:
S
Output
Output the answer.
Sample Input 1
EEWEW
Sample Output 1
East
S contains three Es and two Ws, so the Eastern Army has three soldiers and the Western Army has two soldiers.
Since the Eastern Army has more soldiers than the Western Army, output East.
Sample Input 2
WWWWWWW
Sample Output 2
West
S contains zero Es and seven Ws, so the Eastern Army has zero soldiers and the Western Army has seven soldiers.
Since the Western Army has more soldiers than the Eastern Army, output West.
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 100 点
問題文
英大文字からなる長さ 3 の文字列 S が与えられます。S が ACE、BDF、CEG、DFA、EGB、FAC、GBD のいずれかと等しいとき Yes を、そうでないとき No を出力してください。
制約
- S は英大文字からなる長さ 3 の文字列
入力
入力は以下の形式で標準入力から与えられる。
S
出力
S が ACE、BDF、CEG、DFA、EGB、FAC、GBD のいずれかと等しいとき Yes を、そうでないとき No を出力せよ。
入力例 1
ABC
出力例 1
No
S = ABC のとき、S は ACE、BDF、CEG、DFA、EGB、FAC、GBD のいずれとも等しくないので No を出力します。
入力例 2
FAC
出力例 2
Yes
入力例 3
XYX
出力例 3
No
Score : 100 points
Problem Statement
Given a length-3 string S consisting of uppercase English letters, print Yes if S equals one of ACE, BDF, CEG, DFA, EGB, FAC, and GBD; print No otherwise.
Constraints
- S is a length-3 string consisting of uppercase English letters.
Input
The input is given from Standard Input in the following format:
S
Output
Print Yes if S equals one of ACE, BDF, CEG, DFA, EGB, FAC, and GBD; print No otherwise.
Sample Input 1
ABC
Sample Output 1
No
When S = ABC, S does not equal any of ACE, BDF, CEG, DFA, EGB, FAC, and GBD, so No should be printed.
Sample Input 2
FAC
Sample Output 2
Yes
Sample Input 3
XYX
Sample Output 3
No
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 150 点
問題文
N 個の整数 A_1,A_2,\dots,A_N が、 1 行に 1 つずつ、 N 行にわたって与えられます。但し、 N は入力では与えられません。
さらに、以下が保証されます。
- A_i \neq 0 ( 1 \le i \le N-1 )
- A_N = 0
A_N, A_{N-1},\dots,A_1 をこの順に出力してください。
制約
- 入力は全て整数
- 1 \le N \le 100
- 1 \le A_i \le 10^9 ( 1 \le i \le N-1 )
- A_N = 0
入力
入力は以下の形式で標準入力から与えられる。
A_1 A_2 \vdots A_N
出力
A_N, A_{N-1},\dots,A_1 をこの順に、改行区切りで整数として出力せよ。
入力例 1
3 2 1 0
出力例 1
0 1 2 3
繰り返しになりますが、 N は入力では与えられないことに注意してください。
この入力においては N=4 で、 A=(3,2,1,0) です。
入力例 2
0
出力例 2
0
A=(0) です。
入力例 3
123 456 789 987 654 321 0
出力例 3
0 321 654 987 789 456 123
Score: 150 points
Problem Statement
You are given N integers A_1,A_2,\dots,A_N, one per line, over N lines. However, N is not given in the input.
Furthermore, the following is guaranteed:
- A_i \neq 0 ( 1 \le i \le N-1 )
- A_N = 0
Print A_N, A_{N-1},\dots,A_1 in this order.
Constraints
- All input values are integers.
- 1 \le N \le 100
- 1 \le A_i \le 10^9 ( 1 \le i \le N-1 )
- A_N = 0
Input
The input is given from Standard Input in the following format:
A_1 A_2 \vdots A_N
Output
Print A_N, A_{N-1}, \dots, A_1 in this order, as integers, separated by newlines.
Sample Input 1
3 2 1 0
Sample Output 1
0 1 2 3
Note again that N is not given in the input. Here, N=4 and A=(3,2,1,0).
Sample Input 2
0
Sample Output 2
0
A=(0).
Sample Input 3
123 456 789 987 654 321 0
Sample Output 3
0 321 654 987 789 456 123
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 200 点
問題文
文字列 S が文字列 T の部分文字列であるとは、次の条件を満たすような整数 i, j (1 \leq i \leq j \leq |T|) が存在することを言います。
- T の i 文字目から j 文字目までを順番を変えずに抜き出してできる文字列が S と一致する。
文字列 T を oxx を 10^5 個結合した文字列として定めます。
文字列 S が与えられるので、 S が T の部分文字列である場合は Yes を、そうでない場合は No を出力してください。
制約
- S は
oとxのみからなる文字列である。 - S の長さは 1 以上 10 以下である。
入力
入力は以下の形式で標準入力から与えられる。
S
出力
S が条件を満たす場合は Yes を、そうでない場合は No を出力せよ。
入力例 1
xoxxoxxo
出力例 1
Yes
T のはじめの方を抜き出すと oxxoxxoxxoxx... となっています。
T の 3 文字目から 10 文字目までを抜き出した文字列は S と一致するので、 S は T の部分文字列です。よって Yes を出力します。
入力例 2
xxoxxoxo
出力例 2
No
T から文字列をどのように抜き出しても S と一致しないので、S は T の部分文字列でありません。よって No を出力します。
入力例 3
ox
出力例 3
Yes
Score : 200 points
Problem Statement
A string S is said to be a substring of a string T when there is a pair of integers i and j (1 \leq i \leq j \leq |T|) that satisfy the following condition.
- The extraction of the i-th through j-th characters of T without changing the order equals S.
Let T be the concatenation of 10^5 copies of oxx.
Given a string S, print Yes if S is a substring of T, and No otherwise.
Constraints
- S is a string consisting of
oandx. - The length of S is between 1 and 10 (inclusive).
Input
Input is given from Standard Input in the following format:
S
Output
If S satisfies the condition, print Yes; otherwise, print No.
Sample Input 1
xoxxoxxo
Sample Output 1
Yes
T begins like this: oxxoxxoxxoxx...
Since the extraction of 3-rd through 10-th characters of T equals S, S is a substring of T, so Yes should be printed.
Sample Input 2
xxoxxoxo
Sample Output 2
No
Since there is no way to extract from T a string that equals S, S is not a substring of T, so No should be printed.
Sample Input 3
ox
Sample Output 3
Yes
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 300 点
問題文
N 個のカップがあり、それぞれのカップには無色透明な液体が入っています。
具体的には、i 番目 (1\leq i\leq N) のカップには A_i ml の液体が入っています。
また、これらのうちちょうど K 個のカップには日本酒が入っており、それ以外には水が入っていることが分かっています。
ただし、どのカップに日本酒が入っているかについては分かっていません。
高橋君は(1 つ以上の)いくつかのカップを選んでそれらに入った液体をすべて飲むことができます。
どのカップに日本酒が入っているかによらず、高橋君が確実に X ml 以上の日本酒を飲むためには、最低何個のカップを選ぶ必要があるか求めてください。
そのような選び方が不可能である場合には -1 を出力してください。
制約
- 1 \leq K \leq N \leq 3\times 10^5
- 1 \leq A_i \leq 10^9
- 1 \leq X \leq 3\times 10^{14}
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N K X A_1 A_2 \ldots A_N
出力
条件をみたすために高橋君が選ぶ必要があるカップの個数の最小値を出力せよ。 そのような選び方が不可能である場合には -1 を出力せよ。
入力例 1
3 2 5 10 6 8
出力例 1
2
高橋君が 1 番目と 3 番目のカップを選んで飲んだ場合を考えます。
3 個のカップのうち 2 個に日本酒が入っているため、次の 3 通りが考えられます。
- 1,2 番目のカップに日本酒が入っていた場合
高橋君は 10 ml の日本酒と 8 ml の水を飲むことになります。
- 1,3 番目のカップに日本酒が入っていた場合
高橋君は 18 ml の日本酒を飲むことになります。
- 2,3 番目のカップに日本酒が入っていた場合
高橋君は 8 ml の日本酒と 10 ml の水を飲むことになります。
よって、いずれの場合でも 5 ml 以上の日本酒を飲むことができます。
一方で、どのカップに日本酒が入っているか分かっていない状態で、1 つのみのカップを選んで条件をみたすようにすることは不可能です。
よって、2 を出力します。
入力例 2
2 1 8 6 10
出力例 2
-1
1 番目のカップに日本酒が入っていた場合、どのようにカップを選んでも 8 ml 以上の日本酒を飲むことは不可能です。
よって、-1 を出力します。
入力例 3
5 3 3000000000 1000000000 1000000000 1000000000 1000000000 1000000000
出力例 3
5
Score : 300 points
Problem Statement
There are N cups, each containing a colorless and transparent liquid.
Specifically, the i-th (1\leq i\leq N) cup contains A_i ml of liquid.
It is known that exactly K of these cups contain sake (rice wine), and the rest contain water.
However, it is not known which cups contain sake.
Takahashi can choose some (one or more) cups and drink all the liquid in them.
Find the minimum number of cups he needs to choose to ensure he drinks at least X ml of sake, regardless of which cups contain sake.
If such a choice is impossible, print -1.
Constraints
- 1 \leq K \leq N \leq 3\times 10^5
- 1 \leq A_i \leq 10^9
- 1 \leq X \leq 3\times 10^{14}
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N K X A_1 A_2 \ldots A_N
Output
Print the minimum number of cups Takahashi needs to choose to satisfy the condition. If such a choice is impossible, print -1.
Sample Input 1
3 2 5 10 6 8
Sample Output 1
2
Consider the case where Takahashi chooses the first and third cups and drinks them.
Two out of the three cups contain sake, so the following three cases are possible:
- If the first and second cups contain sake
He drinks 10 ml of sake and 8 ml of water.
- If the first and third cups contain sake
He drinks 18 ml of sake.
- If the second and third cups contain sake
He drinks 8 ml of sake and 10 ml of water.
Thus, in all cases, he can drink at least 5 ml of sake.
On the other hand, it is impossible to satisfy the condition by choosing only one cup without knowing which cups contain sake.
Therefore, print 2.
Sample Input 2
2 1 8 6 10
Sample Output 2
-1
If the first cup contained sake, it is impossible to drink 8 ml or more of sake no matter which cups are chosen.
Therefore, print -1.
Sample Input 3
5 3 3000000000 1000000000 1000000000 1000000000 1000000000 1000000000
Sample Output 3
5