Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 100 点
問題文
末尾が er
または ist
であるような文字列 S が与えられます。
S の末尾が er
である場合は er
を、 ist
である場合は ist
を出力してください。
制約
- 2 \le |S| \le 20
- S は英小文字のみからなる。
- S の末尾は
er
またはist
である。
入力
入力は以下の形式で標準入力から与えられる。
S
出力
答えを出力せよ。
入力例 1
atcoder
出力例 1
er
S="atcoder
" の末尾は er
です。
入力例 2
tourist
出力例 2
ist
入力例 3
er
出力例 3
er
Score : 100 points
Problem Statement
You are given a string S ending with er
or ist
.
If S ends with er
, print er
; if it ends with ist
, print ist
.
Constraints
- 2 \le |S| \le 20
- S consists of lowercase English letters.
- S ends with
er
orist
.
Input
Input is given from Standard Input in the following format:
S
Output
Print the answer.
Sample Input 1
atcoder
Sample Output 1
er
S="atcoder
" ends with er
.
Sample Input 2
tourist
Sample Output 2
ist
Sample Input 3
er
Sample Output 3
er
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 100 点
問題文
野球少年の高橋君は今年とても良い子にしていたので、サンタさんはバットかグローブのうち値段が高い方を高橋君にプレゼントすることにしました。
バットの値段が B 円、グローブの値段が G 円 (B\neq G) のとき、サンタさんが高橋君にプレゼントするのはどちらですか?
制約
- B,G は 1 以上 1000 以下の相異なる整数
入力
入力は以下の形式で標準入力から与えられる。
B G
出力
サンタさんが高橋君にプレゼントするのがバットであるとき Bat
を、グローブであるとき Glove
を出力せよ。
入力例 1
300 100
出力例 1
Bat
バットの方がグローブより値段が高いので、サンタさんは高橋君にバットをプレゼントします。
入力例 2
334 343
出力例 2
Glove
グローブの方がバットより値段が高いので、サンタさんは高橋君にグローブをプレゼントします。
Score : 100 points
Problem Statement
Takahashi, a young baseball enthusiast, has been a very good boy this year, so Santa has decided to give him a bat or a glove, whichever is more expensive.
If a bat costs B yen and a glove costs G yen (B\neq G), which one will Santa give to Takahashi?
Constraints
- B and G are different integers between 1 and 1000, inclusive.
Input
The input is given from Standard Input in the following format:
B G
Output
If Santa gives Takahashi a bat, print Bat
; if Santa gives him a glove, print Glove
.
Sample Input 1
300 100
Sample Output 1
Bat
The bat is more expensive than the glove, so Santa will give Takahashi the bat.
Sample Input 2
334 343
Sample Output 2
Glove
The glove is more expensive than the bat, so Santa will give Takahashi the glove.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
英小文字からなる文字列 S, T が与えられます。S の長さは N、T の長さは M です。(N \leq M が制約で保証されています)
S が T の 接頭辞 であるとは、T のはじめ N 文字からなる文字列が S と一致することを言います。
S が T の 接尾辞 であるとは、T の後ろ N 文字からなる文字列が S と一致することを言います。
S が T の接頭辞であり、かつ接尾辞でもある場合は 0 を、
S が T の接頭辞であるが、接尾辞でない場合は 1 を、
S が T の接尾辞であるが、接頭辞でない場合は 2 を、
S が T の接頭辞でも接尾辞でもない場合は 3 を出力してください。
制約
- 1 \leq N \leq M \leq 100
- S は英小文字からなる長さ N の文字列
- T は英小文字からなる長さ M の文字列
入力
入力は以下の形式で標準入力から与えられる。
N M S T
出力
問題文の指示に従って答えを出力せよ。
入力例 1
3 7 abc abcdefg
出力例 1
1
S は T の接頭辞ですが接尾辞ではありません。よって 1 を出力します。
入力例 2
3 4 abc aabc
出力例 2
2
S は T の接尾辞ですが接頭辞ではありません。
入力例 3
3 3 abc xyz
出力例 3
3
S は T の接頭辞でも接尾辞でもありません。
入力例 4
3 3 aaa aaa
出力例 4
0
S と T が完全に一致する場合もあります。この場合、S は T の接頭辞であり、かつ接尾辞でもあります。
Score : 200 points
Problem Statement
You are given two strings S and T consisting of lowercase English letters. The lengths of S and T are N and M, respectively. (The constraints guarantee that N \leq M.)
S is said to be a prefix of T when the first N characters of T coincide S.
S is said to be a suffix of T when the last N characters of T coincide S.
If S is both a prefix and a suffix of T, print 0;
If S is a prefix of T but not a suffix, print 1;
If S is a suffix of T but not a prefix, print 2;
If S is neither a prefix nor a suffix of T, print 3.
Constraints
- 1 \leq N \leq M \leq 100
- S is a string of length N consisting of lowercase English letters.
- T is a string of length M consisting of lowercase English letters.
Input
The input is given from Standard Input in the following format:
N M S T
Output
Print the answer according to the instructions in the problem statement.
Sample Input 1
3 7 abc abcdefg
Sample Output 1
1
S is a prefix of T but not a suffix, so you should print 1.
Sample Input 2
3 4 abc aabc
Sample Output 2
2
S is a suffix of T but not a prefix.
Sample Input 3
3 3 abc xyz
Sample Output 3
3
S is neither a prefix nor a suffix of T.
Sample Input 4
3 3 aaa aaa
Sample Output 4
0
S and T may coincide, in which case S is both a prefix and a suffix of T.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
長さ N の整数列 A=(A_1,A_2,\ldots,A_N) 及び整数 L,R が与えられます。ここで L,R は L\leq R を満たします。
i=1,2,\ldots,N について以下の 2 つの条件を共に満たす整数 X_i を求めてください。なお、求める整数は常に一意に定まります。
- L\leq X_i \leq R
- L 以上 R 以下であるようなどの整数 Y についても |X_i - A_i| \leq |Y-A_i| を満たす
制約
- 1\leq N\leq 2\times 10^5
- 1\leq L\leq R \leq 10^9
- 1\leq A_i\leq 10^9
- 入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N L R A_1 \ldots A_N
出力
i=1,2,\ldots,N について X_i を空白区切りで出力せよ。
入力例 1
5 4 7 3 1 4 9 7
出力例 1
4 4 4 7 7
i=1 では、
- |4-3|=1
- |5-3|=2
- |6-3|=3
- |7-3|=4
より X_i = 4 です。
入力例 2
3 10 10 11 10 9
出力例 2
10 10 10
Score : 200 points
Problem Statement
You are given an integer sequence A=(A_1,A_2,\ldots,A_N) of length N and integers L and R such that L\leq R.
For each i=1,2,\ldots,N, find the integer X_i that satisfies both of the following conditions. Note that the integer to be found is always uniquely determined.
- L\leq X_i \leq R.
- For every integer Y such that L \leq Y \leq R, it holds that |X_i - A_i| \leq |Y - A_i|.
Constraints
- 1\leq N\leq 2\times 10^5
- 1\leq L\leq R \leq 10^9
- 1\leq A_i\leq 10^9
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N L R A_1 \ldots A_N
Output
Print X_i for i=1,2,\ldots,N, separated by spaces.
Sample Input 1
5 4 7 3 1 4 9 7
Sample Output 1
4 4 4 7 7
For i=1:
- |4-3|=1
- |5-3|=2
- |6-3|=3
- |7-3|=4
Thus, X_i = 4.
Sample Input 2
3 10 10 11 10 9
Sample Output 2
10 10 10
Time Limit: 3 sec / Memory Limit: 1024 MiB
配点 : 250 点
問題文
H 行 W 列のグリッドがあります。
グリッドの各マスは陸か海のどちらかであり、
その情報は H 個の長さ W の文字列 S_1, S_2, \ldots, S_H で与えられます。
上から i 行目、左から j 列目のマスを (i, j) で表すと、
S_i の j 文字目が .
のときマス (i, j) は陸であり、#
のときマス (i, j) は海です。
ここで、グリッドの外周のマス(すなわち、i = 1 、i = H 、j = 1 、j = W のうち少なくとも 1 個以上を満たすマス (i, j) )については、すべて海であることが制約として保証されます。
高橋君が乗った宇宙船が、グリッド上のあるマスに不時着してしまいました。
その後、高橋君は L
、R
、U
、D
のみからなる長さ N の文字列 T で表される手順に沿って、グリッド上を N 回移動しました。
i = 1, 2, \ldots, N について、T の i 文字目は i 回目の移動の内容を下記の通り表します。
L
のとき、左に 1 マス移動したことを表す。すなわち、移動前のマスを (i, j) とするとき、移動後のマスは (i, j-1) である。R
のとき、右に 1 マス移動したことを表す。すなわち、移動前のマスを (i, j) とするとき、移動後のマスは (i, j+1) である。U
のとき、上に 1 マス移動したことを表す。すなわち、移動前のマスを (i, j) とするとき、移動後のマスは (i-1, j) である。D
のとき、下に 1 マス移動したことを表す。すなわち、移動前のマスを (i, j) とするとき、移動後のマスは (i+1, j) である。
高橋君の移動経路上のマス(不時着したマスおよび現在いるマスを含む)はいずれも海でないことがわかっています。 高橋君が現在いるマスとしてあり得るものの個数を出力してください。
制約
- H, W, N は整数
- 3 \leq H, W \leq 500
- 1 \leq N \leq 500
- T は
L
、R
、U
、D
のみからなる長さ N の文字列 - S_i は
.
と#
のみからなる長さ W の文字列 - 高橋君が現在いるマスとしてあり得るものが少なくとも 1 個存在する。
- グリッドの外周のマスはすべて海である。
入力
入力は以下の形式で標準入力から与えられる。
H W N T S_1 S_2 \vdots S_H
出力
答えを出力せよ。
入力例 1
6 7 5 LULDR ####### #...#.# ##...## #.#...# #...#.# #######
出力例 1
2
下記の 2 つの場合がありえるため、高橋君が現在いるマスとしてあり得るものは (3, 4) と (4, 5) の 2 個です。
- マス (3, 5) に不時着し、(3, 5) \rightarrow (3, 4) \rightarrow (2, 4) \rightarrow (2, 3) \rightarrow (3, 3) \rightarrow (3, 4) と移動した場合
- マス (4, 6) に不時着し、(4, 6) \rightarrow (4, 5) \rightarrow (3, 5) \rightarrow (3, 4) \rightarrow (4, 4) \rightarrow (4, 5) と移動した場合
入力例 2
13 16 9 ULURDLURD ################ ##..##.#..####.# ###.#..#.....#.# #..##..#####.### #...#..#......## ###.##.#..#....# ##.#####....##.# ###.###.#.#.#..# ######.....##..# #...#.#.######.# ##..###..#..#.## #...#.#.#...#..# ################
出力例 2
6
Score: 250 points
Problem Statement
There is a grid with H rows and W columns.
Each cell of the grid is land or sea, which is represented by H strings S_1, S_2, \ldots, S_H of length W. Let (i, j) denote the cell at the i-th row from the top and j-th column from the left, and (i, j) is land if the j-th character of S_i is .
, and (i, j) is sea if the character is #
.
The constraints guarantee that all cells on the perimeter of the grid (that is, the cells (i, j) that satisfy at least one of i = 1, i = H, j = 1, j = W) are sea.
Takahashi's spaceship has crash-landed on a cell in the grid. Afterward, he moved N times on the grid following the instructions represented by a string T of length N consisting of L
, R
, U
, and D
. For i = 1, 2, \ldots, N, the i-th character of T describes the i-th move as follows:
L
indicates a move of one cell to the left. That is, if he is at (i, j) before the move, he will be at (i, j-1) after the move.R
indicates a move of one cell to the right. That is, if he is at (i, j) before the move, he will be at (i, j+1) after the move.U
indicates a move of one cell up. That is, if he is at (i, j) before the move, he will be at (i-1, j) after the move.D
indicates a move of one cell down. That is, if he is at (i, j) before the move, he will be at (i+1, j) after the move.
It is known that all cells along his path (including the cell where he crash-landed and the cell he is currently on) are not sea. Print the number of cells that could be his current position.
Constraints
- H, W, and N are integers.
- 3 \leq H, W \leq 500
- 1 \leq N \leq 500
- T is a string of length N consisting of
L
,R
,U
, andD
. - S_i is a string of length W consisting of
.
and#
. - There is at least one cell that could be Takahashi's current position.
- All cells on the perimeter of the grid are sea.
Input
The input is given from Standard Input in the following format:
H W N T S_1 S_2 \vdots S_H
Output
Print the answer.
Sample Input 1
6 7 5 LULDR ####### #...#.# ##...## #.#...# #...#.# #######
Sample Output 1
2
The following two cases are possible, so there are two cells that could be Takahashi's current position: (3, 4) and (4, 5).
- He crash-landed on cell (3, 5) and moved (3, 5) \rightarrow (3, 4) \rightarrow (2, 4) \rightarrow (2, 3) \rightarrow (3, 3) \rightarrow (3, 4).
- He crash-landed on cell (4, 6) and moved (4, 6) \rightarrow (4, 5) \rightarrow (3, 5) \rightarrow (3, 4) \rightarrow (4, 4) \rightarrow (4, 5).
Sample Input 2
13 16 9 ULURDLURD ################ ##..##.#..####.# ###.#..#.....#.# #..##..#####.### #...#..#......## ###.##.#..#....# ##.#####....##.# ###.###.#.#.#..# ######.....##..# #...#.#.######.# ##..###..#..#.## #...#.#.#...#..# ################
Sample Output 2
6