実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 100 点
問題文
高橋くんは、朝食にご飯、味噌汁、サラダを 1 皿ずつ食べます。
高橋くんの家のテーブルは細長いので、 3 皿を横一列に並べました。並べ方は文字列 S によって与えられ、左から i 番目の皿は S_i が R ならご飯、 S_i が M なら味噌汁、 S_i が S ならサラダです。
ご飯の皿が味噌汁の皿より左にあるかどうかを判定してください。
制約
- |S| = 3
- S には
RMSが 1 文字ずつ含まれる
入力
入力は以下の形式で標準入力から与えられる。
S
出力
ご飯の皿が味噌汁の皿より左にあれば Yes 、そうでなければ No を出力してください。
入力例 1
RSM
出力例 1
Yes
ご飯の皿は左から 1 番目にあり、味噌汁の皿は左から 3 番目にあります。ご飯の皿の方が左にあるので、 Yes を出力します。
入力例 2
SMR
出力例 2
No
左から順に、サラダの皿、味噌汁の皿、ご飯の皿と並んでいます。
Score : 100 points
Problem Statement
Takahashi eats three plates for breakfast: rice, miso soup, and salad.
His table is long and narrow, so he arranged the three plates in a row. The arrangement is given by a string S, where the i-th plate from the left is rice if S_i is R, miso soup if S_i is M, and salad if S_i is S.
Determine whether the plate of rice is to the left of the plate of miso soup.
Constraints
- |S| = 3
- S contains one
R, oneM, and oneS.
Input
The input is given from Standard Input in the following format:
S
Output
Print Yes if the plate of rice is to the left of the plate of miso soup, and No otherwise.
Sample Input 1
RSM
Sample Output 1
Yes
The plate of rice is at the 1st position from the left, and the plate of miso soup is at the 3rd position from the left. Since the plate of rice is to the left, print Yes.
Sample Input 2
SMR
Sample Output 2
No
The plates are arranged as salad, miso soup, and rice from left to right.
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 100 点
問題文
o, x からなる長さ N の文字列 S と整数 L,R が与えられます。
S の L 文字目から R 文字目までが全て o であるかどうか判定してください。
制約
- 1\leq N \leq 100
- 1\leq L \leq R \leq N
- S は
o,xのみからなる長さ N の文字列 - N,L,R は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N L R S
出力
S の L 文字目から R 文字目までが全て o なら Yes、そうでないなら No と出力せよ。
入力例 1
10 6 8 xoxxooooxo
出力例 1
Yes
S の 6 文字目から 8 文字目は全て o なので答えは Yes です。
入力例 2
9 6 8 xoxxoxoox
出力例 2
No
6 文字目が x なので答えは No です。
Score : 100 points
Problem Statement
You are given a string S of length N consisting of o and x, and integers L and R.
Determine whether all characters from the L-th through the R-th character of S are o.
Constraints
- 1\leq N \leq 100
- 1\leq L \leq R \leq N
- S is a string of length N consisting of
oandx. - N, L, and R are all integers.
Input
The input is given from Standard Input in the following format:
N L R S
Output
If all characters from the L-th through the R-th character of S are o, output Yes; otherwise, output No.
Sample Input 1
10 6 8 xoxxooooxo
Sample Output 1
Yes
All characters from the 6-th through the 8-th character of S are o, so the answer is Yes.
Sample Input 2
9 6 8 xoxxoxoox
Sample Output 2
No
The 6-th character is x, so the answer is No.
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 200 点
問題文
H 行 W 列のグリッドがあります。グリッドの上から i 番目、左から j 番目のマスをマス (i, j) と表記します。
マス (i, j) は C_{i, j} が . のとき空きマスであり、# のとき空きマスではありません。
高橋君は現在マス (S_i, S_j) におり、i = 1, 2, \ldots, |X| の順に以下のルールに従って行動します。
- X の i 文字目が
Lのとき、高橋君が現在いるマスの 1 つ左のマスが存在し、そのマスが空きマスならば 1 つ左のマスに移動する。そうでないならば、現在いるマスに留まる。 - X の i 文字目が
Rのとき、高橋君が現在いるマスの 1 つ右のマスが存在し、そのマスが空きマスならば 1 つ右のマスに移動する。そうでないならば、現在いるマスに留まる。 - X の i 文字目が
Uのとき、高橋君が現在いるマスの 1 つ上のマスが存在し、そのマスが空きマスならば 1 つ上のマスに移動する。そうでないならば、現在いるマスに留まる。 - X の i 文字目が
Dのとき、高橋君が現在いるマスの 1 つ下のマスが存在し、そのマスが空きマスならば 1 つ下のマスに移動する。そうでないならば、現在いるマスに留まる。
一連の行動を終えた後高橋君がどのマスにいるか出力してください。
制約
- 1 \leq H, W \leq 50
- 1 \leq S_i \leq H
- 1 \leq S_j \leq W
- H, W, S_i, S_j は整数
- C_{i, j} は
.または# - C_{S_i, S_j} =
. - X は
L,R,U,Dからなる長さ 1 以上 50 以下の文字列
入力
入力は以下の形式で標準入力から与えられる。
H W
S_i S_j
C_{1, 1}C_{1, 2}\ldotsC_{1, W}
C_{2, 1}C_{2, 2}\ldotsC_{2, W}
\vdots
C_{H, 1}C_{H, 2}\ldotsC_{H, W}
X
出力
高橋君が一連の行動を終えた後にいるマスをマス (x, y) として、x と y をこの順に空白区切りで出力せよ。
入力例 1
2 3 2 1 .#. ... ULDRU
出力例 1
2 2
高橋君ははじめマス (2, 1) にいます。高橋君の一連の行動は以下のようになります。
- X の 1 文字目は
Uであり、マス (2, 1) の 1 つ上のマスは存在し、そのマスは空きマスであるため 1 つ上のマスであるマス (1, 1) に移動する。 - X の 2 文字目は
Lであり、マス (1, 1) の 1 つ左のマスは存在しないためマス (1, 1) に留まる。 - X の 3 文字目は
Dであり、マス (1, 1) の 1 つ下のマスは存在し、そのマスは空きマスであるため 1 つ下のマスであるマス (2, 1) に移動する。 - X の 4 文字目は
Rであり、マス (2, 1) の 1 つ右のマスは存在し、そのマスは空きマスであるため 1 つ右のマスであるマス (2, 2) に移動する。 - X の 5 文字目は
Uであり、マス (2, 2) の 1 つ上のマスは存在するが、そのマスは空きマスではないためマス (2, 2) に留まる。
したがって一連の行動を終えた後に高橋君がいるマスはマス (2, 2) です。
入力例 2
4 4 4 2 .... .#.. ...# .... DUUUURULRD
出力例 2
2 4
入力例 3
6 6 1 1 .##### ###### ###### ###### ###### ###### RURLDLULLRULRDL
出力例 3
1 1
Score : 200 points
Problem Statement
There is a grid with H rows and W columns. Let (i, j) denote the cell at the i-th row from the top and j-th column from the left.
Cell (i, j) is empty if C_{i, j} is ., and not empty if C_{i, j} is #.
Takahashi is currently at cell (S_i, S_j), and he will act according to the following rules for i = 1, 2, \ldots, |X| in order.
- If the i-th character of X is
L, and the cell to the left of his current cell exists and is empty, he moves to the cell to the left. Otherwise, he stays in the current cell. - If the i-th character of X is
R, and the cell to the right of his current cell exists and is empty, he moves to the cell to the right. Otherwise, he stays in the current cell. - If the i-th character of X is
U, and the cell above his current cell exists and is empty, he moves to the cell above. Otherwise, he stays in the current cell. - If the i-th character of X is
D, and the cell below his current cell exists and is empty, he moves to the cell below. Otherwise, he stays in the current cell.
Print the cell where he is after completing the series of actions.
Constraints
- 1 \leq H, W \leq 50
- 1 \leq S_i \leq H
- 1 \leq S_j \leq W
- H, W, S_i, S_j are integers.
- C_{i, j} is
.or#. - C_{S_i, S_j} =
. - X is a string of length between 1 and 50, inclusive, consisting of
L,R,U,D.
Input
The input is given from Standard Input in the following format:
H W
S_i S_j
C_{1, 1}C_{1, 2}\ldotsC_{1, W}
C_{2, 1}C_{2, 2}\ldotsC_{2, W}
\vdots
C_{H, 1}C_{H, 2}\ldotsC_{H, W}
X
Output
Let (x, y) be the cell where Takahashi is after completing the series of actions. Print x and y, separated by a space.
Sample Input 1
2 3 2 1 .#. ... ULDRU
Sample Output 1
2 2
Takahashi starts at cell (2, 1). His series of actions are as follows:
- The 1st character of X is
U, and the cell above (2, 1) exists and is an empty cell, so he moves to the cell above, which is (1, 1). - The 2nd character of X is
L, and the cell to the left of (1, 1) does not exist, so he stays at (1, 1). - The 3rd character of X is
D, and the cell below (1, 1) exists and is an empty cell, so he moves to the cell below, which is (2, 1). - The 4th character of X is
R, and the cell to the right of (2, 1) exists and is an empty cell, so he moves to the cell to the right, which is (2, 2). - The 5th character of X is
U, and the cell above (2, 2) exists but is not an empty cell, so he stays at (2, 2).
Therefore, after completing the series of actions, he is at cell (2, 2).
Sample Input 2
4 4 4 2 .... .#.. ...# .... DUUUURULRD
Sample Output 2
2 4
Sample Input 3
6 6 1 1 .##### ###### ###### ###### ###### ###### RURLDLULLRULRDL
Sample Output 3
1 1
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 200 点
問題文
長さ N の整数列 A=(A_1,A_2,\dots,A_N) および正整数 M が与えられます。
A の末尾の要素を削除するという操作を 0 回以上 N 回以下行うことで、以下の条件が満たされないようにしたいです。
- 条件:A には 1 以上 M 以下の整数がすべて含まれている。
必要な操作回数の最小値を求めてください。
なお、本問題の制約下において、操作を 0 回以上 N 回以下行うことで上述の条件が満たされないようにすることが必ず可能であることが証明できます。
制約
- 1\leq M \leq N \leq 100
- 1\leq A_i \leq M
- 入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N M A_1 A_2 \dots A_N
出力
条件が満たされなくなるために必要な操作回数の最小値を出力せよ。
入力例 1
5 3 3 2 3 1 2
出力例 1
2
最初、A=(3,2,3,1,2) です。このとき、A には 1 以上 3 以下の整数がすべて含まれるため条件を満たします。
A の末尾の要素を削除する操作を 1 回行うと、A=(3,2,3,1) となります。このとき、A には 1 以上 3 以下の整数がすべて含まれるため条件を満たします。
A の末尾の要素を削除する操作をもう 1 回行うと、A=(3,2,3) となります。このとき、A には 1 が含まれないため条件を満たしません。
よって、条件が満たされなくなるために必要な操作回数の最小値は 2 です。
入力例 2
4 3 1 3 1 3
出力例 2
0
A には最初から 2 が含まれず条件を満たさないため、操作を 1 回も行う必要がありません。
入力例 3
10 4 1 3 3 4 2 1 3 1 2 4
出力例 3
6
Score : 200 points
Problem Statement
You are given an integer sequence A = (A_1, A_2, \dots, A_N) of length N and a positive integer M.
Your goal is to make the following condition false by performing this operation between 0 and N times (inclusive): remove the last element of A.
- Condition: A contains every integer from 1 through M.
Find the minimum number of operations required.
Under the constraints of this problem, it can be proved that it is always possible to make the condition false by performing the operation between 0 and N times.
Constraints
- 1 \le M \le N \le 100
- 1 \le A_i \le M
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N M A_1 A_2 \dots A_N
Output
Output the minimum number of operations required to make the condition false.
Sample Input 1
5 3 3 2 3 1 2
Sample Output 1
2
Initially, A = (3,2,3,1,2). Since A contains every integer from 1 through 3, the condition holds.
If you perform the operation once, A = (3,2,3,1). The condition still holds.
If you perform the operation once more, A = (3,2,3). The integer 1 is missing, so the condition no longer holds.
Therefore, the minimum required number of operations is 2.
Sample Input 2
4 3 1 3 1 3
Sample Output 2
0
Since A initially lacks the integer 2, the condition is already false, so no operation is needed.
Sample Input 3
10 4 1 3 3 4 2 1 3 1 2 4
Sample Output 3
6
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 350 点
問題文
文字列 S が与えられます。次の操作を ちょうど 1 回 行った後の文字列としてあり得るものがいくつあるか求めてください。
- S の長さを N とする。 1\leq i<j\leq N をみたす整数の組 (i,j) を選び、S の i 文字目と j 文字目を入れ替える。
なお、この問題の制約下で操作を必ず行うことができることが証明できます。
制約
- S は英小文字からなる長さ 2 以上 10^6 以下の文字列
入力
入力は以下の形式で標準入力から与えられる。
S
出力
S に対して問題文中の操作をちょうど 1 回行った後の文字列としてあり得るものの個数を出力せよ。
入力例 1
abc
出力例 1
3
S の長さは 3 であるため、1\leq i<j\leq 3 をみたす整数の組 (i,j) としては、 (1,2), (1,3), (2,3) の 3 通りが考えられます。
- S の 1 文字目と 2 文字目を入れ替えた時、S は
bacとなります。 - S の 1 文字目と 3 文字目を入れ替えた時、S は
cbaとなります。 - S の 2 文字目と 3 文字目を入れ替えた時、S は
acbとなります。
よって、abc に対して操作を行った後の文字列としては、bac, cba, acb の 3 つがあり得るため、3 を出力します。
入力例 2
aaaaa
出力例 2
1
どの 2 つの文字を入れ替えても S は aaaaa のままです。よって、操作後の文字列としてあり得るものは 1 つです。
Points: 350 points
Problem Statement
You are given a string S. Find the number of strings that can result from performing the following operation exactly once.
- Let N be the length of S. Choose a pair of integers (i,j) such that 1\leq i<j\leq N and swap the i-th and j-th characters of S.
It can be proved that you can always perform it under the constraints of this problem.
Constraints
- S is a string of length between 2 and 10^6, inclusive, consisting of lowercase English letters.
Input
The input is given from Standard Input in the following format:
S
Output
Print the number of strings that can result from performing the operation in the problem statement exactly once on S.
Sample Input 1
abc
Sample Output 1
3
The length of S is 3, so 1\leq i<j\leq 3 is satisfied by three pairs of integers (i,j): (1,2), (1,3), and (2,3).
- Swapping the 1-st and 2-nd characters of S results in S being
bac. - Swapping the 1-st and 3-rd characters of S results in S being
cba. - Swapping the 2-nd and 3-rd characters of S results in S being
acb.
Therefore, the operation on abc results in one of the three strings: bac, cba, and acb, so print 3.
Sample Input 2
aaaaa
Sample Output 2
1
Swapping any two characters results in S remaining aaaaa. Thus, only one string can result from the operation.