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
配点 : 100 点
問題文
AtCoder 国の暦では、1 年は 1 月から M 月までの M ヶ月からなり、どの月も 1 日から D 日までの D 日からなります。
AtCoder 国の暦で y 年 m 月 d 日の翌日は何年何月何日であるか求めてください。
制約
- 1000 \leq y \leq 9000
- 1 \leq m \leq M \leq 99
- 1 \leq d \leq D \leq 99
- 入力は全て整数である
入力
入力は以下の形式で標準入力から与えられる。
M D y m d
出力
AtCoder 国の暦で y 年 m 月 d 日の翌日が y' 年 m' 月 d' 日であるとき、y',m',d' をこの順に空白区切りで出力せよ。
入力例 1
12 30 2023 12 30
出力例 1
2024 1 1
AtCoder 国の暦では 1 年は 12 ヶ月であり、どの月も 30 日からなります。 よって、2023 年 12 月 30 日の翌日は 2024 年 1 月 1 日になります。
入力例 2
36 72 6789 23 45
出力例 2
6789 23 46
AtCoder 国の暦では 1 年は 36 ヶ月であり、どの月も 72 日からなります。 よって、6789 年 23 月 45 日の翌日は 6789 年 23 月 46 日になります。
入力例 3
12 30 2012 6 20
出力例 3
2012 6 21
Score : 100 points
Problem Statement
In the calendar of AtCoder Kingdom, a year consists of M months from month 1 to month M, and each month consists of D days from day 1 to day D.
What day follows year y, month m, day d in this calendar?
Constraints
- 1000 \leq y \leq 9000
- 1 \leq m \leq M \leq 99
- 1 \leq d \leq D \leq 99
- All input values are integers.
Input
The input is given from Standard Input in the following format:
M D y m d
Output
If the day following year y, month m, day d in the calendar of AtCoder Kingdom is year y', month m', day d', print y', m', and d' in this order, separated by spaces.
Sample Input 1
12 30 2023 12 30
Sample Output 1
2024 1 1
In the calendar of the kingdom, a year consists of 12 months, and each month consists of 30 days. Thus, the day following year 2023, month 12, day 30 is year 2024, month 1, day 1.
Sample Input 2
36 72 6789 23 45
Sample Output 2
6789 23 46
In the calendar of the kingdom, one year consists of 36 months, and each month consists of 72 days. Thus, the day following year 6789, month 23, day 45 is year 6789, month 23, day 46.
Sample Input 3
12 30 2012 6 20
Sample Output 3
2012 6 21
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
長さ N の整数からなる数列 A=(A_1,\ldots,A_N) が与えられます。
A_1,\ldots,A_N に含まれない最小の非負整数を求めてください。
制約
- 1 \leq N \leq 2000
- 0 \leq A_i \leq 2000
- 入力は全て整数である
入力
入力は以下の形式で標準入力から与えられる。
N A_1 \ldots A_N
出力
答えを出力せよ。
入力例 1
8 0 3 2 6 2 1 0 0
出力例 1
4
非負整数は 0,1,2,3,4,\ldots と続きます。
0,1,2,3 は A に含まれ、4 は A に含まれないので、答えは 4 です。
入力例 2
3 2000 2000 2000
出力例 2
0
Score : 200 points
Problem Statement
You are given a sequence of length N consisting of integers: A=(A_1,\ldots,A_N).
Find the smallest non-negative integer not in (A_1,\ldots,A_N).
Constraints
- 1 \leq N \leq 2000
- 0 \leq A_i \leq 2000
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N A_1 \ldots A_N
Output
Print the answer.
Sample Input 1
8 0 3 2 6 2 1 0 0
Sample Output 1
4
The non-negative integers are 0,1,2,3,4,\ldots.
We have 0,1,2,3 in A, but not 4, so the answer is 4.
Sample Input 2
3 2000 2000 2000
Sample Output 2
0
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
文字列 S, T が与えられます。以下の操作を高々 1 回行うことで、S を T と一致させることができるかを判定してください。
- S の隣り合う 2 文字を選び、入れ替える。
なお、上記の操作を一度も行わないことも可能です。
制約
- S, T はそれぞれ英小文字のみからなる、長さ 2 以上 100 以下の文字列
- S の長さと T の長さは等しい
入力
入力は以下の形式で標準入力から与えられる。
S T
出力
問題文中の操作を高々 1 回行うことで S を T と一致させることができるなら Yes を、できないなら No を出力せよ。
入力例 1
abc acb
出力例 1
Yes
S の 2 文字目と 3 文字目を入れ替えることで、S を T と一致させることができます。
入力例 2
aabb bbaa
出力例 2
No
どのように操作を行っても、S を T と一致させることはできません。
入力例 3
abcde abcde
出力例 3
Yes
S と T は既に一致しています。
Score : 200 points
Problem Statement
You are given two strings S and T. Determine whether it is possible to make S and T equal by doing the following operation at most once:
- choose two adjacent characters in S and swap them.
Note that it is allowed to choose not to do the operation.
Constraints
- Each of S and T is a string of length between 2 and 100 (inclusive) consisting of lowercase English letters.
- S and T have the same length.
Input
Input is given from Standard Input in the following format:
S T
Output
If it is possible to make S and T equal by doing the operation in Problem Statement at most once, print Yes; otherwise, print No.
Sample Input 1
abc acb
Sample Output 1
Yes
You can swap the 2-nd and 3-rd characters of S to make S and T equal.
Sample Input 2
aabb bbaa
Sample Output 2
No
There is no way to do the operation to make S and T equal.
Sample Input 3
abcde abcde
Sample Output 3
Yes
S and T are already equal.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
列 S_n を次のように定義します。
- S_1 は 1 つの 1 からなる長さ 1 の列である。
- S_n (n は 2 以上の整数) は S_{n-1}, n, S_{n-1} をこの順につなげた列である。
たとえば S_2,S_3 は次のような列です。
- S_2 は S_1, 2, S_1 をこの順につなげた列なので 1,2,1 である。
- S_3 は S_2, 3, S_2 をこの順につなげた列なので 1,2,1,3,1,2,1 である。
N が与えられるので、列 S_N をすべて出力してください。
制約
- N は整数
- 1 \leq N \leq 16
入力
入力は以下の形式で標準入力から与えられる。
N
出力
S_N を空白区切りで出力せよ。
入力例 1
2
出力例 1
1 2 1
問題文の説明にある通り、S_2 は 1,2,1 となります。
入力例 2
1
出力例 2
1
入力例 3
4
出力例 3
1 2 1 3 1 2 1 4 1 2 1 3 1 2 1
S_4 は S_3,4,S_3 をこの順につなげた列です。
Score : 300 points
Problem Statement
We define sequences S_n as follows.
- S_1 is a sequence of length 1 containing a single 1.
- S_n (n is an integer greater than or equal to 2) is a sequence obtained by concatenating S_{n-1}, n, S_{n-1} in this order.
For example, S_2 and S_3 is defined as follows.
- S_2 is a concatenation of S_1, 2, and S_1, in this order, so it is 1,2,1.
- S_3 is a concatenation of S_2, 3, and S_2, in this order, so it is 1,2,1,3,1,2,1.
Given N, print the entire sequence S_N.
Constraints
- N is an integer.
- 1 \leq N \leq 16
Input
Input is given from Standard Input in the following format:
N
Output
Print S_N, with spaces in between.
Sample Input 1
2
Sample Output 1
1 2 1
As described in the Problem Statement, S_2 is 1,2,1.
Sample Input 2
1
Sample Output 2
1
Sample Input 3
4
Sample Output 3
1 2 1 3 1 2 1 4 1 2 1 3 1 2 1
- S_4 is a concatenation of S_3, 4, and S_3, in this order.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
整数 N,K と N 個の整数列 A_1,A_2,\ldots,A_N 、長さ N の整数列 C=(C_1,C_2,\ldots,C_N) が与えられます。整数列 A_i の長さは L_i であり A_i=(A_{i,1},A_{i,2},\ldots,A_{i,L_i}) です。また、\displaystyle 1\le K\le \sum_{i=1}^N C_iL_i が保証されます。
A と C から以下の手順で整数列 B=(B_1,B_2,\ldots,B_{\sum_{i=1}^N C_iL_i}) を構成します。
- B を長さ 0 の整数列とする。
- i=1,2,\ldots,N の順に以下の操作を行う:
- B の末尾に A_i を連結させる操作を C_i 回行う。
B_K の値を求めてください。
制約
- 1\le N
- 1\le L_i
- \displaystyle \sum_{i=1}^N L_i\le 2\times 10^5
- 1\le A_{i,j} \le 10^9 (1\le j\le L_i)
- 1\le C_i\le 10^9
- \displaystyle 1\le K\le \sum_{i=1}^N C_iL_i
- 入力される値は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N K
L_1 A_{1,1} A_{1,2} \ldots A_{1,L_1}
L_2 A_{2,1} A_{2,2} \ldots A_{2,L_2}
\vdots
L_N A_{N,1} A_{N,2} \ldots A_{N,L_N}
C_1 C_2 \ldots C_N
出力
答えを出力せよ。
入力例 1
3 9 3 1 3 2 1 3 2 4 3 1 3 2
出力例 1
4
B は以下のように構成されます:
- B=() とする。
- B の末尾に A_1 を連結させる操作を 1 回行う。B=(1,3,2) となる。
- B の末尾に A_2 を連結させる操作を 3 回行う。B=(1,3,2,3,3,3) となる。
- B の末尾に A_3 を連結させる操作を 2 回行う。B=(1,3,2,3,3,3,4,3,4,3) となる。
B=(1,3,2,3,3,3,4,3,4,3) に対し B_9=4 なので 4 を出力してください。
入力例 2
3 1 1 7 1 111 1 5 1 100 10000
出力例 2
7
入力例 3
3 3163812 5 1 2 3 4 5 4 9 8 7 6 2 10 11 87043 908415 9814
出力例 3
9
Score : 300 points
Problem Statement
You are given integers N and K, along with N integer sequences A_1, A_2, \ldots, A_N and a length-N integer sequence C = (C_1, C_2, \ldots, C_N). The length of integer sequence A_i is L_i, and A_i = (A_{i,1}, A_{i,2}, \ldots, A_{i,L_i}). It is guaranteed that \displaystyle 1 \le K \le \sum_{i=1}^N C_iL_i.
Construct an integer sequence B = (B_1, B_2, \ldots, B_{\sum_{i=1}^N C_iL_i}) from A and C using the following procedure.
- Let B be an integer sequence of length 0.
- For i = 1, 2, \ldots, N in this order, perform the following operation:
- Do this C_i times: append A_i to the end of B.
Find the value of B_K.
Constraints
- 1 \le N
- 1 \le L_i
- \displaystyle \sum_{i=1}^N L_i \le 2 \times 10^5
- 1 \le A_{i,j} \le 10^9 (1 \le j \le L_i)
- 1 \le C_i \le 10^9
- \displaystyle 1 \le K \le \sum_{i=1}^N C_iL_i
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N K
L_1 A_{1,1} A_{1,2} \ldots A_{1,L_1}
L_2 A_{2,1} A_{2,2} \ldots A_{2,L_2}
\vdots
L_N A_{N,1} A_{N,2} \ldots A_{N,L_N}
C_1 C_2 \ldots C_N
Output
Output the answer.
Sample Input 1
3 9 3 1 3 2 1 3 2 4 3 1 3 2
Sample Output 1
4
B is constructed as follows:
- Let B = ().
- Append A_1 to the end of B once. We get B = (1, 3, 2).
- Append A_2 to the end of B three times. We get B = (1, 3, 2, 3, 3, 3).
- Append A_3 to the end of B twice. We get B = (1, 3, 2, 3, 3, 3, 4, 3, 4, 3).
For B = (1, 3, 2, 3, 3, 3, 4, 3, 4, 3), we have B_9 = 4, so output 4.
Sample Input 2
3 1 1 7 1 111 1 5 1 100 10000
Sample Output 2
7
Sample Input 3
3 3163812 5 1 2 3 4 5 4 9 8 7 6 2 10 11 87043 908415 9814
Sample Output 3
9
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 425 点
問題文
H 行 W 列のマス目があります。上から i 行目 (1\leq i\leq H)、左から j 列目 (1\leq j\leq W) のマスをマス (i,j) と呼ぶことにします。
はじめ、マス (i,j) は S_{i,j} が # のとき黒、. のとき白で塗られています。
以下の操作を 10^{100} 回行います。
- 白で塗られているマスであって、そのマスに辺で隣接するマスのうちちょうど 1 つが黒で塗られているようなマスの集合を T とする。T の各マスに対して、そのマスを黒で塗る。ただし、2 つのマス (i_1,j_1),(i_2,j_2) が辺で隣接するとは、 |i_1-i_2|+|j_1-j_2|=1 であることをいう。
すべての操作が終わったあとに黒く塗られているマスの個数を求めてください。
制約
- 2\leq H,W
- HW\leq 3\times 10^5
- H,W は整数
- S_{i,j} は
#または.
入力
入力は以下の形式で標準入力から与えられる。
H W
S_{1,1}S_{1,2}\ldots S_{1,W}
S_{2,1}S_{2,2}\ldots S_{2,W}
\vdots
S_{H,1}S_{H,2}\ldots S_{H,W}
出力
答えを出力せよ。
入力例 1
9 9 ......... ......... ......... ......... ....#.... ......... ......... ......... .........
出力例 1
57
操作によってマス目は以下のように変化します。(上の数字は操作回数を表しており、10 回目の操作後まで表示しています。)

