Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
チェス盤のどこにコマが置かれているか答えてください。
縦 8 マス、横 8 マスのグリッドがあります。グリッドの各マスには、次のルールで定められる長さ 2 の文字列の名前がついています。
- 左から 1 列目にあるマスの名前の 1 文字目は
aである。同様に、左から 2,3,\ldots,8 列目にあるマスの名前の 1 文字目はb,c,d,e,f,g,hである。 - 下から 1 行目にあるマスの名前の 2 文字目は
1である。同様に、下から 2,3,\ldots,8 行目にあるマスの名前の 2 文字目は2,3,4,5,6,7,8である。
例えば、グリッドの左下のマスの名前は a1、右下のマスの名前は h1、右上のマスの名前は h8 です。
グリッドの状態を表す長さ 8 の 8 つの文字列 S_1,\ldots,S_8 が与えられます。
S_i の j 文字目は、グリッドの上から i 行目 左から j 列目のマスにコマが置かれているとき *、置かれていないとき . であり、S_1,\ldots,S_8 の中に文字 * はちょうど 1 つ存在します。
コマが置かれているマスの名前を求めてください。
制約
- S_i は
.および*のみからなる長さ 8 の文字列である - S_1,\ldots,S_8 の中に文字
*はちょうど 1 つ存在する。
入力
入力は以下の形式で標準入力から与えられる。
S_1 S_2 S_3 S_4 S_5 S_6 S_7 S_8
出力
答えを出力せよ。
入力例 1
........ ........ ........ ........ ........ ........ ........ *.......
出力例 1
a1
問題文中で説明したとおり、グリッドの左下のマスの名前は a1 です。
入力例 2
........ ........ ........ ........ ........ .*...... ........ ........
出力例 2
b3
Score : 200 points
Problem Statement
Locate a piece on a chessboard.
We have a grid with 8 rows and 8 columns of squares. Each of the squares has a 2-character name determined as follows.
- The first character of the name of a square in the 1-st column from the left is
a. Similarly, the first character of the name of a square in the 2-nd, 3-rd, \ldots, 8-th column from the left isb,c,d,e,f,g,h, respectively. - The second character of the name of a square in the 1-st row from the bottom is
1. Similarly, the second character of the name of a square in the 2-nd, 3-rd, \ldots, 8-th row from the bottom is2,3,4,5,6,7,8, respectively.
For instance, the bottom-left square is named a1, the bottom-right square is named h1, and the top-right square is named h8.
You are given 8 strings S_1,\ldots,S_8, each of length 8, representing the state of the grid.
The j-th character of S_i is * if the square at the i-th row from the top and j-th column from the left has a piece on it, and . otherwise.
The character * occurs exactly once among S_1,\ldots,S_8.
Find the name of the square that has a piece on it.
Constraints
- S_i is a string of length 8 consisting of
.and*. - The character
*occurs exactly once among S_1,\ldots,S_8.
Input
The input is given from Standard Input in the following format:
S_1 S_2 S_3 S_4 S_5 S_6 S_7 S_8
Output
Print the answer.
Sample Input 1
........ ........ ........ ........ ........ ........ ........ *.......
Sample Output 1
a1
As explained in the problem statement, the bottom-left square is named a1.
Sample Input 2
........ ........ ........ ........ ........ .*...... ........ ........
Sample Output 2
b3
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
N 個の整数 A_1, A_2, \ldots, A_N が与えられます。 このうち最大でない整数の中で最大である整数を求めてください。
ただし、この問題の制約下で答えは必ず存在します。
制約
- 2 \leq N \leq 100
- 1 \leq A_i \leq 100
- A_1, A_2, \ldots, A_N がすべて等しいということはない
- 入力値はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N A_1 A_2 \ldots A_N
出力
答えを出力せよ。
入力例 1
5 2 1 3 3 2
出力例 1
2
2,1,3,3,2 の中で最大である整数は 3 です。
2,1,3,3,2 の中で 3 でない整数は 2,1,2 の 3 つであり、これらの中で最大である整数は 2 です。
入力例 2
4 4 3 2 1
出力例 2
3
入力例 3
8 22 22 18 16 22 18 18 22
出力例 3
18
Score : 200 points
Problem Statement
You are given N integers A_1, A_2, \ldots, A_N. Find the largest among those integers that are not the largest.
The constraints of this problem guarantee that the answer exists.
Constraints
- 2 \leq N \leq 100
- 1 \leq A_i \leq 100
- It is not the case that all A_1, A_2, \ldots, A_N are equal.
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N A_1 A_2 \ldots A_N
Output
Print the answer.
Sample Input 1
5 2 1 3 3 2
Sample Output 1
2
The largest integer among 2,1,3,3,2 is 3.
The integers that are not 3 among 2,1,3,3,2 are 2,1,2, among which the largest is 2.
Sample Input 2
4 4 3 2 1
Sample Output 2
3
Sample Input 3
8 22 22 18 16 22 18 18 22
Sample Output 3
18
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 250 点
問題文
一台のバスが走っています。バスの乗客の数は常に非負整数です。
このバスにはある時点で 0 人以上の乗客が乗っており、その時点から現在までに N 回停車しました。このうち i 回目の停車では乗客が差し引き A_i 人増えました。A_i は負の値であることもあり、その場合は乗客が差し引き -A_i 人減ったことを意味しています。また、停車時以外には乗客の乗り降りはありませんでした。
与えられた情報に矛盾しない現在のバスの乗客の数として考えられる最小値を求めてください。
制約
- 1 \leq N \leq 2 \times 10^5
- -10^9 \leq A_i \leq 10^9
- 入力される数値はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N A_1 A_2 \ldots A_N
出力
答えを出力せよ。
入力例 1
4 3 -5 7 -4
出力例 1
3
はじめに乗っている乗客の人数が 2 人であるとき、現在の乗客の人数は 2 + 3 + (-5) + 7 + (-4) = 3 人であり、さらにバスの乗客の人数は常に非負整数となります。
入力例 2
5 0 0 0 0 0
出力例 2
0
入力例 3
4 -1 1000000000 1000000000 1000000000
出力例 3
3000000000
Score: 250 points
Problem Statement
A bus is in operation. The number of passengers on the bus is always a non-negative integer.
At some point in time, the bus had zero or more passengers, and it has stopped N times since then. At the i-th stop, the number of passengers increased by A_i. Here, A_i can be negative, meaning the number of passengers decreased by -A_i. Also, no passengers got on or off the bus other than at the stops.
Find the minimum possible current number of passengers on the bus that is consistent with the given information.
Constraints
- 1 \leq N \leq 2 \times 10^5
- -10^9 \leq A_i \leq 10^9
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N A_1 A_2 \ldots A_N
Output
Print the answer.
Sample Input 1
4 3 -5 7 -4
Sample Output 1
3
If the initial number of passengers was 2, the current number of passengers would be 2 + 3 + (-5) + 7 + (-4) = 3, and the number of passengers on the bus would have always been a non-negative integer.
Sample Input 2
5 0 0 0 0 0
Sample Output 2
0
Sample Input 3
4 -1 1000000000 1000000000 1000000000
Sample Output 3
3000000000
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
高橋君は部屋に PC を沢山置こうとしています。そこで最大何台の PC を部屋に置けるか調べるプログラムを書くことにしました。
H 個の長さ W の ., T からなる文字列 S_1,S_2,\ldots,S_H が与えられます。
高橋君は以下の操作を 0 回以上何回でも行うことができます。
- 1\leq i \leq H, 1 \leq j \leq W-1 を満たす整数であって、 S_i の j 番目の文字も j+1 番目の文字も
Tであるようなものを選ぶ。 S_i の j 番目の文字をPで置き換え、S_i の j+1 番目の文字をCで置き換える。
高橋君が操作回数の最大化を目指すとき、操作終了後の S_1,S_2,\ldots,S_H としてあり得るものの一例を出力してください。
制約
- 1\leq H \leq 100
- 2\leq W \leq 100
- H と W は整数である
- S_i は
.,Tからなる長さ W の文字列
入力
入力は以下の形式で標準入力から与えられる。
H W S_1 S_2 \vdots S_H
出力
高橋君が操作回数の最大化を目指すとき、操作終了後の S_1,S_2,\ldots,S_H としてあり得るものの一例を改行区切りで出力せよ。
解が複数存在する場合、どれを出力しても正答とみなされる。
入力例 1
2 3 TTT T.T
出力例 1
PCT T.T
可能な操作回数の最大値は 1 です。
例えば、 (i,j)=(1,1) として操作を行うと、S_1 が PCT に変化します。
入力例 2
3 5 TTT.. .TTT. TTTTT
出力例 2
PCT.. .PCT. PCTPC
Score : 300 points
Problem Statement
Planning to place many PCs in his room, Takahashi has decided to write a code that finds how many PCs he can place in his room.
You are given H strings S_1,S_2,\ldots,S_H, each of length W, consisting of . and T.
Takahashi may perform the following operation any number of times (possibly zero):
- Choose integers satisfying 1\leq i \leq H and 1 \leq j \leq W-1 such that the j-th and (j+1)-th characters of S_i are both
T. Replace the j-th character of S_i withP, and (j+1)-th withC.
He tries to maximize the number of times he performs the operation. Find possible resulting S_1,S_2,\ldots,S_H.
Constraints
- 1\leq H \leq 100
- 2\leq W \leq 100
- H and W are integers.
- S_i is a string of length W consisting of
.andT.
Input
The input is given from Standard Input in the following format:
H W S_1 S_2 \vdots S_H
Output
Print a sequence of strings, S_1,S_2,\ldots,S_H, separated by newlines, possibly resulting from maximizing the number of times he performs the operation.
If multiple solutions exist, print any of them.
Sample Input 1
2 3 TTT T.T
Sample Output 1
PCT T.T
He can perform the operation at most once.
For example, an operation with (i,j)=(1,1) makes S_1 PCT.
Sample Input 2
3 5 TTT.. .TTT. TTTTT
Sample Output 2
PCT.. .PCT. PCTPC
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 400 点
問題文
高橋君はあるサービスで使うユーザー名を決めるのに困っています。彼を助けるプログラムを書いてください。
以下の条件をすべて満たす文字列 X を 1 つ求めてください。
- X は次の手順で得られる文字列である。
- N 個の文字列 S_1,S_2,\ldots,S_N を好きな順番で並べたものを S_1', S_2', \ldots,S_N' とする。そして、S_1'、( 1 個以上の
_)、S_2'、( 1 個以上の_)、\ldots、( 1 個以上の_)、S_N' をこの順番で連結したものを X とする。
- N 個の文字列 S_1,S_2,\ldots,S_N を好きな順番で並べたものを S_1', S_2', \ldots,S_N' とする。そして、S_1'、( 1 個以上の
- X の文字数は 3 以上 16 以下である。
- X は M 個の文字列 T_1,T_2,\ldots,T_M のいずれとも一致しない。
ただし、条件をすべて満たす文字列 X が存在しない場合は代わりに -1 と出力してください。
制約
- 1 \leq N \leq 8
- 0 \leq M \leq 10^5
- N,M は整数
- 1 \leq |S_i| \leq 16
- N-1+\sum{|S_i|} \leq 16
- i \neq j ならば S_i \neq S_j
- S_i は英小文字のみからなる文字列
- 3 \leq |T_i| \leq 16
- i \neq j ならば T_i \neq T_j
- T_i は英小文字と
_のみからなる文字列
入力
入力は以下の形式で標準入力から与えられる。
N M S_1 S_2 \vdots S_N T_1 T_2 \vdots T_M
出力
条件をすべて満たす文字列 X を 1 つ出力せよ。ただし、条件をすべて満たす文字列 X が存在しない場合は代わりに -1 を出力せよ。
答えが複数存在する場合、どれを出力しても良い。
入力例 1
1 1 chokudai chokudai
出力例 1
-1
条件のうち 1 番目と 2 番目を満たす文字列は X= chokudai しかありませんが、これは T_1 と一致します。
このため、条件をすべて満たす文字列 X が存在せず、-1 が正しい出力となります。
入力例 2
2 2 choku dai chokudai choku_dai
出力例 2
dai_choku
この他に、choku__dai (choku と dai の間の _ が 2 つ) 等も条件をすべて満たします。
入力例 3
2 2 chokudai atcoder chokudai_atcoder atcoder_chokudai
出力例 3
-1
chokudai__atcoder や atcoder__chokudai (chokudai と atcoder の間の _ が 2 つ)は文字数が 17 なので 2 番目の条件を満たしません。
入力例 4
4 4 ab cd ef gh hoge fuga ____ _ab_cd_ef_gh_
出力例 4
ab__ef___cd_gh
1 番目の条件で記述されている操作で得られないような文字列が T_i として与えられる場合があります。
Score : 400 points
Problem Statement
Takahashi is having trouble with deciding a username for a service. Write a code to help him.
Find a string X that satisfies all of the following conditions:
- X is obtained by the following procedure:
- Let S_1', S_2', \ldots,S_N' be a permutation of S_1, S_2, \ldots,S_N. Let X be the concatenation of S_1', (1 or more copies of
_), S_2', (1 or more copies of_), \ldots, (1 or more copies of_), and S_N', in this order.
- Let S_1', S_2', \ldots,S_N' be a permutation of S_1, S_2, \ldots,S_N. Let X be the concatenation of S_1', (1 or more copies of
- The length of X is between 3 and 16, inclusive.
- X does not coincide with any of M strings T_1,T_2,\ldots,T_M.
If there is no X that satisfies all of the conditions, print -1 instead.
Constraints
- 1 \leq N \leq 8
- 0 \leq M \leq 10^5
- N and M are integers.
- 1 \leq |S_i| \leq 16
- N-1+\sum{|S_i|} \leq 16
- S_i \neq S_j if i \neq j.
- S_i is a string consisting of lowercase English letters.
- 3 \leq |T_i| \leq 16
- T_i \neq T_j if i \neq j.
- T_i is a string consisting of lowercase English letters and
_.
Input
Input is given from Standard Input in the following format:
N M S_1 S_2 \vdots S_N T_1 T_2 \vdots T_M
Output
Print a string X that satisfies all of the conditions. If there is no X that satisfies all of the conditions, print -1 instead.
If there are multiple solutions, print any of them.
Sample Input 1
1 1 chokudai chokudai
Sample Output 1
-1
The only string that satisfies the first and second conditions is X= chokudai, but it coincides with T_1.
Thus, there is no X that satisfies all of the conditions, so -1 should be printed.
Sample Input 2
2 2 choku dai chokudai choku_dai
Sample Output 2
dai_choku
Strings like choku__dai (which has two _'s between choku and dai) also satisfy all of the conditions.
Sample Input 3
2 2 chokudai atcoder chokudai_atcoder atcoder_chokudai
Sample Output 3
-1
chokudai__atcoder and atcoder__chokudai (which have two _'s between chokudai and atcoder) have a length of 17, which violates the second condition.
Sample Input 4
4 4 ab cd ef gh hoge fuga ____ _ab_cd_ef_gh_
Sample Output 4
ab__ef___cd_gh
The given T_i may contain a string that cannot be obtained by the procedure described in the first condition.