実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 100 点
問題文
N 個の座席が並んでおり、座席には 1, 2, \ldots, N の番号が付けられています。
座席の状態は #, . からなる長さ N の文字列 S によって与えられます。S の i 文字目が # のとき座席 i には人が座っていることを表し、S の i 文字目が . のとき座席 i には人が座っていないことを表します。
1 以上 N - 2 以下の整数 i であって、以下の条件を満たすものの個数を求めてください。
- 座席 i, i + 2 には人が座っており、座席 i + 1 には人が座っていない
制約
- N は 1 以上 2 \times 10^5 以下の整数
- S は
#,.からなる長さ N の文字列
入力
入力は以下の形式で標準入力から与えられる。
N S
出力
答えを出力せよ。
入力例 1
6 #.##.#
出力例 1
2
i = 1, 4 が条件を満たすので、答えは 2 です。
入力例 2
1 #
出力例 2
0
入力例 3
9 ##.#.#.##
出力例 3
3
Score : 100 points
Problem Statement
There are N seats in a row, numbered 1, 2, \ldots, N.
The state of the seats is given by a string S of length N consisting of # and .. If the i-th character of S is #, it means seat i is occupied; if it is ., seat i is unoccupied.
Find the number of integers i between 1 and N - 2, inclusive, that satisfy the following condition:
- Seats i and i + 2 are occupied, and seat i + 1 is unoccupied.
Constraints
- N is an integer satisfying 1 \leq N \leq 2 \times 10^5.
- S is a string of length N consisting of
#and..
Input
The input is given from Standard Input in the following format:
N S
Output
Print the answer.
Sample Input 1
6 #.##.#
Sample Output 1
2
i = 1 and 4 satisfy the condition, so the answer is 2.
Sample Input 2
1 #
Sample Output 2
0
Sample Input 3
9 ##.#.#.##
Sample Output 3
3
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 150 点
問題文
AtCoder 王国の住民は A 時になるとたこ焼きへの愛を叫ぶことになっています。
AtCoder 王国に住む高橋君は毎日 B 時に就寝し C 時に起床します。高橋君は、起きているときはたこ焼きへの愛を叫ぶことができ、寝ているときは叫ぶことができません。高橋君が毎日たこ焼きへの愛を叫ぶことができているか判定してください。ただし、一日は 24 時間であり、高橋君が寝ている時間は 24 時間未満であるとします。
制約
- 0\leq A,B,C\lt 24
- A,B,C は相異なる
- 入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。
A B C
出力
高橋君が毎日たこ焼きへの愛を叫ぶことができているならば Yes を、そうでないならば No を出力せよ。
入力例 1
21 8 14
出力例 1
Yes
高橋君は毎日 8 時に就寝し 14 時に起床します。21 時には起きているため、高橋君は毎日たこ焼きへの愛を叫ぶことができます。よって Yes を出力します。
入力例 2
0 21 7
出力例 2
No
高橋君は毎日 21 時に就寝し 7 時に起床します。0 時には起きていないため、高橋君は毎日たこ焼きへの愛を叫ぶことができません。よって No を出力します。
入力例 3
10 7 17
出力例 3
No
Score : 150 points
Problem Statement
In the Kingdom of AtCoder, residents are required to shout their love for takoyaki at A o'clock every day.
Takahashi, who lives in the Kingdom of AtCoder, goes to bed at B o'clock and wakes up at C o'clock every day (in the 24-hour clock). He can shout his love for takoyaki when he is awake, but cannot when he is asleep. Determine whether he can shout his love for takoyaki every day. Here, a day has 24 hours, and his sleeping time is less than 24 hours.
Constraints
- 0\leq A,B,C\lt 24
- A, B, and C are pairwise different.
- All input values are integers.
Input
The input is given from Standard Input in the following format:
A B C
Output
Print Yes if Takahashi can shout his love for takoyaki every day, and No otherwise.
Sample Input 1
21 8 14
Sample Output 1
Yes
Takahashi goes to bed at 8 o'clock and wakes up at 14 o'clock every day. He is awake at 21 o'clock, so he can shout his love for takoyaki every day. Therefore, print Yes.
Sample Input 2
0 21 7
Sample Output 2
No
Takahashi goes to bed at 21 o'clock and wakes up at 7 o'clock every day. He is not awake at 0 o'clock, so he cannot shout his love for takoyaki every day. Therefore, print No.
Sample Input 3
10 7 17
Sample Output 3
No
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 200 点
問題文
AtCoder Land では時報がモールス信号で行なわれます。高橋君はこのモールス信号を解読したいです。
N 個の文字列 S_1, S_2, \ldots, S_N が与えられます。S_i (1 \leq i \leq N) は . と - からなる文字列で、0 以上 9 以下のある数字に対応するモールス符号です。N 個の文字列を復号し、順に連結して 1 つの文字列として出力してください。
数字とモールス符号の対応は以下の通りです。
0 ----- 1 .---- 2 ..--- 3 ...-- 4 ....- 5 ..... 6 -.... 7 --... 8 ---.. 9 ----.
制約
- 1 \leq N \leq 100
- N は整数
- S_i (1 \leq i \leq N) は
.と-からなる文字列 - S_i (1 \leq i \leq N) は 0 以上 9 以下のある数字に対応するモールス符号
入力
入力は以下の形式で標準入力から与えられる。
N S_1 S_2 \vdots S_N
出力
N 個の文字列を復号し、順に連結して 1 つの文字列として出力してください。
入力例 1
3 ...-- ..... ---..
出力例 1
358
...-- は 3 と、..... は 5 と、---.. は 8 と復号されます。よって、358 を出力します。
入力例 2
10 ----- .---- ..--- ...-- ....- ..... -.... --... ---.. ----.
出力例 2
0123456789
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 200 点
問題文
長さ N の数列 A=(A_1,A_2,\dots,A_N) と、長さ M の数列 B=(B_1,B_2,\dots,B_M) が与えられます。ここで、A,B のすべての要素は互いに相異なります。A,B のすべての要素を昇順に並べた長さ N+M の数列 C=(C_1,C_2,\dots,C_{N+M}) において、A に現れる要素が2つ連続するかどうか判定してください。
制約
- 1\leq N,M \leq 100
- 1\leq A_i,B_j \leq 200
- A_1, A_2, \dots, A_N, B_1, B_2, \dots, B_M は相異なる
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N M A_1 A_2 \dots A_N B_1 B_2 \dots B_M
出力
A に現れる要素が C において2つ連続するならば Yes を、そうでないなら No を出力せよ。
入力例 1
3 2 3 2 5 4 1
出力例 1
Yes
C=(1,2,3,4,5) です。A に現れる 2,3 が C で連続しているため、Yes を出力します。
入力例 2
3 2 3 1 5 4 2
出力例 2
No
C=(1,2,3,4,5) です。A に現れる要素が C で連続している箇所はないため、No を出力します。
入力例 3
1 1 1 2
出力例 3
No
Score : 200 points
Problem Statement
You are given a sequence A=(A_1,A_2,\dots,A_N) of length N and a sequence B=(B_1,B_2,\dots,B_M) of length M. Here, all elements of A and B are pairwise distinct. Determine whether the sequence C=(C_1,C_2,\dots,C_{N+M}) formed by sorting all elements of A and B in ascending order contains two consecutive elements appearing in A.
Constraints
- 1 \leq N, M \leq 100
- 1 \leq A_i, B_j \leq 200
- A_1, A_2, \dots, A_N, B_1, B_2, \dots, B_M are distinct.
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N M A_1 A_2 \dots A_N B_1 B_2 \dots B_M
Output
If C contains two consecutive elements appearing in A, print Yes; otherwise, print No.
Sample Input 1
3 2 3 2 5 4 1
Sample Output 1
Yes
C=(1,2,3,4,5). Since 2 and 3 from A occur consecutively in C, print Yes.
Sample Input 2
3 2 3 1 5 4 2
Sample Output 2
No
C=(1,2,3,4,5). Since no two elements from A occur consecutively in C, print No.
Sample Input 3
1 1 1 2
Sample Output 3
No
実行時間制限: 2 sec / メモリ制限: 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.
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 300 点
問題文
二次元平面上に高橋君がいます。高橋君は原点から移動を N 回行いました。
N 回の移動は長さ N の文字列で表され、意味は次の通りです。
- i 回目の高橋君の移動後の座標は、移動前の座標を (x,y) として、
- S の i 文字目が
Rであるとき (x+1,y) - S の i 文字目が
Lであるとき (x-1,y) - S の i 文字目が
Uであるとき (x,y+1) - S の i 文字目が
Dであるとき (x,y-1)
- S の i 文字目が
N 回の移動 (始点と終点を含む) で、高橋君が同じ座標にいたことがあるかどうかを判定してください。
制約
- 1 \leq N \leq 2\times 10^5
- N は整数
- S は
R,L,U,Dのみからなる長さ N の文字列
入力
入力は以下の形式で標準入力から与えられる。
N S
出力
N 回の移動 (始点と終点を含む) で、高橋君が同じ座標にいたことがあれば Yes、なければ No と出力せよ。
入力例 1
5 RLURU
出力例 1
Yes
高橋君のいる座標は (0,0)\to (1,0)\to (0,0)\to (0,1)\to (1,1)\to (1,2) と変化します。
入力例 2
20 URDDLLUUURRRDDDDLLLL
出力例 2
No
Score : 300 points
Problem Statement
Takahashi is on a two-dimensional plane. Starting from the origin, he made N moves.
The N moves are represented by a string of length N as described below:
-
Takahashi's coordinates after the i-th move are:
- (x+1,y) if the i-th character of S is
R; - (x-1,y) if the i-th character of S is
L; - (x,y+1) if the i-th character of S is
U; and - (x,y-1) if the i-th character of S is
D,
where (x,y) is his coordinates before the move.
- (x+1,y) if the i-th character of S is
Determine if Takahashi visited the same coordinates multiple times in the course of the N moves (including the starting and ending points).
Constraints
- 1 \leq N \leq 2\times 10^5
- N is an integer.
- S is a string of length N consisting of
R,L,U, andD.
Input
The input is given from Standard Input in the following format:
N S
Output
Print Yes if Takahashi visited the same coordinates multiple times in the course of the N moves; print No otherwise.
Sample Input 1
5 RLURU
Sample Output 1
Yes
Takahashi's coordinates change as follows: (0,0)\to (1,0)\to (0,0)\to (0,1)\to (1,1)\to (1,2).
Sample Input 2
20 URDDLLUUURRRDDDDLLLL
Sample Output 2
No
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 400 点
問題文
A, B, C のみからなる文字列 S が与えられます。
S^{(0)}:=S とし、i=1,2,3,\ldots について S^{(i)} を S^{(i-1)} の各文字を A → BC, B → CA, C → AB と同時に置き換えたものと定義します。
以下の Q 個のクエリに答えてください。i 個目のクエリの内容は以下の通りです。
- S^{(t_i)} の先頭から k_i 文字目を出力せよ。
制約
- S は
A,B,Cのみからなる長さ 1 以上 10^5 以下の文字列 - 1 \leq Q \leq 10^5
- 0 \leq t_i \leq 10^{18}
- 1 \leq k_i \leq \min(10^{18},\ S^{(t_i)} の長さ)
- Q, t_i, k_i は整数
入力
入力は以下の形式で標準入力から与えられる。
S
Q
t_1 k_1
t_2 k_2
\hspace{0.4cm}\vdots
t_Q k_Q
出力
Q 個のクエリを添字の昇順に、すなわち与えられる順に処理し、出力ごとに改行せよ。
入力例 1
ABC 4 0 1 1 1 1 3 1 6
出力例 1
A B C B
S^{(0)}=ABC, S^{(1)}=BCCAAB です。
よって各クエリへの答えは順に A, B, C, B となります。
入力例 2
CBBAACCCCC 5 57530144230160008 659279164847814847 29622990657296329 861239705300265164 509705228051901259 994708708957785197 176678501072691541 655134104344481648 827291290937314275 407121144297426665
出力例 2
A A C A A
Score : 400 points
Problem Statement
You are given a string S consisting of A, B, C.
Let S^{(0)}:=S. For i=1,2,3,\ldots, let S^{(i)} be the result of simultaneously replacing the characters of S^{(i-1)} as follows: A → BC, B → CA, C → AB.
Answer Q queries. The i-th query is as follows.
- Print the k_i-th character from the beginning of S^{(t_i)}.
Constraints
- S is a string of length between 1 and 10^5 (inclusive) consisting of
A,B,C. - 1 \leq Q \leq 10^5
- 0 \leq t_i \leq 10^{18}
- 1 \leq k_i \leq \min(10^{18}, the length of S^{(t_i)})
- Q, t_i, k_i are integers.
Input
Input is given from Standard Input in the following format:
S
Q
t_1 k_1
t_2 k_2
\hspace{0.4cm}\vdots
t_Q k_Q
Output
Process the Q queries in ascending order of index, that is, in the given order. Each answer should be followed by a newline.
Sample Input 1
ABC 4 0 1 1 1 1 3 1 6
Sample Output 1
A B C B
We have S^{(0)}=ABC, S^{(1)}=BCCAAB.
Thus, the answers to the queries are A, B, C, B in the given order.
Sample Input 2
CBBAACCCCC 5 57530144230160008 659279164847814847 29622990657296329 861239705300265164 509705228051901259 994708708957785197 176678501072691541 655134104344481648 827291290937314275 407121144297426665
Sample Output 2
A A C A A
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 500 点
問題文
円周上に 2N 個の点が等間隔に並んでおり、ある点から始めて時計回りに 1 から 2N までの番号が付けられています。
円周上にはさらに N 個の弦があり、i 個目の弦は点 A_i と点 B_i を結んでいます。 ここで、A_1,\dots,A_N,B_1,\dots,B_N は全て相異なることが保証されます。
弦どうしの交点が存在するかどうか判定してください。
制約
- 2\leq N \leq 2\times 10^5
- 1\leq A_i,B_i \leq 2N
- A_1,\dots,A_N,B_1,\dots,B_N は全て相異なる
- 入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N A_1 B_1 A_2 B_2 \vdots A_N B_N
出力
弦どうしの交点が存在するならば Yes を、存在しないならば No を出力せよ。
入力例 1
3 1 3 4 2 5 6
出力例 1
Yes

