実行時間制限: 2 sec / メモリ制限: 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
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 100 点
問題文
整数 A,B が与えられます。
以下の条件を満たす整数 x が何通りあるか求めてください。
- 条件:3 つの整数 A,B,x をうまく並べることで、等差数列を作ることができる。
なお、3 つの整数 p,q,r をこの順に並べた列が等差数列であるとは、q-p が r-q と一致することをいいます。
制約
- 1\leq A,B \leq 100
- 入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。
A B
出力
問題文中の条件を満たす整数 x が何通りあるかを出力せよ。 なお、答えは有限であることが証明できる。
入力例 1
5 7
出力例 1
3
以下のように、x=3,6,9 はいずれも条件を満たします。
- x=3 のとき、例えば x,A,B と並べることで等差数列 3,5,7 を作ることができます。
- x=6 のとき、例えば B,x,A と並べることで等差数列 7,6,5 を作ることができます。
- x=9 のとき、例えば A,B,x と並べることで等差数列 5,7,9 を作ることができます。
逆に、これ以外に条件を満たす x は存在しません。 よって答えは 3 です。
入力例 2
6 1
出力例 2
2
x=-4,11 のみが条件を満たします。
入力例 3
3 3
出力例 3
1
x=3 のみが条件を満たします。
Score : 100 points
Problem Statement
You are given two integers A and B.
How many integers x satisfy the following condition?
- Condition: It is possible to arrange the three integers A, B, and x in some order to form an arithmetic sequence.
A sequence of three integers p, q, and r in this order is an arithmetic sequence if and only if q-p is equal to r-q.
Constraints
- 1 \leq A,B \leq 100
- All input values are integers.
Input
The input is given from Standard Input in the following format:
A B
Output
Print the number of integers x that satisfy the condition in the problem statement. It can be proved that the answer is finite.
Sample Input 1
5 7
Sample Output 1
3
The integers x=3,6,9 all satisfy the condition as follows:
- When x=3, for example, arranging x,A,B forms the arithmetic sequence 3,5,7.
- When x=6, for example, arranging B,x,A forms the arithmetic sequence 7,6,5.
- When x=9, for example, arranging A,B,x forms the arithmetic sequence 5,7,9.
Conversely, there are no other values of x that satisfy the condition. Therefore, the answer is 3.
Sample Input 2
6 1
Sample Output 2
2
Only x=-4 and 11 satisfy the condition.
Sample Input 3
3 3
Sample Output 3
1
Only x=3 satisfies the condition.
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 200 点
問題文
英小文字のみからなる 2 つの文字列 S, T が与えられます。 S が T の接頭辞かどうかを判定してください。
接頭辞とは
長さ N の文字列 T_1T_2\ldots T_N の接頭辞とは、 0 \leq i \leq N を満たすある整数 i によって、T の先頭 i 文字目までの文字列 T_1T_2\ldots T_i として表される文字列です。例えば、T = abc のとき、T の接頭辞は、空文字列、a 、ab 、abc の 4 つです。制約
- S と T はそれぞれ英小文字のみからなる長さが 1 以上 100 以下の文字列
入力
入力は以下の形式で標準入力から与えられる。
S T
出力
S が T の接頭辞である場合は Yes を、そうでない場合は No を出力せよ。
ジャッジは英小文字と英大文字を厳密に区別することに注意せよ。
入力例 1
atco atcoder
出力例 1
Yes
atco は atcoder の接頭辞です。よって、Yes を出力します。
入力例 2
code atcoder
出力例 2
No
code は atcoder の接頭辞ではありません。よって、No を出力します。
入力例 3
abc abc
出力例 3
Yes
文字列全体もその文字列の接頭辞であることに注意してください。
入力例 4
aaaa aa
出力例 4
No
Score : 200 points
Problem Statement
You are given two strings S and T consisting of lowercase English letters. Determine if S is a prefix of T.
What is a prefix?
A prefix of a string T_1T_2\ldots T_N of length N is a string expressed as the first i characters of T, T_1T_2\ldots T_i, where i is an integer such that 0 \leq i \leq N. For example, when T = abc, there are four prefixes of T: an empty string, a, ab, and abc.Constraints
- S and T are strings of lengths between 1 and 100 (inclusive) consisting of lowercase English letters.
Input
Input is given from Standard Input in the following format:
S T
Output
Print Yes if S is a prefix of T; print No otherwise.
Note that the judge is case-sensitive.
Sample Input 1
atco atcoder
Sample Output 1
Yes
atco is a prefix of atcoder. Thus, Yes should be printed.
Sample Input 2
code atcoder
Sample Output 2
No
code is not a prefix of atcoder. Thus, No should be printed.
Sample Input 3
abc abc
Sample Output 3
Yes
Note that a string is also a prefix of itself.
Sample Input 4
aaaa aa
Sample Output 4
No
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 200 点
問題文
英小文字からなる文字列 S,T が与えられるので、 T が S の(連続する)部分文字列かどうか判定してください。
なお、文字列 X に以下の操作を 0 回以上施して文字列 Y が得られる時、またその時に限り Y は X の(連続する)部分文字列であると言います。
- 以下の 2 つの操作から 1 つを選択して、その操作を行う。
- X の先頭の 1 文字を削除する。
- X の末尾の 1 文字を削除する。
例えば tag は voltage の(連続する)部分文字列ですが、 ace は atcoder の(連続する)部分文字列ではありません。
制約
- S,T は英小文字からなる
- 1 \le |S|,|T| \le 100 ( |X| は文字列 X の長さ )
入力
入力は以下の形式で標準入力から与えられる。
S T
出力
T が S の(連続する)部分文字列なら Yes 、そうでないなら No と出力せよ。
入力例 1
voltage tag
出力例 1
Yes
tag は voltage の(連続する)部分文字列です。
入力例 2
atcoder ace
出力例 2
No
ace は atcoder の(連続する)部分文字列ではありません。
入力例 3
gorilla gorillagorillagorilla
出力例 3
No
入力例 4
toyotasystems toyotasystems
出力例 4
Yes
S=T である場合もあります。
Score : 200 points
Problem Statement
You are given strings S and T consisting of lowercase English letters. Determine whether T is a (contiguous) substring of S.
A string Y is said to be a (contiguous) substring of X if and only if Y can be obtained by performing the operation below on X zero or more times.
- Do one of the following.
- Delete the first character in X.
- Delete the last character in X.
For instance, tag is a (contiguous) substring of voltage, while ace is not a (contiguous) substring of atcoder.
Constraints
- S and T consist of lowercase English letters.
- 1 \le |S|,|T| \le 100 (|X| denotes the length of a string X.)
Input
The input is given from Standard Input in the following format:
S T
Output
If T is a (contiguous) substring of S, print Yes; otherwise, print No.
Sample Input 1
voltage tag
Sample Output 1
Yes
tag is a (contiguous) substring of voltage.
Sample Input 2
atcoder ace
Sample Output 2
No
ace is not a (contiguous) substring of atcoder.
Sample Input 3
gorilla gorillagorillagorilla
Sample Output 3
No
Sample Input 4
toyotasystems toyotasystems
Sample Output 4
Yes
It is possible that S=T.
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 300 点
問題文
0, 1 のみからなる長さ N の文字列 S が与えられます。
S の中で先頭から K 番目の 1 の塊を K-1 番目の 1 の塊の直後まで移動した文字列を出力してください。
なお、S には 1 の塊が K 個以上含まれることが保証されます。
より正確な説明は以下の通りです。
- S の l 文字目から r 文字目までからなる部分文字列を S_{l\ldots r} と表す。
- S の部分文字列 S_{l\ldots r} が
1の塊であるとは、以下の条件を全て満たすことと定める。- S_l=S_{l+1}=\cdots=S_r=
1 - l=1 または S_{l-1}=
0 - r=N または S_{r+1}=
0
- S_l=S_{l+1}=\cdots=S_r=
- S に含まれる
1の塊が S_{l_1\ldots r_1},\ldots,S_{l_m\ldots r_m} で全てであり、l_1 < \cdots < l_m を満たしているとする。
このとき、以下で定義される長さ N の文字列 T を、「S の中で先頭から K 番目の1の塊を K-1 番目の1の塊の直後まで移動した文字列」と定める- 1 \leq i \leq r_{K-1} のとき T_i = S_i
- r_{K-1}+1 \leq i \leq r_{K-1}+(r_K-l_K)+1 のとき T_i=
1 - r_{K-1}+(r_K-l_K)+2 \leq i \leq r_K のとき T_i=
0 - r_K+1 \leq i \leq N のとき T_i=S_i
制約
- 1 \leq N \leq 5\times 10^5
- S は
0,1のみからなる長さ N の文字列 - 2 \leq K
- S には
1の塊が K 個以上含まれる
入力
入力は以下の形式で標準入力から与えられる。
N K S
出力
答えを出力せよ。
入力例 1
15 3 010011100011001
出力例 1
010011111000001
S には、2 文字目から 2 文字目、5 文字目から 7 文字目、11 文字目から 12 文字目、15 文字目から 15 文字目の 4 つの 1 の塊があります。
入力例 2
10 2 1011111111
出力例 2
1111111110
Score : 300 points
Problem Statement
You are given a string S of length N consisting of 0 and 1.
Move the K-th 1-block from the beginning in S to immediately after the (K-1)-th 1-block, and print the resulting string.
It is guaranteed that S contains at least K 1-blocks.
Here is a more precise description.
- Let S_{l\ldots r} denote the substring of S from the l-th character through the r-th character.
- We define a substring S_{l\ldots r} of S to be a
1-block if it satisfies all of the following conditions:- S_l = S_{l+1} = \cdots = S_r =
1 - l = 1 or S_{l-1} =
0 - r = N or S_{r+1} =
0
- S_l = S_{l+1} = \cdots = S_r =
-
Suppose that all
1-blocks in S are S_{l_1\ldots r_1}, \ldots, S_{l_m\ldots r_m}, where l_1 < l_2 < \cdots < l_m.Then, we define the length N string T, obtained by moving the K-th
1-block to immediately after the (K-1)-th1-block, as follows:- T_i = S_i for 1 \leq i \leq r_{K-1}
- T_i =
1for r_{K-1} + 1 \leq i \leq r_{K-1} + (r_K - l_K) + 1 - T_i =
0for r_{K-1} + (r_K - l_K) + 2 \leq i \leq r_K - T_i = S_i for r_K + 1 \leq i \leq N
Constraints
- 1 \leq N \leq 5 \times 10^5
- S is a string of length N consisting of
0and1. - 2 \leq K
- S contains at least K
1-blocks.
Input
The input is given from Standard Input in the following format:
N K S
Output
Print the answer.
Sample Input 1
15 3 010011100011001
Sample Output 1
010011111000001
S has four 1-blocks: from the 2nd to the 2nd character, from the 5th to the 7th character, from the 11th to the 12th character, and from the 15th to the 15th character.
Sample Input 2
10 2 1011111111
Sample Output 2
1111111110