Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 100 点
問題文
高橋君は AtCoder Land を目指しています。 目の前に看板が置かれているので、ここが AtCoder Land であるかどうか判定したいです。
文字列 S,T が空白区切りで与えられます。
S= AtCoder
かつ T= Land
であるかどうか判定してください。
制約
- S,T は英大小文字からなる長さ 1 以上 10 以下の文字列
入力
入力は以下の形式で標準入力から与えられる。
S T
出力
S= AtCoder
かつ T= Land
であるならば Yes
を、そうでないならば No
を出力せよ。
入力例 1
AtCoder Land
出力例 1
Yes
S= AtCoder
かつ T= Land
です。
入力例 2
CodeQUEEN Land
出力例 2
No
S= AtCoder
ではありません。
入力例 3
aTcodeR lANd
出力例 3
No
大文字と小文字は区別します。
Score : 100 points
Problem Statement
Takahashi is heading to AtCoder Land. There is a signboard in front of him, and he wants to determine whether it says AtCoder Land.
You are given two strings S and T separated by a space.
Determine whether S= AtCoder
and T= Land
.
Constraints
- S and T are strings consisting of uppercase and lowercase English letters, with lengths between 1 and 10, inclusive.
Input
The input is given from Standard Input in the following format:
S T
Output
If S= AtCoder
and T= Land
, print Yes
; otherwise, print No
.
Sample Input 1
AtCoder Land
Sample Output 1
Yes
S= AtCoder
and T= Land
.
Sample Input 2
CodeQUEEN Land
Sample Output 2
No
S is not AtCoder
.
Sample Input 3
aTcodeR lANd
Sample Output 3
No
Uppercase and lowercase letters are distinguished.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
AtCoder Land の入り口には 1 つのチケット売り場があり、来園客はこのチケット売り場の前に一列に並んで順にチケットを購入します。 チケットの購入手続きには一人当たり A 秒かかり、列の先頭の人がチケットを購入し終わると、(存在すれば)次の人がすぐさま購入手続きを開始します。
現在チケット売り場に並んでいる人はおらず、今から N 人の人が順にチケットを買いに来ます。 具体的には、i 番目の人は今から T_i 秒後にチケット売り場を訪れ、既に列が存在すればその最後尾に並び、存在しなければすぐさま購入手続きを開始します。 ここで、T_1< T_2< \dots < T_N です。
各 i\ (1\leq i\leq N) について、i 番目の人がチケットを購入し終わるのは今から何秒後か求めてください。
制約
- 1\leq N \leq 100
- 0\leq T_1< T_2< \dots < T_N\leq 10^6
- 1\leq A\leq 10^6
- 入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N A T_1 T_2 \dots T_N
出力
N 行出力せよ。 i\ (1\leq i \leq N) 行目には、i 番目の人がチケットを購入し終わるのは今から何秒後かを整数として出力せよ。
入力例 1
3 4 0 2 10
出力例 1
4 8 14
時系列順に以下のように物事が進行します。
- 0 秒後:1 番目の人がチケット売り場を訪れ、チケットの購入手続きを開始する。
- 2 秒後:2 番目の人がチケット売り場を訪れ、1 番目の人の後ろに並ぶ。
- 4 秒後:1 番目の人がチケットを購入し終え、2 番目の人が購入手続きを開始する。
- 8 秒後:2 番目の人がチケットを購入し終える。
- 10 秒後:3 番目の人がチケット売り場を訪れ、チケットの購入手続きを開始する。
- 14 秒後:3 番目の人がチケットを購入し終える。
入力例 2
3 3 1 4 7
出力例 2
4 7 10
時系列順に以下のように物事が進行します。
- 1 秒後:1 番目の人がチケット売り場を訪れ、チケットの購入手続きを開始する。
- 4 秒後:1 番目の人がチケットを購入し終えると同時に、2 番目の人がチケット売り場を訪れ、チケットの購入手続きを開始する。
- 7 秒後:2 番目の人がチケットを購入し終えると同時に、3 番目の人がチケット売り場を訪れ、チケットの購入手続きを開始する。
- 10 秒後:3 番目の人がチケットを購入し終える。
入力例 3
10 50000 120190 165111 196897 456895 540000 552614 561627 743796 757613 991216
出力例 3
170190 220190 270190 506895 590000 640000 690000 793796 843796 1041216
Score : 200 points
Problem Statement
At the entrance of AtCoder Land, there is a single ticket booth where visitors line up to purchase tickets one by one. The purchasing process takes A seconds per person. Once the person at the front of the line finishes purchasing their ticket, the next person (if any) immediately starts their purchasing process.
Currently, there is no one in line at the ticket booth, and N people will come to buy tickets one after another. Specifically, the i-th person will arrive at the ticket booth T_i seconds from now. If there is already a line, they will join the end of it; if not, they will start the purchasing process immediately. Here, T_1 < T_2 < \dots < T_N.
For each i\ (1 \leq i \leq N), determine how many seconds from now the i-th person will finish purchasing their ticket.
Constraints
- 1 \leq N \leq 100
- 0 \leq T_1 < T_2 < \dots < T_N \leq 10^6
- 1 \leq A \leq 10^6
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N A T_1 T_2 \dots T_N
Output
Print N lines. The i-th line should contain the number of seconds from now that the i-th person will finish purchasing their ticket.
Sample Input 1
3 4 0 2 10
Sample Output 1
4 8 14
The events proceed in the following order:
- At 0 seconds: The 1st person arrives at the ticket booth and starts the purchasing process.
- At 2 seconds: The 2nd person arrives at the ticket booth and joins the line behind the 1st person.
- At 4 seconds: The 1st person finishes purchasing their ticket, and the 2nd person starts the purchasing process.
- At 8 seconds: The 2nd person finishes purchasing their ticket.
- At 10 seconds: The 3rd person arrives at the ticket booth and starts the purchasing process.
- At 14 seconds: The 3rd person finishes purchasing their ticket.
Sample Input 2
3 3 1 4 7
Sample Output 2
4 7 10
The events proceed in the following order:
- At 1 second: The 1st person arrives at the ticket booth and starts the purchasing process.
- At 4 seconds: The 1st person finishes purchasing their ticket, and the 2nd person arrives at the ticket booth and starts the purchasing process.
- At 7 seconds: The 2nd person finishes purchasing their ticket, and the 3rd person arrives at the ticket booth and starts the purchasing process.
- At 10 seconds: The 3rd person finishes purchasing their ticket.
Sample Input 3
10 50000 120190 165111 196897 456895 540000 552614 561627 743796 757613 991216
Sample Output 3
170190 220190 270190 506895 590000 640000 690000 793796 843796 1041216
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
AtCoder Land には 1 から N までの番号が付けられた N 個のポップコーン売り場があります。 売られているポップコーンの味には味 1,2,\dots,M の M 種類がありますが、すべての売り場ですべての味のポップコーンを売っているわけではありません。
高橋君は、それぞれのポップコーン売り場でどの味のポップコーンを売っているかの情報を入手しました。
この情報は N 個の長さ M の文字列 S_1,S_2,\dots,S_N によって表され、S_i の j 文字目が o
であるとき売り場 i が味 j のポップコーンを売っていることを、
x
であるとき売っていないことを示します。
どの売り場も最低 1 種類の味のポップコーンを売っており、どの味のポップコーンも最低 1 つの売り場で売られています。
高橋君は全種類のポップコーンを食べたがっていますが、あまり何度も移動はしたくありません。 高橋君がすべての味のポップコーンを購入するためには最低何個の売り場を訪れる必要があるか求めてください。
制約
- N,M は整数
- 1\leq N,M \leq 10
- S_i は
o
およびx
からなる長さ M の文字列 - すべての i\ (1\leq i\leq N) について、S_i の中には
o
が 1 つ以上存在する - すべての j\ (1\leq j\leq M) について、S_i の j 文字目が
o
であるような i が 1 つ以上存在する
入力
入力は以下の形式で標準入力から与えられる。
N M S_1 S_2 \vdots S_N
出力
高橋君がすべての味のポップコーンを購入するために訪れる必要がある売り場の個数の最小値を出力せよ。
入力例 1
3 5 oooxx xooox xxooo
出力例 1
2
1 つめの売り場と 3 つめの売り場を訪れることで、すべての味のポップコーンを購入することができます。 1 つの売り場ですべての味のポップコーンを購入することはできないので、答えは 2 です。
入力例 2
3 2 oo ox xo
出力例 2
1
入力例 3
8 6 xxoxxo xxoxxx xoxxxx xxxoxx xxoooo xxxxox xoxxox oxoxxo
出力例 3
3
Score : 300 points
Problem Statement
In AtCoder Land, there are N popcorn stands numbered 1 to N. They have M different flavors of popcorn, labeled 1, 2, \dots, M, but not every stand sells all flavors of popcorn.
Takahashi has obtained information about which flavors of popcorn are sold at each stand. This information is represented by N strings S_1, S_2, \dots, S_N of length M. If the j-th character of S_i is o
, it means that stand i sells flavor j of popcorn. If it is x
, it means that stand i does not sell flavor j. Each stand sells at least one flavor of popcorn, and each flavor of popcorn is sold at least at one stand.
Takahashi wants to try all the flavors of popcorn but does not want to move around too much. Determine the minimum number of stands Takahashi needs to visit to buy all the flavors of popcorn.
Constraints
- N and M are integers.
- 1 \leq N, M \leq 10
- Each S_i is a string of length M consisting of
o
andx
. - For every i (1 \leq i \leq N), there is at least one
o
in S_i. - For every j (1 \leq j \leq M), there is at least one i such that the j-th character of S_i is
o
.
Input
The input is given from Standard Input in the following format:
N M S_1 S_2 \vdots S_N
Output
Print the minimum number of stands Takahashi needs to visit to buy all the flavors of popcorn.
Sample Input 1
3 5 oooxx xooox xxooo
Sample Output 1
2
By visiting the 1st and 3rd stands, you can buy all the flavors of popcorn. It is impossible to buy all the flavors from a single stand, so the answer is 2.
Sample Input 2
3 2 oo ox xo
Sample Output 2
1
Sample Input 3
8 6 xxoxxo xxoxxx xoxxxx xxxoxx xxoooo xxxxox xoxxox oxoxxo
Sample Output 3
3
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 350 点
問題文
AtCoder Land のお土産屋に N 個の箱が売られています。
箱には 1, 2, \ldots, N の番号が付いており、箱 i の価格は A_i 円であり、A_i 個のお菓子が入っています。
高橋君は N 個の箱のうち M 個の箱を選んで買って帰り、1, 2, \ldots, M の名前が付いた M 人の人に 1 つずつ箱を渡そうとしています。
ただし、高橋君は以下の条件を満たすことができるように箱を買いたいです。
- 各 i = 1, 2, \ldots, M について、人 i には B_i 個以上のお菓子が入った箱を渡す
1 人に 2 個以上の箱を渡すことや同じ箱を複数人に渡すことはできないことに注意してください。
適切に箱を M 個買うことで条件を満たすことができるか判定し、条件を満たすことができる場合は高橋君が支払う金額の合計の最小値を求めてください。
制約
- 1 \leq M \leq N \leq 2 \times 10^5
- 1 \leq A_i, B_i \leq 10^9
- 入力される値はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N M A_1 A_2 \ldots A_N B_1 B_2 \ldots B_M
出力
適切に箱を M 個買うことで条件を満たすことができる場合は高橋君が支払う金額の合計の最小値を出力せよ。そうでない場合は -1 を出力せよ。
入力例 1
4 2 3 4 5 4 1 4
出力例 1
7
高橋君は箱 1, 4 を買い、箱 1 を人 1、箱 4 を人 2 に渡すことで条件を満たすことができます。
このとき高橋君が支払う金額の合計は 7 円であり、支払う金額が 7 円未満のときは条件を満たすことはできないため、7 を出力します。
入力例 2
3 3 1 1 1 1000000000 1000000000 1000000000
出力例 2
-1
入力例 3
7 3 2 6 8 9 5 1 11 3 5 7
出力例 3
19
Score : 350 points
Problem Statement
A souvenir shop at AtCoder Land sells N boxes.
The boxes are numbered 1 to N, and box i has a price of A_i yen and contains A_i pieces of candy.
Takahashi wants to buy M out of the N boxes and give one box each to M people named 1, 2, \ldots, M.
Here, he wants to buy boxes that can satisfy the following condition:
- For each i = 1, 2, \ldots, M, person i is given a box containing at least B_i pieces of candy.
Note that it is not allowed to give more than one box to a single person or to give the same box to multiple people.
Determine whether it is possible to buy M boxes that can satisfy the condition, and if it is possible, find the minimum total amount of money Takahashi needs to pay.
Constraints
- 1 \leq M \leq N \leq 2 \times 10^5
- 1 \leq A_i, B_i \leq 10^9
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N M A_1 A_2 \ldots A_N B_1 B_2 \ldots B_M
Output
If it is possible to buy M boxes that can satisfy the condition, print the minimum total amount of money Takahashi needs to pay. Otherwise, print -1.
Sample Input 1
4 2 3 4 5 4 1 4
Sample Output 1
7
Takahashi can buy boxes 1 and 4, and give box 1 to person 1 and box 4 to person 2 to satisfy the condition.
In this case, he needs to pay 7 yen in total, and it is impossible to satisfy the condition by paying less than 7 yen, so print 7.
Sample Input 2
3 3 1 1 1 1000000000 1000000000 1000000000
Sample Output 2
-1
Sample Input 3
7 3 2 6 8 9 5 1 11 3 5 7
Sample Output 3
19
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 475 点
問題文
AtCoder Land では、アルファベットの書かれたタイルが販売されています。高橋君は、タイルを一列に並べてネームプレートを作ろうと考えました。
長さ 1 以上 K 以下の英大文字からなる文字列であって、以下の条件を満たすものの個数を 998244353 で割った余りを求めてください。
- 1 \leq i \leq 26 を満たす任意の整数 i について以下が成立する。
- 辞書順で i 番目の英大文字を a_i とおく。例えば、a_1 =
A
, a_5 =E
, a_{26} =Z
である。 - 文字列の中に含まれている a_i の個数は 0 個以上 C_i 個以下である。
- 辞書順で i 番目の英大文字を a_i とおく。例えば、a_1 =
制約
- 1 \leq K \leq 1000
- 0 \leq C_i \leq 1000
- 入力される値はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
K C_1 C_2 \ldots C_{26}
出力
答えを出力せよ。
入力例 1
2 2 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
出力例 1
10
A
, B
, C
, AA
, AB
, AC
, BA
, BC
, CA
, CB
の 10 個の文字列が条件を満たします。
入力例 2
358 1 0 1 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
出力例 2
64
入力例 3
1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000
出力例 3
270274035
Score : 475 points
Problem Statement
AtCoder Land sells tiles with English letters written on them. Takahashi is thinking of making a nameplate by arranging these tiles in a row.
Find the number, modulo 998244353, of strings consisting of uppercase English letters with a length between 1 and K, inclusive, that satisfy the following conditions:
- For every integer i satisfying 1 \leq i \leq 26, the following holds:
- Let a_i be the i-th uppercase English letter in lexicographical order. For example, a_1 =
A
, a_5 =E
, a_{26} =Z
. - The number of occurrences of a_i in the string is between 0 and C_i, inclusive.
- Let a_i be the i-th uppercase English letter in lexicographical order. For example, a_1 =
Constraints
- 1 \leq K \leq 1000
- 0 \leq C_i \leq 1000
- All input values are integers.
Input
The input is given from Standard Input in the following format:
K C_1 C_2 \ldots C_{26}
Output
Print the answer.
Sample Input 1
2 2 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Sample Output 1
10
The 10 strings that satisfy the conditions are A
, B
, C
, AA
, AB
, AC
, BA
, BC
, CA
, CB
.
Sample Input 2
358 1 0 1 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Sample Output 2
64
Sample Input 3
1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000
Sample Output 3
270274035
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 525 点
問題文
すぬけくんは、AtCoder Land の新たな目玉アトラクションとして迷路を建設しようと考えています。 迷路は縦 N 行・横 M 列のグリッドとして表され、右上のマスの上端が入口、右下のマスの下端が出口です。 すぬけくんは、隣接するマスの間に適切に壁を配置することで迷路を作ります。
すぬけくんは簡単な迷路が大好きなので、入口から出口までの道順は枝分かれを一切持たずにちょうど K マスを通るようなものにしたいです。 そのような迷路を作ることが可能か判定し、可能ならば 1 つ構築してください。
例えば以下の図では、N=3,M=3 であり、実線で書かれているところに壁が配置されています(入口と出口を除く外周部には必ず壁が配置されるものとします)。 このとき、入口から出口までの道順は枝分かれを一切持たずにちょうど 7 マスを通っています。
厳密には以下の通りです。
縦 N 行・横 M 列のグリッドがあります。 上から i 行目、左から j 列目のマスを (i,j) と表記します。 あなたは、辺で隣接する任意の 2 マスの間それぞれについて壁を置くか置かないか決めることができます。 壁を置く場所をうまく定めることで以下の条件を満たすことができるか判定し、できるならば実際に 1 つ構築してください。
NM 頂点からなる無向グラフ G を考える。G の各頂点は 2 つの整数の組 (i,j)\ (1\leq i\leq N, 1\leq j\leq M) によって互いに相異なるラベルが付けられている。 相異なる 2 頂点 (i_1,j_1),(i_2,j_2) は、|i_1-i_2|+|j_1-j_2|=1 かつグリッド上の 2 マス (i_1,j_1),(i_2,j_2) の間に壁が置かれていない場合、またその場合に限り辺で結ばれている。
条件:K 頂点からなり 2 頂点 (1,M),(N,M) を結ぶような単純パスが存在し、また 2 頂点 (1,M),(N,M) を含む連結成分はこのパスのみからなる。
制約
- 2\leq N \leq 100
- 1\leq M \leq 100
- 1\leq K\leq NM
- 入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N M K
出力
条件を満たす壁の配置が存在しないならば No
を出力し、存在するならばそのうちの 1 つを以下の形式で出力せよ。
条件を満たす壁の配置が複数存在する場合は、そのどれを出力してもよい。
複雑な出力形式のため、下記の出力例も参考にしてください。
Yes +++++ \dots +++S+ +o?o? \dots ?o?o+ +?+?+ \dots +?+?+ +o?o? \dots ?o?o+ +?+?+ \dots +?+?+ \vdots +o?o? \dots ?o?o+ +?+?+ \dots +?+?+ +o?o? \dots ?o?o+ +++++ \dots +++G+
ここで、S
, G
, +
, o
はそれぞれ入口、出口、壁、マスを表し、マスとマスの間にある ?
は壁を置くことができる場所である。
横に隣接する 2 マスの間にある ?
は、壁を置くならば |
で、壁を置かないならば .
で置き換えよ。
縦に隣接する 2 マスの間にある ?
は、壁を置くならば -
で、壁を置かないならば .
で置き換えよ。
厳密には以下の通りである。
- 出力は 2N+2 行からなり、1 行目には文字列
Yes
を、2 行目から 2N+2 行目には以下で説明されるように長さ 2M+1 の文字列を出力する。- 2 行目には、2M-1 個の
+
,S
,+
をこの順に連結して出力する。 - 1+2i 行目 (1\leq i\leq N) には、
+
,o
, c_{i,1},o
, c_{i,2}, \dots, c_{i,M-1},o
,+
をこの順に連結して出力する。 ここで、c_{i,j} はマス (i,j),(i,j+1) の間に壁を置くならば|
、置かないならば.
である。 - 2+2i 行目 (1\leq i\leq N-1) には、
+
, r_{i,1},+
, r_{i,2},+
, \dots,+
, r_{i,M},+
をこの順に連結して出力する。 ここで、r_{i,j} はマス (i,j),(i+1,j) の間に壁を置くならば-
、置かないならば.
である。 - 2N+2 行目には、2M-1 個の
+
,G
,+
をこの順に連結して出力する。
- 2 行目には、2M-1 個の
入力例 1
3 3 7
出力例 1
Yes +++++S+ +o.o.o+ +.+-+-+ +o.o.o+ +-+-+.+ +o.o|o+ +++++G+
問題文中の図と同じ壁の配置です。
入力例 2
3 3 2
出力例 2
No
入力例 3
4 1 4
出力例 3
Yes +S+ +o+ +.+ +o+ +.+ +o+ +.+ +o+ +G+
Score : 525 points
Problem Statement
Snuke is planning to build a maze as a new attraction in AtCoder Land. The maze is represented as a grid with N rows and M columns, with the top edge of the top-right cell being the entrance and the bottom edge of the bottom-right cell being the exit. He will create the maze by appropriately placing walls between adjacent cells.
He loves simple mazes, so he wants the path from the entrance to the exit to pass through exactly K cells without any branches. Determine if it is possible to create such a maze, and if possible, construct one.
For example, in the following figure, N=3 and M=3, and walls are placed at the solid lines (walls are always placed around the outer perimeter except for the entrance and exit). In this case, the path from the entrance to the exit passes through exactly 7 cells without any branches.
Below is a formal statement.
There is a grid with N rows and M columns. Let (i, j) denote the cell at the i-th row from the top and j-th column from the left. For each pair of side-adjacent cells, you can decide whether to place a wall between them. Determine whether it is possible to place walls to satisfy the following condition, and if it is possible, construct one such placement.
Consider an undirected graph G with NM vertices. Each vertex of G is uniquely labeled by a pair of integers (i,j)\ (1\leq i\leq N, 1\leq j\leq M). Two distinct vertices (i_1,j_1) and (i_2,j_2) are connected by an edge if and only if |i_1-i_2|+|j_1-j_2|=1 and there is no wall between the corresponding cells (i_1,j_1) and (i_2,j_2) on the grid.
Condition: there exists a simple path with K vertices that connects the two vertices (1,M) and (N,M), and the connected component containing the vertices (1,M) and (N,M) consists only of this path.
Constraints
- 2\leq N \leq 100
- 1\leq M \leq 100
- 1\leq K\leq NM
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N M K
Output
If there is no placement of walls that satisfies the condition, print No
. Otherwise, print one such placement in the following format. If multiple valid placements exist, any of them can be printed.
See also the sample outputs below to better understand the complicated output format.
Yes +++++ \dots +++S+ +o?o? \dots ?o?o+ +?+?+ \dots +?+?+ +o?o? \dots ?o?o+ +?+?+ \dots +?+?+ \vdots +o?o? \dots ?o?o+ +?+?+ \dots +?+?+ +o?o? \dots ?o?o+ +++++ \dots +++G+
Here, S
, G
, +
, and o
represent the entrance, exit, a wall, and a cell, respectively, and ?
between cells represents a position where a wall can be placed. Replace ?
between two horizontally adjacent cells with |
if a wall is placed, and .
otherwise. Replace ?
between two vertically adjacent cells with -
if a wall is placed, and .
otherwise.
Below is a formal instruction.
- The output should consist of 2N+2 lines. Line 1 should contain the string
Yes
, and lines 2 to 2N+2 should contain strings of length 2M+1 as described below.- Line 2 should be a concatenation of
+
repeated 2M-1 times,S
, and+
, in this order. - Line 1+2i (1\leq i\leq N) should be a concatenation of
+
,o
, c_{i,1},o
, c_{i,2}, \dots, c_{i,M-1},o
,+
, in this order. Here, c_{i,j} is|
if a wall is placed between cells (i,j) and (i,j+1), and.
otherwise. - Line 2+2i (1\leq i\leq N-1) should be a concatenation of
+
, r_{i,1},+
, r_{i,2},+
, \dots,+
, r_{i,M},+
, in this order. Here, r_{i,j} is-
if a wall is placed between cells (i,j) and (i+1,j), and.
otherwise. - Line 2N+2 should be a concatenation of
+
repeated 2M-1 times,G
, and+
, in this order.
- Line 2 should be a concatenation of
Sample Input 1
3 3 7
Sample Output 1
Yes +++++S+ +o.o.o+ +.+-+-+ +o.o.o+ +-+-+.+ +o.o|o+ +++++G+
This is the same placement of walls as in the figure in the problem statement.
Sample Input 2
3 3 2
Sample Output 2
No
Sample Input 3
4 1 4
Sample Output 3
Yes +S+ +o+ +.+ +o+ +.+ +o+ +.+ +o+ +G+
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 550 点
問題文
AtCoder Land は H 行 W 列のグリッドで表されます。上から i 番目、左から j 番目のマスを (i, j) と表記します。
高橋君ははじめマス (S_i, S_j) におり、以下の行動を K 回繰り返します。
- 高橋君は現在いるマスに留まるか、隣のマスに移動する。その後の時点で高橋君がいるマスを (i, j) として A_{i, j} の楽しさを得る。
高橋君が得ることのできる楽しさの合計の最大値を求めてください。
ただし、マス (x', y') がマス (x, y) の隣のマスであるとは |x - x'| + |y - y'| = 1 であることを指します。
制約
- 1 \leq H, W \leq 50
- 1 \leq K \leq 10^9
- 1 \leq S_i \leq H
- 1 \leq S_j \leq W
- 1 \leq A_{i, j} \leq 10^9
- 入力される値はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
H W K S_i S_j A_{1, 1} A_{1, 2} \ldots A_{1, W} A_{2, 1} A_{2, 2} \ldots A_{2, W} \vdots A_{H, 1} A_{H, 2} \ldots A_{H, W}
出力
答えを出力せよ。
入力例 1
2 3 3 1 2 2 1 2 3 4 5
出力例 1
14
高橋君は以下のように行動することで楽しさの合計を 14 にすることができます。
- はじめ、高橋君は (1, 2) にいる。
- 高橋君はマス (2, 2) に移動する。その後、A_{2, 2} = 4 の楽しさを得る。
- 高橋君はマス (2, 3) に移動する。その後、A_{2, 3} = 5 の楽しさを得る。
- 高橋君はマス (2, 3) に留まる。その後、A_{2, 3} = 5 の楽しさを得る。
高橋君は楽しさの合計を 14 より大きくすることはできないため、14 を出力します。
入力例 2
2 2 1000000000 2 1 100 100 100 99
出力例 2
100000000000
Score : 550 points
Problem Statement
AtCoder Land is represented by a grid with H rows and W columns. Let (i, j) denote the cell at the i-th row and j-th column.
Takahashi starts at cell (S_i, S_j) and repeats the following action K times:
- He either stays in the current cell or moves to an adjacent cell. After this action, if he is in cell (i, j), he gains a fun value of A_{i, j}.
Find the maximum total fun value he can gain.
Here, a cell (x', y') is considered adjacent to cell (x, y) if and only if |x - x'| + |y - y'| = 1.
Constraints
- 1 \leq H, W \leq 50
- 1 \leq K \leq 10^9
- 1 \leq S_i \leq H
- 1 \leq S_j \leq W
- 1 \leq A_{i, j} \leq 10^9
- All input values are integers.
Input
The input is given from Standard Input in the following format:
H W K S_i S_j A_{1, 1} A_{1, 2} \ldots A_{1, W} A_{2, 1} A_{2, 2} \ldots A_{2, W} \vdots A_{H, 1} A_{H, 2} \ldots A_{H, W}
Output
Print the answer.
Sample Input 1
2 3 3 1 2 2 1 2 3 4 5
Sample Output 1
14
Takahashi can gain a total fun value of 14 by acting as follows:
- Initially, he is at (1, 2).
- He moves to cell (2, 2). Then, he gains a fun value of A_{2, 2} = 4.
- He moves to cell (2, 3). Then, he gains a fun value of A_{2, 3} = 5.
- He stays in cell (2, 3). Then, he gains a fun value of A_{2, 3} = 5.
He cannot gain a total fun value greater than 14, so print 14.
Sample Input 2
2 2 1000000000 2 1 100 100 100 99
Sample Output 2
100000000000