実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 100 点
問題文
長さ N の英小文字からなる文字列 S が与えられます。
S の i 文字目を S_i と記します。
S_1,S_1,S_2,S_2,\dots,S_N,S_N をこの順に連結した長さ 2N の文字列を出力してください。
例えば、 S が beginner
のときは bbeeggiinnnneerr
と出力してください。
制約
- N は 1 \le N \le 50 を満たす整数
- S は長さ N の英小文字からなる文字列
入力
入力は以下の形式で標準入力から与えられる。
N S
出力
答えを出力せよ。
入力例 1
8 beginner
出力例 1
bbeeggiinnnneerr
問題文中の例と同じです。
入力例 2
3 aaa
出力例 2
aaaaaa
Score : 100 points
Problem Statement
You are given a string S of length N consisting of lowercase English letters.
We denote the i-th character of S by S_i.
Print the string of length 2N obtained by concatenating S_1,S_1,S_2,S_2,\dots,S_N, and S_N in this order.
For example, if S is beginner
, print bbeeggiinnnneerr
.
Constraints
- N is an integer such that 1 \le N \le 50.
- S is a string of length N consisting of lowercase English letters.
Input
The input is given from Standard Input in the following format:
N S
Output
Print the answer.
Sample Input 1
8 beginner
Sample Output 1
bbeeggiinnnneerr
It is the same as the example described in the problem statement.
Sample Input 2
3 aaa
Sample Output 2
aaaaaa
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 150 点
問題文
A, B, C の三兄弟がいます。この 3 人の年齢関係は、3 つの文字 S_{\mathrm{AB}},S_{\mathrm{AC}},S_{\mathrm{BC}} によって与えられ、それぞれ以下を意味します。
- S_{\mathrm{AB}} が
<
の場合 A は B より年下であり、>
の場合 A は B より年上である。 - S_{\mathrm{AC}} が
<
の場合 A は C より年下であり、>
の場合 A は C より年上である。 - S_{\mathrm{BC}} が
<
の場合 B は C より年下であり、>
の場合 B は C より年上である。
三兄弟の次男、つまり二番目に年上の人は誰ですか?
制約
- S_{\mathrm{AB}},S_{\mathrm{AC}},S_{\mathrm{BC}} はそれぞれ
<
または>
- 入力に矛盾は含まれない。つまり、与えられた大小関係を全て満たす年齢関係が必ず存在する入力のみが与えられる。
入力
入力は以下の形式で標準入力から与えられる。
S_{\mathrm{AB}} S_{\mathrm{AC}} S_{\mathrm{BC}}
出力
三兄弟の次男、つまり二番目に年上の人の名前を出力せよ。
入力例 1
< < <
出力例 1
B
A が B より年下であり、B が C より年下であることから、C が長男、B が次男、A が三男であることがわかります。よって答えは B
です。
入力例 2
< < >
出力例 2
C
Score : 150 points
Problem Statement
There are three brothers named A
, B
, and C
. The age relationships among them are given by three characters S_{\mathrm{AB}}, S_{\mathrm{AC}}, S_{\mathrm{BC}}, which mean the following:
- If S_{\mathrm{AB}} is
<
, then A is younger than B; if it is>
, then A is older than B. - If S_{\mathrm{AC}} is
<
, then A is younger than C; if it is>
, then A is older than C. - If S_{\mathrm{BC}} is
<
, then B is younger than C; if it is>
, then B is older than C.
Who is the middle brother, that is, the second oldest among the three?
Constraints
- Each of S_{\mathrm{AB}}, S_{\mathrm{AC}}, S_{\mathrm{BC}} is
<
or>
. - The input contains no contradictions; that is, there always exists an age relationship that satisfies all given inequalities.
Input
The input is given from Standard Input in the following format:
S_{\mathrm{AB}} S_{\mathrm{AC}} S_{\mathrm{BC}}
Output
Print the name of the middle brother, that is, the second oldest among the three.
Sample Input 1
< < <
Sample Output 1
B
Since A is younger than B, and B is younger than C, we can determine that C is the oldest, B is the middle, and A is the youngest. Hence, the answer is B
.
Sample Input 2
< < >
Sample Output 2
C
実行時間制限: 2 sec / メモリ制限: 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.
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 200 点
問題文
正整数 N が与えられるので、下記で定まる長さ (N+1) の文字列 s_0s_1\ldots s_N を出力してください。
各 i = 0, 1, 2, \ldots, N について、
- 1 以上 9 以下の N の約数 j であって、i が N/j の倍数であるものが存在するとき、そのような j のうち最小のものに対応する数字を s_i とする。(よって、この場合 s_i は
1
、2
、\ldots 、9
のいずれかである。)- そのような j が存在しないとき、s_i は
-
とする。
制約
- 1 \leq N \leq 1000
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N
出力
答えを出力せよ。
入力例 1
12
出力例 1
1-643-2-346-1
以下で、いくつかの i について s_i の決め方を説明します。
-
i = 0 について、1 以上 9 以下の N の約数 j であって i が N/j の倍数であるものは、j = 1, 2, 3, 4, 6 の 5 個です。そのうち最小のものは 1 であるので、s_0 =
1
です。 -
i = 4 について、1 以上 9 以下の N の約数 j であって i が N/j の倍数であるものは、j = 3, 6 の 2 個です。そのうち最小のものは 3 であるので、s_4 =
3
です。 -
i = 11 について、1 以上 9 以下の N の約数 j であって i が N/j の倍数であるものは存在しないので、s_{11} =
-
です。
入力例 2
7
出力例 2
17777771
入力例 3
1
出力例 3
11
Score : 200 points
Problem Statement
You are given a positive integer N. Print a string of length (N+1), s_0s_1\ldots s_N, defined as follows.
For each i = 0, 1, 2, \ldots, N,
- if there is a divisor j of N that is between 1 and 9, inclusive, and i is a multiple of N/j, then s_i is the digit corresponding to the smallest such j (s_i will thus be one of
1
,2
, ...,9
);- if no such j exists, then s_i is
-
.
Constraints
- 1 \leq N \leq 1000
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N
Output
Print the answer.
Sample Input 1
12
Sample Output 1
1-643-2-346-1
We will explain how to determine s_i for some i.
-
For i = 0, the divisors j of N between 1 and 9 such that i is a multiple of N/j are 1, 2, 3, 4, 6. The smallest of these is 1, so s_0 =
1
. -
For i = 4, the divisors j of N between 1 and 9 such that i is a multiple of N/j are 3, 6. The smallest of these is 3, so s_4 =
3
. -
For i = 11, there are no divisors j of N between 1 and 9 such that i is a multiple of N/j, so s_{11} =
-
.
Sample Input 2
7
Sample Output 2
17777771
Sample Input 3
1
Sample Output 3
11
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 300 点
問題文
縦 H マス横 W マスのグリッドがあります。グリッドの上から i 行目、左から j 列目のマスを (i, j) と呼びます。
グリッドの各マスには #
と .
のいずれかの文字が書かれています。(i, j) に書かれている文字を C[i][j] とします。また、整数 i, j が 1 \leq i \leq H と 1 \leq j \leq W の少なくとも一方を満たさない場合、 C[i][j] を .
と定義します。
正整数 a, b, n が以下の条件を全て満たす時、(a,b) および (a+d,b+d),(a+d,b-d),(a-d,b+d),(a-d,b-d) (1 \leq d \leq n) の 4n + 1 マスを (a,b) を中心とするサイズ n のバツ印 と呼びます。
- C[a][b] は
#
である。 - 1 \leq d \leq n を満たす整数 d について、 C[a+d][b+d],C[a+d][b-d],C[a-d][b+d],C[a-d][b-d] はいずれも
#
である。 - C[a+n+1][b+n+1],C[a+n+1][b-n-1],C[a-n-1][b+n+1],C[a-n-1][b-n-1] のうち少なくとも 1 つは
.
である。
例えば次の図で示された例では、(2, 2) を中心とするサイズ 1 のバツ印と (3, 7) を中心とするサイズ 2 のバツ印がグリッド上にあります。
グリッドにはいくつかのバツ印があります。バツ印を構成するマス以外に #
は書かれていません。
また、異なるバツ印を構成するマス同士は頂点を共有しません。以下の 2 つのグリッドは異なるバツ印を構成するマス同士が頂点を共有している例で、このようなグリッドの状態は入力として与えられません。 例えば左のグリッドでは (3, 3) と (4, 4) が頂点を共有しているのが条件に反しています。
N = \min(H, W) とします。また、サイズ n のバツ印の個数を S_n とします。S_1, S_2, \dots, S_N を計算してください。
制約
- 3 \leq H, W \leq 100
- C[i][j] は
#
または.
- 異なるバツ印を構成するマス同士は頂点を共有しない
- H, W は整数
入力
入力は以下の形式で標準入力から与えられる。
H W C[1][1]C[1][2]\dots C[1][W] C[2][1]C[2][2]\dots C[2][W] \vdots C[H][1]C[H][2]\dots C[H][W]
出力
S_1, S_2, \dots, S_N を空白区切りで出力せよ。
入力例 1
5 9 #.#.#...# .#...#.#. #.#...#.. .....#.#. ....#...#
出力例 1
1 1 0 0 0
問題文に書かれた説明の通り、(2, 2) を中心とするサイズ 1 のバツ印と (3, 7) を中心とするサイズ 2 のバツ印が書かれています。
入力例 2
3 3 ... ... ...
出力例 2
0 0 0
バツ印が 1 個も書かれていない場合もあります。
入力例 3
3 16 #.#.....#.#..#.# .#.......#....#. #.#.....#.#..#.#
出力例 3
3 0 0
入力例 4
15 20 #.#..#.............# .#....#....#.#....#. #.#....#....#....#.. ........#..#.#..#... #.....#..#.....#.... .#...#....#...#..#.# ..#.#......#.#....#. ...#........#....#.# ..#.#......#.#...... .#...#....#...#..... #.....#..#.....#.... ........#.......#... #.#....#....#.#..#.. .#....#......#....#. #.#..#......#.#....#
出力例 4
5 0 1 0 0 0 1 0 0 0 0 0 0 0 0
Score : 300 points
Problem Statement
We have a grid with H horizontal rows and W vertical columns. We denote by (i, j) the cell at the i-th row from the top and j-th column from the left of the grid.
Each cell in the grid has a symbol #
or .
written on it. Let C[i][j] be the character written on (i, j). For integers i and j such that at least one of 1 \leq i \leq H and 1 \leq j \leq W is violated, we define C[i][j] to be .
.
(4n+1) squares, consisting of (a, b) and (a+d,b+d),(a+d,b-d),(a-d,b+d),(a-d,b-d) (1 \leq d \leq n, 1 \leq n), are said to be a cross of size n centered at (a,b) if and only if all of the following conditions are satisfied:
- C[a][b] is
#
. - C[a+d][b+d],C[a+d][b-d],C[a-d][b+d], and C[a-d][b-d] are all
#
, for all integers d such that 1 \leq d \leq n, - At least one of C[a+n+1][b+n+1],C[a+n+1][b-n-1],C[a-n-1][b+n+1], and C[a-n-1][b-n-1] is
.
.
For example, the grid in the following figure has a cross of size 1 centered at (2, 2) and another of size 2 centered at (3, 7).
The grid has some crosses. No #
is written on the cells except for those comprising a cross.
Additionally, no two squares that comprise two different crosses share a corner. The two grids in the following figure are the examples of grids where two squares that comprise different crosses share a corner; such grids are not given as an input. For example, the left grid is invalid because (3, 3) and (4, 4) share a corner.
Let N = \min(H, W), and S_n be the number of crosses of size n. Find S_1, S_2, \dots, S_N.
Constraints
- 3 \leq H, W \leq 100
- C[i][j] is
#
or.
. - No two different squares that comprise two different crosses share a corner.
- H and W are integers.
Input
The input is given from Standard Input in the following format:
H W C[1][1]C[1][2]\dots C[1][W] C[2][1]C[2][2]\dots C[2][W] \vdots C[H][1]C[H][2]\dots C[H][W]
Output
Print S_1, S_2, \dots, and S_N, separated by spaces.
Sample Input 1
5 9 #.#.#...# .#...#.#. #.#...#.. .....#.#. ....#...#
Sample Output 1
1 1 0 0 0
As described in the Problem Statement, there are a cross of size 1 centered at (2, 2) and another of size 2 centered at (3, 7).
Sample Input 2
3 3 ... ... ...
Sample Output 2
0 0 0
There may be no cross.
Sample Input 3
3 16 #.#.....#.#..#.# .#.......#....#. #.#.....#.#..#.#
Sample Output 3
3 0 0
Sample Input 4
15 20 #.#..#.............# .#....#....#.#....#. #.#....#....#....#.. ........#..#.#..#... #.....#..#.....#.... .#...#....#...#..#.# ..#.#......#.#....#. ...#........#....#.# ..#.#......#.#...... .#...#....#...#..... #.....#..#.....#.... ........#.......#... #.#....#....#.#..#.. .#....#......#....#. #.#..#......#.#....#
Sample Output 4
5 0 1 0 0 0 1 0 0 0 0 0 0 0 0