実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 100 点
問題文
高橋くんは、頭パーツを 1 個と体パーツを 1 個組み合わせてロボットを 1 体作ることができます。 ロボットは頭パーツの重さが体パーツの重さより大きいと倒れてしまいます。
現在、高橋くんは頭パーツと体パーツを 1 個ずつ持っています。 高橋くんが持っている頭パーツの重さは H グラム、体パーツの重さは B グラムです。
高橋くんは、体パーツを重くすることで、ロボットを倒れないようにしたいです。 高橋くんが作るロボットが倒れないようにするためには、体パーツをあと何グラム重くする必要があるか求めてください。
制約
- 1\le H\le100
- 1\le B\le100
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
H B
出力
答えを出力せよ。
入力例 1
43 1
出力例 1
42
高橋くんは、体パーツを 42 グラム重くすることで、頭パーツと体パーツの重さを等しくすることができます。
体パーツを重くする量が 42 グラム未満のとき、高橋くんが作るロボットは倒れてしまうため、42 を出力してください。
入力例 2
4 31
出力例 2
0
高橋くんがこのままロボットを作ってもロボットは倒れないため、0 を出力してください。
入力例 3
1 1
出力例 3
0
Score : 100 points
Problem Statement
Takahashi can combine a head part and a body part to create a robot. A robot falls over if the weight of the head part is greater than the weight of the body part.
Currently, he has one head part and one body part. The weight of the head part is H grams, and the weight of the body part is B grams.
He wants to make the body part heavier so that the robot does not fall over. Find how many more grams the body part needs to be made heavier so that his robot does not fall over.
Constraints
- 1\le H\le100
- 1\le B\le100
- All input values are integers.
Input
The input is given from Standard Input in the following format:
H B
Output
Print the answer.
Sample Input 1
43 1
Sample Output 1
42
By making the body part 42 grams heavier, Takahashi can make the weights of the head part and body part equal.
When the amount by which the body part is made heavier is less than 42 grams, his robot will fall over, so print 42.
Sample Input 2
4 31
Sample Output 2
0
Even if he creates the robot as is, the robot will not fall over, so print 0.
Sample Input 3
1 1
Sample Output 3
0
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 100 点
問題文
英小文字 a, b, \ldots, z の ASCII 文字コードはこの順に 97,98,\ldots,122 です。
97 以上 122 以下の整数 N が与えられるので、ASCII 文字コードが N であるような英小文字を出力してください。
制約
- N は 97 以上 122 以下の整数
入力
入力は以下の形式で標準入力から与えられる。
N
出力
答えを出力せよ。
入力例 1
97
出力例 1
a
ASCII 文字コードが 97 である英小文字は a です。
入力例 2
122
出力例 2
z
Score : 100 points
Problem Statement
The ASCII values of the lowercase English letters a, b, \ldots, z are 97,98,\ldots,122 in this order.
Given an integer N between 97 and 122, print the letter whose ASCII value is N.
Constraints
- N is an integer between 97 and 122 (inclusive).
Input
Input is given from Standard Input in the following format:
N
Output
Print the answer.
Sample Input 1
97
Sample Output 1
a
97 is the ASCII value of a.
Sample Input 2
122
Sample Output 2
z
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 200 点
問題文
英小文字と英大文字からなる文字列 S が与えられます。S の長さは奇数です。
S に含まれる大文字の個数が小文字の個数よりも多ければ、S に含まれる全ての小文字を大文字に変換してください。
そうでない場合は、S に含まれる全ての大文字を小文字に変換してください。
制約
- S は英小文字および英大文字からなる文字列
- S の長さは 1 以上 99 以下の奇数
入力
入力は以下の形式で標準入力から与えられる。
S
出力
問題文の指示に従って文字を変換した後の S を出力せよ。
入力例 1
AtCoder
出力例 1
atcoder
AtCoder に含まれる小文字の個数は 5 個、大文字の個数は 2 個です。よって AtCoder に含まれる全ての大文字を小文字に変換した atcoder が答えとなります。
入力例 2
SunTORY
出力例 2
SUNTORY
SunTORY に含まれる小文字の個数は 2 個、大文字の個数は 5 個です。よって SunTORY に含まれる全ての小文字を大文字に変換した SUNTORY が答えとなります。
入力例 3
a
出力例 3
a
Score : 200 points
Problem Statement
You are given a string S consisting of lowercase and uppercase English letters. The length of S is odd.
If the number of uppercase letters in S is greater than the number of lowercase letters, convert all lowercase letters in S to uppercase.
Otherwise, convert all uppercase letters in S to lowercase.
Constraints
- S is a string consisting of lowercase and uppercase English letters.
- The length of S is an odd number between 1 and 99, inclusive.
Input
The input is given from Standard Input in the following format:
S
Output
Print the string S after converting the letters according to the problem statement.
Sample Input 1
AtCoder
Sample Output 1
atcoder
The string AtCoder contains five lowercase letters and two uppercase letters. Thus, convert all uppercase letters in AtCoder to lowercase, which results in atcoder.
Sample Input 2
SunTORY
Sample Output 2
SUNTORY
The string SunTORY contains two lowercase letters and five uppercase letters. Thus, convert all lowercase letters in SunTORY to uppercase, which results in SUNTORY.
Sample Input 3
a
Sample Output 3
a
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 200 点
問題文
縦 H 行横 W 列のマス目があります。上から i 行目、左から j 列目のマスをマス (i,j) と表します。
マス (i,j) は S_{i,j} が # のとき通行不可能、. のとき通行可能であり家が建っていない、@ のとき通行可能であり家が建っていることを表します。
最初、マス (X,Y) にサンタクロースがいます。サンタクロースは文字列 T に従って以下の行動を行います。
- 文字列 T の長さを |T| とする。i=1,2,\ldots,|T| の順に以下のように移動する。
- 現在サンタクロースがいるマスを (x,y) とする。
- T_i が
Uかつマス (x-1,y) が通行可能ならマス (x-1,y) に移動する。 - T_i が
Dかつマス (x+1,y) が通行可能ならマス (x+1,y) に移動する。 - T_i が
Lかつマス (x,y-1) が通行可能ならマス (x,y-1) に移動する。 - T_i が
Rかつマス (x,y+1) が通行可能ならマス (x,y+1) に移動する。 - それ以外の場合、マス (x,y) に留まる。
- T_i が
- 現在サンタクロースがいるマスを (x,y) とする。
行動を終えたあとにサンタクロースがいるマスと、行動により通過または到達した家の数を求めてください。ただし、同じ家を複数回通過または到達してもそれらは重複して数えません。
制約
- 3 \leq H,W \leq 100
- 1 \leq X \leq H
- 1 \leq Y \leq W
- 与えられる数値は全て整数である
- S_{i,j} は
#,.,@のいずれか - 全ての 1 \leq i \leq H について S_{i,1},S_{i,W} は
# - 全ての 1 \leq j \leq W について S_{1,j},S_{H,j} は
# - S_{X,Y}=
. - T は
U,D,L,Rのいずれかからなる長さ 1 以上 10^4 以下の文字列
入力
入力は以下の形式で標準入力から与えられる。
H W X Y
S_{1,1}S_{1,2}\ldots S_{1,W}
\dots
S_{H,1}S_{H,2}\ldots S_{H,W}
T
出力
行動を終えたあとサンタクロースがいるマスを (X,Y)、行動により通過または到達した家の数を C とするとき、X,Y,C をこの順に空白区切りで出力せよ。
入力例 1
5 5 3 4 ##### #...# #.@.# #..@# ##### LLLDRUU
出力例 1
2 3 1
サンタクロースは以下のように行動します。