最終的に黒く塗られたマスは 57 個です。
入力例 2
2 2 .. ..
出力例 2
0
入力例 3
10 10 .......... ....#..... #.......#. ......#... .......#.. .....#.... .......... .......... ..#...#... .......#..
出力例 3
64
Score : 425 points
Problem Statement
There is a grid with H rows and W columns. We call the cell at the i-th row from the top (1\leq i\leq H) and j-th column from the left (1\leq j\leq W) as cell (i,j).
Initially, cell (i,j) is colored black if S_{i,j} is # and white if it is ..
Perform the following operation 10^{100} times:
- Let T be the set of cells that are colored white and have exactly one adjacent cell colored black. Color each cell in T black. Here, two cells (i_1,j_1) and (i_2,j_2) are adjacent if and only if |i_1-i_2|+|j_1-j_2|=1.
Find the number of cells that are colored black after all operations are completed.
Constraints
- 2\leq H,W
- HW\leq 3\times 10^5
- 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}\ldots S_{1,W}
S_{2,1}S_{2,2}\ldots S_{2,W}
\vdots
S_{H,1}S_{H,2}\ldots S_{H,W}
Output
Output the answer.
Sample Input 1
9 9 ......... ......... ......... ......... ....#.... ......... ......... ......... .........
Sample Output 1
57
The grid changes as follows through the operations. (The number above represents the operation count. The first ten operations are displayed.)

