Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 100 点
問題文
キーエンスでは、役割や年齢、立場の違いに関係なく「さん」付けして呼ぶという文化があります。 新入社員が社長を呼ぶときも「中田さん」と呼びます。
ある人の苗字と名前がそれぞれ文字列 S,T として与えられます。
苗字、スペース( )、敬称(san)をこの順に連結した文字列を出力してください。
制約
- S,T は以下の各条件を満たす文字列
- 長さ 1 以上 10 以下
- 先頭の文字は英大文字
- 先頭以外の文字は英小文字
入力
入力は以下の形式で標準入力から与えられる。
S T
出力
苗字、スペース( )、敬称(san)をこの順に連結した文字列を出力せよ。
入力例 1
Takahashi Chokudai
出力例 1
Takahashi san
苗字(Takahashi)、スペース( )、敬称(san)をこの順に連結した文字列を出力します。
入力例 2
K Eyence
出力例 2
K san
Score : 100 points
Problem Statement
Keyence has a culture of addressing everyone with the honorific "san," regardless of their role, age, or position. Even a new employee would call the president "Nakata-san." [Translator's note: this is a bit unusual in Japan.]
You are given a person's surname and first name as strings S and T, respectively.
Print the concatenation of the surname, a space ( ), and the honorific (san) in this order.
Constraints
- Each of S and T is a string that satisfies the following conditions.
- The length is between 1 and 10, inclusive.
- The first character is an uppercase English letter.
- All characters except the first one are lowercase English letters.
Input
The input is given from Standard Input in the following format:
S T
Output
Print the concatenation of the surname, a space ( ), and the honorific (san) in this order.
Sample Input 1
Takahashi Chokudai
Sample Output 1
Takahashi san
Print the concatenation of the surname (Takahashi), a space ( ), and the honorific (san) in this order.
Sample Input 2
K Eyence
Sample Output 2
K san
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 100 点
問題文
以下の 5 つの日を五節句と呼びます。
- 1 月 \color{red}{\mathbf{7}} 日
- 3 月 3 日
- 5 月 5 日
- 7 月 7 日
- 9 月 9 日
M 月 D 日が五節句に含まれるならば Yes を、含まれないならば No を出力してください。
制約
- M, D は整数
- M 月 D 日はグレゴリオ暦における閏年の日付として正しい。
入力
入力は以下の形式で標準入力から与えられる。
M D
出力
M 月 D 日が五節句に含まれるならば Yes を、含まれないならば No を出力せよ。
入力例 1
3 3
出力例 1
Yes
3 月 3 日は五節句に含まれるので、Yes を出力します。
入力例 2
1 1
出力例 2
No
1 月 1 日は五節句に含まれないので、No を出力します。
入力例 3
4 4
出力例 3
No
入力例 4
11 7
出力例 4
No
Score : 100 points
Problem Statement
The following five days are called the five seasonal festivals (gosekku).
- January \color{red}{\mathbf{7}}
- March 3
- May 5
- July 7
- September 9
If month M, day D is one of the five seasonal festivals, output Yes; otherwise, output No.
Constraints
- M and D are integers.
- Month M, day D is a valid date in a leap year in the Gregorian calendar.
Input
The input is given from Standard Input in the following format:
M D
Output
If month M, day D is one of the five seasonal festivals, output Yes; otherwise, output No.
Sample Input 1
3 3
Sample Output 1
Yes
March 3 is one of the five seasonal festivals, so output Yes.
Sample Input 2
1 1
Sample Output 2
No
January 1 is not one of the five seasonal festivals, so output No.
Sample Input 3
4 4
Sample Output 3
No
Sample Input 4
11 7
Sample Output 4
No
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 150 点
問題文
1 から N までの番号がつけられた N 個の国があり、i = 1, 2, \ldots, N について、高橋君は国 i の通貨を A_i 単位持っています。
高橋君は、下記の操作を好きな回数( 0 回でも良い)繰り返します。
- まず、1 以上 N-1 以下の整数 i を選ぶ。
- その後、国 i の通貨を S_i 単位以上持っているなら、下記の行動を 1 回行う。
- 国 i の通貨を S_i 単位だけ支払い、国 (i+1) の通貨を T_i 単位だけ獲得する。
最終的に高橋君が持っている国 N の通貨の単位数としてあり得る最大値を出力してください。
制約
- 入力される値はすべて整数
- 2 \leq N \leq 2 \times 10^5
- 0 \leq A_i \leq 10^9
- 1 \leq T_i \leq S_i \leq 10^9
入力
入力は以下の形式で標準入力から与えられる。
N
A_1 A_2 \ldots A_N
S_1 T_1
S_2 T_2
\vdots
S_{N-1} T_{N-1}
出力
答えを出力せよ。
入力例 1
4 5 7 0 3 2 2 4 3 5 2
出力例 1
5
以下の説明では、高橋君が持っている各国の通貨の単位数を、数列 A = (A_1, A_2, A_3, A_4) として表します。はじめ、A = (5, 7, 0, 3) です。
下記の通りに 4 回操作を行うことを考えます。
- i = 2 を選び、国 2 の通貨 4 単位を支払って、国 3 の通貨 3 単位を獲得する。その結果、A = (5, 3, 3, 3) となる。
- i = 1 を選び、国 1 の通貨 2 単位を支払って、国 2 の通貨 2 単位を獲得する。その結果、A = (3, 5, 3, 3) となる。
- i = 2 を選び、国 2 の通貨 4 単位を支払って、国 3 の通貨 3 単位を獲得する。その結果、A = (3, 1, 6, 3) となる。
- i = 3 を選び、国 3 の通貨 5 単位を支払って、国 4 の通貨 2 単位を獲得する。その結果、A = (3, 1, 1, 5) となる。
このとき、最終的に高橋君が持っている国 4 の通貨の単位数は 5 であり、これが考えられる最大値です。
入力例 2
10 32 6 46 9 37 8 33 14 31 5 5 5 3 1 4 3 2 2 3 2 3 2 4 4 3 3 3 1
出力例 2
45
Score: 150 points
Problem Statement
There are N countries numbered 1 to N. For each i = 1, 2, \ldots, N, Takahashi has A_i units of the currency of country i.
Takahashi can repeat the following operation any number of times, possibly zero:
- First, choose an integer i between 1 and N-1, inclusive.
- Then, if Takahashi has at least S_i units of the currency of country i, he performs the following action once:
- Pay S_i units of the currency of country i and gain T_i units of the currency of country (i+1).
Print the maximum possible number of units of the currency of country N that Takahashi could have in the end.
Constraints
- All input values are integers.
- 2 \leq N \leq 2 \times 10^5
- 0 \leq A_i \leq 10^9
- 1 \leq T_i \leq S_i \leq 10^9
Input
The input is given from Standard Input in the following format:
N
A_1 A_2 \ldots A_N
S_1 T_1
S_2 T_2
\vdots
S_{N-1} T_{N-1}
Output
Print the answer.
Sample Input 1
4 5 7 0 3 2 2 4 3 5 2
Sample Output 1
5
In the following explanation, let the sequence A = (A_1, A_2, A_3, A_4) represent the numbers of units of the currencies of the countries Takahashi has. Initially, A = (5, 7, 0, 3).
Consider performing the operation four times as follows:
- Choose i = 2, pay four units of the currency of country 2, and gain three units of the currency of country 3. Now, A = (5, 3, 3, 3).
- Choose i = 1, pay two units of the currency of country 1, and gain two units of the currency of country 2. Now, A = (3, 5, 3, 3).
- Choose i = 2, pay four units of the currency of country 2, and gain three units of the currency of country 3. Now, A = (3, 1, 6, 3).
- Choose i = 3, pay five units of the currency of country 3, and gain two units of the currency of country 4. Now, A = (3, 1, 1, 5).
At this point, Takahashi has five units of the currency of country 4, which is the maximum possible number.
Sample Input 2
10 32 6 46 9 37 8 33 14 31 5 5 5 3 1 4 3 2 2 3 2 3 2 4 4 3 3 3 1
Sample Output 2
45
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
A 問題と似た設定の問題です。A 問題とは、高橋君が食べるクッキーの選び方および求めるものが異なります。
N 個の箱が横一列に並んでおり、そのうちのいくつかの箱にはクッキーが入っています。
各箱の状態は長さ N の文字列 S によって表されます。
具体的には、左から i\ (1\leq i\leq N) 番目の箱は、S の i 文字目が @ のときクッキーが 1 枚入っており、. のとき空き箱です。
高橋君は今からの D 日間、一日一回ずつ、その時点でクッキーが入っている箱のうち最も右にある箱のクッキーを選んで食べます。
N 個の箱それぞれについて、D 日間が経過した後にその箱にクッキーが入っているかを求めてください。
なお、S には @ が D 個以上含まれることが保証されます。
制約
- 1\leq D \leq N \leq 100
- N,D は整数
- S は
@と.からなる長さ N の文字列 - S には
@が D 個以上含まれる
入力
入力は以下の形式で標準入力から与えられる。
N D S
出力
長さ N の文字列を出力せよ。
出力する文字列の i\ (1\leq i\leq N) 文字目は、D 日間が経過した後に左から i 番目の箱にクッキーが入っているならば @、入っていないならば . とせよ。
入力例 1
5 2 .@@.@
出力例 1
.@...
高橋君は以下のように行動します。
- 1 日目:左から 2,3,5 番目の箱にクッキーが入っている。このうちで最も右にある、左から 5 番目の箱に入っているクッキーを選んで食べる。
- 2 日目:左から 2,3 番目の箱にクッキーが入っている。このうちで最も右にある、左から 3 番目の箱に入っているクッキーを選んで食べる。
- 2 日間が経過した後、左から 2 番目の箱にのみクッキーが入っている。
よって、正しい出力は .@... です。
入力例 2
3 3 @@@
出力例 2
...
入力例 3
10 4 @@@.@@.@@.
出力例 3
@@@.......
Score: 200 points
Problem Statement
This problem shares a similar setting with Problem A. The way Takahashi chooses cookies and what you are required to find are different from Problem A.
There are N boxes arranged in a row, and some of these boxes contain cookies.
The state of these boxes is represented by a string S of length N.
Specifically, the i-th box (1\leq i \leq N) from the left contains one cookie if the i-th character of S is @, and is empty if it is ..
Over the next D days, Takahashi will choose and eat one cookie per day from among the cookies in these boxes. On each day, he chooses the cookie in the rightmost box that contains a cookie at that point.
Determine, for each of the N boxes, whether it will contain a cookie after D days have passed.
It is guaranteed that S contains at least D occurrences of @.
Constraints
- 1 \leq D \leq N \leq 100
- N and D are integers.
- S is a string of length N consisting of
@and.. - S contains at least D occurrences of
@.
Input
The input is given from Standard Input in the following format:
N D S
Output
Print a string of length N.
The i-th character (1 \leq i \leq N) of the string should be @ if the i-th box from the left contains a cookie after D days have passed, and . otherwise.
Sample Input 1
5 2 .@@.@
Sample Output 1
.@...
Takahashi acts as follows:
- Day 1: There are cookies in the 2nd, 3rd, and 5th boxes from the left. Among these, the rightmost is the 5th box. He eats the cookie in this box.
- Day 2: There are cookies in the 2nd and 3rd boxes. Among these, the rightmost is the 3rd box. He eats the cookie in this box.
- After two days have passed, only the 2nd box from the left contains a cookie.
Therefore, the correct output is .@....
Sample Input 2
3 3 @@@
Sample Output 2
...
Sample Input 3
10 4 @@@.@@.@@.
Sample Output 3
@@@.......
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
縦 H 行、横 W 列のグリッドがあります。
上から i 行目左から j 列目のマスは S_{i,j} が # のとき黒く、 . のとき白く塗られています。
白マスからなる四方位に連結な領域のうち、黒マスに囲まれたものの個数を求めてください。
より厳密には次の通りです。
上から i 行目左から j 列目のマスをマス (i,j) と表します。
2 つのマス (i,j),(i',j') が隣接しているとは、|i-i'|+|j-j'|=1 であることと定めます。
白マスの集合 C が連結であるとは、C に属するどの 2 マス c,c' に対しても、C に属する隣接するマスへの移動を繰り返すことで c から c' へ移動できることと定めます。
空でない白マスの連結な集合であって、極大なものを白マスの連結成分と定めます。
白マスの連結成分であって、グリッドの最外周(すなわち、 1 行目、 H 行目、 1 列目、 W 行目)のマスを含まないものの個数を求めてください。
制約
- 3 \leq H,W \leq 10^3
- H,W は整数
- S_{i,j} は
#か.
入力
入力は以下の形式で標準入力から与えられる。
H W
S_{1,1}S_{1,2}\dots S_{1,W}
\vdots
S_{H,1}S_{H,2}\dots S_{H,W}
出力
答えを出力せよ。
入力例 1
5 15 ##########..### #...#######.### ####....###..## ######.######## ########....###
出力例 1
2
上から 2 行目左から 2,3,4 列目の 3 マスからなる領域と、上から 3 行目左から 5,6,7,8 列目及び上から 4 行目左から 7 列目の計 5 マスからなる領域の 2 個です。
入力例 2
10 22 ###################### ####.################# ###...################ ##.###.##.....######## ##.....##.####.####### .######.#......#.....# .######.#.####.#.##### #########.....##.##### ################.##### ################.....#
出力例 2
4
Score : 300 points
Problem Statement
There is a grid with H rows and W columns.
The cell at the i-th row from the top and j-th column from the left is painted black if S_{i,j} is #, and white if S_{i,j} is ..
Among the four-directionally connected regions consisting of white cells, find the number of those that are surrounded by black cells.
Below is a more formal statement.
We denote the cell at the i-th row from the top and j-th column from the left as cell (i, j).
Two cells (i, j) and (i', j') are said to be adjacent if and only if |i-i'|+|j-j'|=1.
A set C of white cells is said to be connected if and only if, for any two cells c and c' in C, it is possible to move from c to c' by repeatedly moving to an adjacent cell in C.
A non-empty connected set of white cells that is maximal is called a connected component of white cells.
Find the number of connected components of white cells that do not contain any cell on the outermost border of the grid (that is, in row 1, row H, column 1, or column W).
Constraints
- 3 \leq H, W \leq 10^3
- H and W are integers.
- S_{i,j} is
#or..
Input
The input is given from Standard Input in the following format:
H W
S_{1,1}S_{1,2}\dots S_{1,W}
\vdots
S_{H,1}S_{H,2}\dots S_{H,W}
Output
Output the answer.
Sample Input 1
5 15 ##########..### #...#######.### ####....###..## ######.######## ########....###
Sample Output 1
2
There are two such regions: the region consisting of the three cells in row 2 from the top and columns 2, 3, 4 from the left, and the region consisting of a total of five cells: columns 5, 6, 7, 8 from the left in row 3 from the top and column 7 from the left in row 4 from the top.
Sample Input 2
10 22 ###################### ####.################# ###...################ ##.###.##.....######## ##.....##.####.####### .######.#......#.....# .######.#.####.#.##### #########.....##.##### ################.##### ################.....#
Sample Output 2
4