図のように、弦 1(点 1 と点 3 を結ぶ線分)と弦 2(点 4 と点 2 を結ぶ線分)が交点を持つので、Yes を出力します。
入力例 2
3 6 1 4 3 2 5
出力例 2
No

図のように、弦どうしの交点は存在しないので、No を出力します。
入力例 3
4 2 4 3 7 8 6 5 1
出力例 3
Yes
Score: 500 points
Problem Statement
There are 2N points placed at equal intervals on a circle, numbered 1 to 2N in a clockwise direction starting from a certain point.
There are also N chords on the circle, with the i-th chord connecting points A_i and B_i. It is guaranteed that all the values A_1,\dots,A_N,B_1,\dots,B_N are distinct.
Determine whether there is an intersection between the chords.
Constraints
- 2\leq N \leq 2\times 10^5
- 1\leq A_i,B_i \leq 2N
- A_1,\dots,A_N,B_1,\dots,B_N are all distinct
- All input values are integers
Input
The input is given from Standard Input in the following format:
N A_1 B_1 A_2 B_2 \vdots A_N B_N
Output
If there is an intersection between the chords, print Yes; otherwise, print No.
Sample Input 1
3 1 3 4 2 5 6
Sample Output 1
Yes

As shown in the figure, chord 1 (the line segment connecting points 1 and 3) and chord 2 (the line segment connecting points 4 and 2) intersect, so print Yes.
Sample Input 2
3 6 1 4 3 2 5
Sample Output 2
No