- T_1=
Lなのでマス (3,4) からマス (3,3) に移動する。これにより家を通過する。 - T_2=
Lなのでマス (3,3) からマス (3,2) に移動する。 - T_3=
Lだがマス (3,1) は通行不可能なので、マス (3,2) に留まる。 - T_4=
Dなのでマス (3,2) からマス (4,2) に移動する。 - T_5=
Rなのでマス (4,2) からマス (4,3) に移動する。 - T_6=
Uなのでマス (4,3) からマス (3,3) に移動する。これにより家を通過するが、この家はすでに通過したことがある家である。 - T_7=
Uなのでマス (3,3) からマス (2,3) に移動する。
行動により通過または到達した家の数は 1 です。
入力例 2
6 13 4 6 ############# #@@@@@@@@@@@# #@@@@@@@@@@@# #@@@@.@@@@@@# #@@@@@@@@@@@# ############# UURUURLRLUUDDURDURRR
出力例 2
3 11 11
入力例 3
12 35 7 10 ################################### #.................................# #..........@......................# #......@................@.........# #.............##............@.....# #...##........##....##............# #...##........##....##.......##...# #....##......##......##....##.....# #....##......##......##..##.......# #.....#######.........###.........# #.................................# ################################### LRURRRUUDDULUDUUDLRLRDRRLULRRUDLDRU
出力例 3
4 14 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 the j-th column from the left.
If S_{i,j} is #, the cell (i,j) is impassable; if it is ., the cell is passable and contains no house; if it is @, the cell is passable and contains a house.
Initially, Santa Claus is in cell (X,Y). He will act according to the string T as follows.
- Let |T| be the length of the string T. For i=1,2,\ldots,|T|, he moves as follows.
- Let (x,y) be the cell he is currently in.
- If T_i is
Uand cell (x-1,y) is passable, move to cell (x-1,y). - If T_i is
Dand cell (x+1,y) is passable, move to cell (x+1,y). - If T_i is
Land cell (x,y-1) is passable, move to cell (x,y-1). - If T_i is
Rand cell (x,y+1) is passable, move to cell (x,y+1). - Otherwise, stay in cell (x,y).
- If T_i is
- Let (x,y) be the cell he is currently in.
Find the cell where he is after completing all actions, and the number of distinct houses that he passed through or arrived at during his actions. If the same house is passed multiple times, it is only counted once.
Constraints
- 3 \leq H,W \leq 100
- 1 \leq X \leq H
- 1 \leq Y \leq W
- All given numbers are integers.
- Each S_{i,j} is one of
#,.,@. - S_{i,1} and S_{i,W} are
#for every 1 \leq i \leq H. - S_{1,j} and S_{H,j} are
#for every 1 \leq j \leq W. - S_{X,Y}=
. - T is a string of length at least 1 and at most 10^4, consisting of
U,D,L,R.
Input
The Input is given from Standard Input in the following format:
H W X Y
S_{1,1}S_{1,2}\ldots S_{1,W}
\dots
S_{H,1}S_{H,2}\ldots S_{H,W}
T
Output
Let (X,Y) be the cell where he is after completing all actions, and C be the number of distinct houses he passed through or arrived at during his actions. Print X,Y,C in this order separated by spaces.
Sample Input 1
5 5 3 4 ##### #...# #.@.# #..@# ##### LLLDRUU
Sample Output 1
2 3 1
Santa Claus behaves as follows:

- T_1=
L, so he moves from (3,4) to (3,3). A house is passed. - T_2=
L, so he moves from (3,3) to (3,2). - T_3=
L, but cell (3,1) is impassable, so he stays at (3,2). - T_4=
D, so he moves from (3,2) to (4,2). - T_5=
R, so he moves from (4,2) to (4,3). - T_6=
U, so he moves from (4,3) to (3,3). A house is passed, but it has already been passed. - T_7=
U, so he moves from (3,3) to (2,3).
The number of houses he passed or arrived during his actions is 1.
Sample Input 2
6 13 4 6 ############# #@@@@@@@@@@@# #@@@@@@@@@@@# #@@@@.@@@@@@# #@@@@@@@@@@@# ############# UURUURLRLUUDDURDURRR
Sample Output 2
3 11 11
Sample Input 3
12 35 7 10 ################################### #.................................# #..........@......................# #......@................@.........# #.............##............@.....# #...##........##....##............# #...##........##....##.......##...# #....##......##......##....##.....# #....##......##......##..##.......# #.....#######.........###.........# #.................................# ################################### LRURRRUUDDULUDUUDLRLRDRRLULRRUDLDRU
Sample Output 3
4 14 1
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 300 点
問題文
英大文字のみからなる文字列 S が与えられます。
S に対して、次の手順を行った後に得られる文字列を出力してください。
文字列が
WAを(連続する)部分文字列として含む限り、次の操作を繰り返す。
- 文字列中に登場する
WAのうち最も先頭のものをACに置換する。
なお、本問題の制約下で、この操作は高々有限回しか繰り返されないことが証明できます。
制約
- S は長さ 1 以上 3\times 10^5 以下の英大文字のみからなる文字列
入力
入力は以下の形式で標準入力から与えられる。
S
出力
S に対して、問題文中に記された手順を行った後に得られる文字列を出力せよ。
入力例 1
WACWA
出力例 1
ACCAC
最初、文字列は S=WACWA です。
この文字列には 1 文字目から 2 文字目、および、4 文字目から 5 文字目の 2 ヶ所に WA が部分文字列として含まれています。
1 回目の操作では、そのうち先頭のもの、すなわち 1 文字目から 2 文字目の部分を AC に置換し、文字列は ACCWA となります。
1 回目の操作後の文字列には 4 文字目から 5 文字目の 1 ヶ所にのみ WA が部分文字列として含まれているため、2 回目の操作ではこれを AC に置換し、文字列は ACCAC となります。
ACCAC は WA を部分文字列として含まないため、手順は終了します。よって、ACCAC を出力します。
入力例 2
WWA
出力例 2
ACC
最初、文字列は S=WWA です。
この文字列には 2 文字目から 3 文字目の 1 ヶ所にのみ WA が部分文字列として含まれているため、1 回目の操作ではこれを AC に置換し、文字列は WAC となります。
次に、1 回目の操作後の文字列は 1 文字目から 2 文字目の 1 ヶ所にのみ WA が部分文字列として含まれているため、2 回目の操作ではこれを AC に置換し、文字列は ACC となります。
ACC は WA を部分文字列として含まないため、手順は終了します。よって、ACC を出力します。
入力例 3
WWWWW
出力例 3
WWWWW
S には最初から WA が部分文字列として含まれてないため、操作は 1 回も行われず手順は終了します。よって、WWWWW を出力します。
Score : 300 points
Problem Statement
You are given a string S consisting of uppercase English letters.
Apply the following procedure to S, and then output the resulting string:
As long as the string contains
WAas a (contiguous) substring, repeat the following operation:
- Among all occurrences of
WAin the string, replace the leftmost one withAC.
It can be proved under the constraints of this problem that this operation is repeated at most a finite number of times.
Constraints
- S is a string of uppercase English letters with length between 1 and 3\times 10^5, inclusive.
Input
The input is given from Standard Input in the following format:
S
Output
Print the resulting string after performing the procedure described in the problem statement on S.
Sample Input 1
WACWA
Sample Output 1
ACCAC
Initially, the string is S= WACWA.
This string contains WA as a substring in two places: from the 1st to the 2nd character, and from the 4th to the 5th character.
In the first operation, we replace the leftmost occurrence (the substring from the 1st to the 2nd character) with AC, resulting in ACCWA.
After the first operation, the string contains WA as a substring in exactly one place: from the 4th to the 5th character.
In the second operation, we replace it with AC, resulting in ACCAC.
Since ACCAC does not contain WA as a substring, the procedure ends. Therefore, we output ACCAC.
Sample Input 2
WWA
Sample Output 2
ACC
Initially, the string is S= WWA.
This string contains WA as a substring in exactly one place: from the 2nd to the 3rd character.
In the first operation, we replace it with AC, resulting in WAC.
Then, after the first operation, the string contains WA in exactly one place: from the 1st to the 2nd character.
In the second operation, we replace it with AC, resulting in ACC.
Since ACC does not contain WA as a substring, the procedure ends. Therefore, we output ACC.
Sample Input 3
WWWWW
Sample Output 3
WWWWW
Since S does not contain WA as a substring from the start, no operations are performed and the procedure ends immediately. Therefore, we output WWWWW.