Eventually, 57 cells are colored black.
Sample Input 2
2 2 .. ..
Sample Output 2
0
Sample Input 3
10 10 .......... ....#..... #.......#. ......#... .......#.. .....#.... .......... .......... ..#...#... .......#..
Sample Output 3
64
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 450 点
問題文
長さ 3^n \; (n \geq 1) の 01 列 B=B_1 B_2 \dots B_{3^n} に対して、長さ 3^{n-1} の 01 列 C=C_1 C_2 \dots C_{3^{n-1}} を得る操作を以下のように定めます。
- B の要素を 3 つずつまとめて多数決を取る。すなわち、i=1,2,\dots,3^{n-1} について、B_{3i-2},B_{3i-1},B_{3i} のうち最も多く現れる値を C_i とする。
長さ 3^N の 01 列 A = A_1 A_2 \dots A_{3^N} が与えられます。A に上の操作を N 回適用して得られる長さ 1 の列を A' = A'_1 とします。
A の要素のいくつかを 0 から 1 または 1 から 0 へ変えることを考えたとき、A の要素を最小で何個変えれば、A'_1 の値が変わるか求めてください。
制約
- N は 1 以上 13 以下の整数
- A は 0,1 からなる長さ 3^N の文字列
入力
入力は以下の形式で標準入力から与えられる。
N
A_1 A_2 \dots A_{3^N}
出力
答えを出力せよ。
入力例 1
2 010011101
出力例 1
1
A=010011101 に操作を 2 回適用すると、以下のようになります。
- 1 回目: 010 の過半数は 0, 011 の過半数は 1, 101 の過半数は 1 なので、これらをつなげて 011 を得る。
- 2 回目: 011 の過半数は 1 なので、 1 を得る。
最終的な値を 1 から 0 にするためには、例えば A の 5 文字目を 1 から 0 にして A=010001101 にすればよいです。変更後、操作は以下のようになります。
- 1 回目: 010 の過半数は 0, 001 の過半数は 0, 101 の過半数は 1 なので、これらをつなげて 001 を得る。
- 2 回目: 001 の過半数は 0 なので、 0 を得る。
よって、 A の要素を 1 個変えるのが最小です。
入力例 2
1 000
出力例 2
2
Score : 450 points
Problem Statement
For a binary string B = B_1 B_2 \dots B_{3^n} of length 3^n (n \geq 1), we define an operation to obtain a binary string C = C_1 C_2 \dots C_{3^{n-1}} of length 3^{n-1} as follows:
- Partition the elements of B into groups of 3 and take the majority value from each group. That is, for i=1,2,\dots,3^{n-1}, let C_i be the value that appears most frequently among B_{3i-2}, B_{3i-1}, and B_{3i}.
You are given a binary string A = A_1 A_2 \dots A_{3^N} of length 3^N. Let A' = A'_1 be the length-1 string obtained by applying the above operation N times to A.
Determine the minimum number of elements of A that must be changed (from 0 to 1 or from 1 to 0) in order to change the value of A'_1.
Constraints
- N is an integer with 1 \leq N \leq 13.
- A is a string of length 3^N consisting of 0 and 1.
Input
The input is given from Standard Input in the following format:
N
A_1 A_2 \dots A_{3^N}
Output
Print the answer.
Sample Input 1
2 010011101
Sample Output 1
1
For example, with A=010011101, after applying the operation twice, we obtain:
- First operation: The majority of 010 is 0, of 011 is 1, and of 101 is 1, resulting in 011.
- Second operation: The majority of 011 is 1, yielding 1.
To change the final value from 1 to 0, one way is to change the 5th character of A from 1 to 0, yielding A=010001101. After the change, the operations yield:
- First operation: The majority of 010 is 0, of 001 is 0, and of 101 is 1, resulting in 001.
- Second operation: The majority of 001 is 0, yielding 0.
Thus, the minimum number of changes required is 1.
Sample Input 2
1 000
Sample Output 2
2
Time Limit: 3 sec / Memory Limit: 1024 MiB
配点 : 525 点
問題文
長さ n の文字列 X に対して、X を k 回繰り返して得られる文字列を f(X,k) と表記し、X の 1 文字目、2 文字目、\dots、n 文字目を k 回ずつこの順に繰り返して得られる文字列を g(X,k) と表記します。
例えば、X= abc のとき、f(X,2)= abcabc、g(X,3)= aaabbbccc です。
また、任意の文字列 X に対して、f(X,0) と g(X,0) は共に空文字列です。
正整数 N および文字列 S,T が与えられます。 g(T,k) が f(S,N) の(連続とは限らない)部分列であるような最大の非負整数 k を求めてください。 なお、定義より、g(T,0) は常に f(S,N) の部分列であることに注意してください。
部分列とは
文字列 X の(連続とは限らない)部分列とは、X から 0 個以上の文字を取り除いた後、残りの文字を元の順序で連結して得られる文字列のことをいいます。 例えば、ac、atcoder、 (空文字列)などはどれも atcoder の部分列ですが、ta は atcoder の部分列ではありません。
制約
- N は整数
- 1\leq N\leq 10^{12}
- S, T は英小文字からなる長さ 1 以上 10^5 以下の文字列
入力
入力は以下の形式で標準入力から与えられる。
N S T
出力
g(T,k) が f(S,N) の(連続とは限らない)部分列であるような最大の非負整数 k を出力せよ。
入力例 1
3 abc ab
出力例 1
2
f(S,3)= abcabcabc です。
g(T,2)= aabb は f(S,3) の部分列ですが、g(T,3)= aaabbb は f(S,3) の部分列ではないので、2 を出力します。
入力例 2
3 abc arc
出力例 2
0
入力例 3
1000000000000 kzazkakxkk azakxk
出力例 3
344827586207
Score: 525 points
Problem Statement
For a string X of length n, let f(X,k) denote the string obtained by repeating k times the string X, and g(X,k) denote the string obtained by repeating k times the first character, the second character, \dots, the n-th character of X, in this order. For example, if X= abc, then f(X,2)= abcabc, and g(X,3)= aaabbbccc. Also, for any string X, both f(X,0) and g(X,0) are empty strings.
You are given a positive integer N and strings S and T. Find the largest non-negative integer k such that g(T,k) is a (not necessarily contiguous) subsequence of f(S,N). Note that g(T,0) is always a subsequence of f(S,N) by definition.
What is a subsequence?
A (not necessarily contiguous) subsequence of a string X is a string obtained by removing zero or more characters from X and then concatenating the remaining elements without changing the order. For example,ac, atcoder, and (empty string) are all subsequences of atcoder, but ta is not.
Constraints
- N is an integer.
- 1\leq N\leq 10^{12}
- S and T are strings consisting of lowercase English letters with lengths between 1 and 10^5, inclusive.
Input
The input is given from Standard Input in the following format:
N S T
Output
Print the largest non-negative integer k such that g(T,k) is a (not necessarily contiguous) subsequence of f(S,N).
Sample Input 1
3 abc ab
Sample Output 1
2
We have f(S,3)= abcabcabc.
g(T,2)= aabb is a subsequence of f(S,3), but g(T,3)= aaabbb is not, so print 2.
Sample Input 2
3 abc arc
Sample Output 2
0
Sample Input 3
1000000000000 kzazkakxkk azakxk
Sample Output 3
344827586207