As shown in the figure, there is no intersection between the chords, so print No.
Sample Input 3
4 2 4 3 7 8 6 5 1
Sample Output 3
Yes
実行時間制限: 2.5 sec / メモリ制限: 1024 MiB
配点 : 525 点
問題文
一列に並んだ N 個のマス 1,2,\dots,N と長さ N の数列 A=(A_1,A_2,\dots,A_N) があります。
最初、マス 1 は黒く、他の N-1 個のマスは白く塗られており、 1 つのコマがマス 1 に置かれています。
以下の操作を 0 回以上好きな回数繰り返します。
- コマがマス i にあるとき、ある正整数 x を決めてコマをマス i + A_i \times x に移動させる。
- 但し、 i + A_i \times x > N となるような移動はできません。
- その後、マス i + A_i \times x を黒く塗る。
操作を終えた時点で黒く塗られたマスの集合として考えられるものの数を 998244353 で割った余りを求めてください。
制約
- 入力は全て整数
- 1 \le N \le 2 \times 10^5
- 1 \le A_i \le 2 \times 10^5
入力
入力は以下の形式で標準入力から与えられる。
N A_1 A_2 \dots A_N
出力
答えを整数として出力せよ。
入力例 1
5 1 2 3 1 1
出力例 1
8
黒く塗られたマスの集合として考えられるものは以下の 8 通りです。
- マス 1
- マス 1,2
- マス 1,2,4
- マス 1,2,4,5
- マス 1,3
- マス 1,4
- マス 1,4,5
- マス 1,5
入力例 2
1 200000
出力例 2
1
入力例 3
40 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
出力例 3
721419738
998244353 で割った余りを求めることに注意してください。
Score : 525 points
Problem Statement
There is a row of N squares labeled 1,2,\dots,N and a sequence A=(A_1,A_2,\dots,A_N) of length N.
Initially, square 1 is painted black, the other N-1 squares are painted white, and a piece is placed on square 1.
You may repeat the following operation any number of times, possibly zero:
- When the piece is on square i, choose a positive integer x and move the piece to square i + A_i \times x.
- Here, you cannot make a move with i + A_i \times x > N.
- Then, paint the square i + A_i \times x black.
Find the number of possible sets of squares that can be painted black at the end of the operations, modulo 998244353.
Constraints
- All input values are integers.
- 1 \le N \le 2 \times 10^5
- 1 \le A_i \le 2 \times 10^5
Input
The input is given from Standard Input in the following format:
N A_1 A_2 \dots A_N
Output
Print the answer as an integer.
Sample Input 1
5 1 2 3 1 1
Sample Output 1
8
There are eight possible sets of squares painted black:
- Square 1
- Squares 1,2
- Squares 1,2,4
- Squares 1,2,4,5
- Squares 1,3
- Squares 1,4
- Squares 1,4,5
- Squares 1,5
Sample Input 2
1 200000
Sample Output 2
1
Sample Input 3
40 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Sample Output 3
721419738
Be sure to find the number modulo 998244353.