実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 200 点
問題文
xy 平面を考えます。x 軸の正の向きを東向き、y 軸の正の向きを北向きとします。
高橋君ははじめ、点 (x, y) = (0, 0) にいて東( x 軸の正の向き)を向いています。
S と R のみからなる長さ N の文字列 T = t_1t_2\ldots t_N が与えられます。
高橋君は i = 1, 2, \ldots, N の順番で下記を行います。
- t_i =
Sならば、高橋君はいま向いている方向に距離 1 だけ進む。 - t_i =
Rならば、高橋君はその場で右に 90 度回転する。その結果、高橋君の向いている方向が下記の通りに変わる。- 回転前の向きが東向き( x 軸の正の向き)ならば、回転後の向きは南向き( y 軸の負の向き)になる。
- 回転前の向きが南向き( y 軸の負の向き)ならば、回転後の向きは西向き( x 軸の負の向き)になる。
- 回転前の向きが西向き( x 軸の負の向き)ならば、回転後の向きは北向き( y 軸の正の向き)になる。
- 回転前の向きが北向き( y 軸の正の向き)ならば、回転後の向きは東向き( x 軸の正の向き)になる。
上記の手順を終えた後に高橋君がいる点の座標を出力してください。
制約
- 1 \leq N \leq 10^5
- N は整数
- T は
SとRのみからなる長さ N の文字列
入力
入力は以下の形式で標準入力から与えられる。
N T
出力
問題文中の手順を終えた後に高橋君がいる点の座標 (x, y) を、下記の形式にしたがって空白区切りで出力せよ。
x y
入力例 1
4 SSRS
出力例 1
2 -1
高橋君ははじめ (0, 0) にいて東を向いています。その後、高橋君は下記の通りに行動します。
- t_1 =
Sであるので、高橋君は東に距離 1 だけ進んだ (1, 0) に移動します。 - t_2 =
Sであるので、高橋君は東に距離 1 だけ進んだ (2, 0) に移動します。 - t_3 =
Rであるので、高橋君は右に 90 度回転し、高橋君は南を向きます。 - t_4 =
Sであるので、高橋君は南に距離 1 だけ進んだ (2, -1) に移動します。
よって、高橋君の最終的な位置である (x, y) = (2, -1) を出力します。
入力例 2
20 SRSRSSRSSSRSRRRRRSRR
出力例 2
0 1
Score : 200 points
Problem Statement
Consider an xy-plane. The positive direction of the x-axis is in the direction of east, and the positive direction of the y-axis is in the direction of north.
Takahashi is initially at point (x, y) = (0, 0) and facing east (in the positive direction of the x-axis).
You are given a string T = t_1t_2\ldots t_N of length N consisting of S and R.
Takahashi will do the following move for each i = 1, 2, \ldots, N in this order.
- If t_i =
S, Takahashi advances in the current direction by distance 1. - If t_i =
R, Takahashi turns 90 degrees clockwise without changing his position. As a result, Takahashi's direction changes as follows.- If he is facing east (in the positive direction of the x-axis) before he turns, he will face south (in the negative direction of the y-axis) after he turns.
- If he is facing south (in the negative direction of the y-axis) before he turns, he will face west (in the negative direction of the x-axis) after he turns.
- If he is facing west (in the negative direction of the x-axis) before he turns, he will face north (in the positive direction of the y-axis) after he turns.
- If he is facing north (in the positive direction of the y-axis) before he turns, he will face east (in the positive direction of the x-axis) after he turns.
Print the coordinates Takahashi is at after all the steps above have been done.
Constraints
- 1 \leq N \leq 10^5
- N is an integer.
- T is a string of length N consisting of
SandR.
Input
Input is given from Standard Input in the following format:
N T
Output
Print the coordinates (x, y) Takahashi is at after all the steps described in the Problem Statement have been completed, in the following format, with a space in between:
x y
Sample Input 1
4 SSRS
Sample Output 1
2 -1
Takahashi is initially at (0, 0) facing east. Then, he moves as follows.
- t_1 =
S, so he advances in the direction of east by distance 1, arriving at (1, 0). - t_2 =
S, so he advances in the direction of east by distance 1, arriving at (2, 0). - t_3 =
R, so he turns 90 degrees clockwise, resulting in facing south. - t_4 =
S, so he advances in the direction of south by distance 1, arriving at (2, -1).
Thus, Takahashi's final position, (x, y) = (2, -1), should be printed.
Sample Input 2
20 SRSRSSRSSSRSRRRRRSRR
Sample Output 2
0 1
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 200 点
問題文
ボウリングのピンは 1 から 10 の番号が付けられており、上から見ると下図のように配置されます。

この図の二つの点線に挟まれた部分を列と呼ぶことにします。
例えば、ピン 1, 5 とピン 3, 9 はそれぞれ同じ列に存在します。
いくつかのピンが倒れた状態のうち、特殊なものはスプリットと呼ばれます。
ピンの配置がスプリットであるとは、以下の条件が全て成り立つことを言います。
- ピン 1 が倒れている。
- ある二つの異なる列であって、次の条件を満たすものが存在する。
- それぞれの列には、立っているピンが 1 本以上存在する。
- それらの列の間に、ピンが全て倒れている列が存在する。
具体例は入出力例を参考にしてください。
さて、あるピンの配置が長さ 10 の文字列 S として与えられます。
i = 1, \dots, 10 について、ピン i が倒れているとき S の i 文字目は 0 であり、ピン i が立っているとき S の i 文字目は 1 です。
S で表されるピンの配置がスプリットかどうか判定してください。
制約
- S は
0と1からなる長さ 10 の文字列
入力
入力は以下の形式で標準入力から与えられる。
S
出力
S で表されるピンの配置がスプリットなら Yes を、そうでないなら No を出力せよ。
入力例 1
0101110101
出力例 1
Yes
倒れているピンを灰色で、立っているピンを白色で示すと下図のようになります。

ピン 5 が立っている列とピン 6 が立っている列の間にはピン 3, 9 が置かれている列が存在しますが、ピン 3, 9 はいずれも倒れているので、この配置はスプリットです。
入力例 2
0100101001
出力例 2
Yes

入力例 3
0000100110
出力例 3
No

この配置はスプリットではありません。
入力例 4
1101110101
出力例 4
No

ピン 1 が倒れていないので、スプリットではありません。
Score : 200 points
Problem Statement
Bowling pins are numbered 1 through 10. The following figure is a top view of the arrangement of the pins:

Let us call each part between two dotted lines in the figure a column.
For example, Pins 1 and 5 belong to the same column, and so do Pin 3 and 9.
When some of the pins are knocked down, a special situation called split may occur.
A placement of the pins is a split if both of the following conditions are satisfied:
- Pin 1 is knocked down.
- There are two different columns that satisfy both of the following conditions:
- Each of the columns has one or more standing pins.
- There exists a column between these columns such that all pins in the column are knocked down.
See also Sample Inputs and Outputs for examples.
Now, you are given a placement of the pins as a string S of length 10.
For i = 1, \dots, 10, the i-th character of S is 0 if Pin i is knocked down, and is 1 if it is standing.
Determine if the placement of the pins represented by S is a split.
Constraints
- S is a string of length 10 consisting of
0and1.
Input
Input is given from Standard Input in the following format:
S
Output
If the placement of the pins represented by S is a split, print Yes; otherwise, print No.
Sample Input 1
0101110101
Sample Output 1
Yes
In the figure below, the knocked-down pins are painted gray, and the standing pins are painted white:

Between the column containing a standing pin 5 and the column containing a standing pin 6 is a column containing Pins 3 and 9. Since Pins 3 and 9 are both knocked down, the placement is a split.
Sample Input 2
0100101001
Sample Output 2
Yes

Sample Input 3
0000100110
Sample Output 3
No

This placement is not a split.
Sample Input 4
1101110101
Sample Output 4
No

This is not a split because Pin 1 is not knocked down.
実行時間制限: 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 点
問題文
高橋君は英小文字からなる文字列 T を青木君に向けて送りました。その結果、青木君は英小文字からなる文字列 T' を受信しました。
T' は T から一部が変更されてしまっている可能性があり、具体的には、下記の 4 つのうちのちょうど 1 つが成り立つことがわかっています。
- T' は、T と等しい。
- T' は、T のいずれか 1 つの位置(先頭と末尾も含む)に英小文字を 1 つ挿入して得られる文字列である。
- T' は、T からある 1 文字を削除して得られる文字列である。
- T' は、T のある 1 文字を別の英小文字に変更して得られる文字列である。
青木君が受信した文字列 T' と、英小文字からなる N 個の文字列 S_1, S_2, \ldots, S_N が入力として与えられるので、 S_1, S_2, \ldots, S_N のうち、高橋君が送った文字列 T と等しい可能性があるものをすべて求めてください。
制約
- N は整数
- 1 \leq N \leq 5 \times 10^5
- S_i と T' は英小文字からなる長さ 1 以上 5 \times 10^5 以下の文字列
- S_1, S_2, \ldots, S_N の長さの総和は 5 \times 10^5 以下
入力
入力は以下の形式で標準入力から与えられる。
N T' S_1 S_2 \vdots S_N
出力
S_1, S_2, \ldots, S_N のうち T と等しい可能性があるものすべての添字を昇順に並べた列を (i_1, i_2, \ldots, i_K) とする。 この列の長さ K および列自体を、下記の形式にしたがって出力せよ。
K i_1 i_2 \ldots i_K
入力例 1
5 ababc ababc babc abacbc abdbc abbac
出力例 1
4 1 2 3 4
S_1, S_2, \ldots, S_5 のうち、T と等しい可能性があるものは S_1, S_2, S_3, S_4 の 4 つであることが下記の通りわかります。
- S_1 は T と等しい可能性があります。なぜなら、T' =
ababcは S_1 =ababcと等しいからです。 - S_2 は T と等しい可能性があります。なぜなら、T' =
ababcは S_2 =babcの先頭に文字aを挿入して得られる文字列だからです。 - S_3 は T と等しい可能性があります。なぜなら、T' =
ababcは S_3 =abacbcから 4 文字目のcを削除して得られる文字列だからです。 - S_4 は T と等しい可能性があります。なぜなら、T' =
ababcは S_4 =abdbcの 3 文字目のdをbに変更して得られる文字列だからです。 - S_5 は T と等しい可能性はありません。なぜなら、S_5 =
abbacを T としたとき、T' =ababcは問題文中の 4 つの条件をいずれも満たさないからです。
入力例 2
1 aoki takahashi
出力例 2
0
入力例 3
9 atcoder atoder atcode athqcoder atcoder tacoder jttcoder atoder atceoder atcoer
出力例 3
6 1 2 4 7 8 9
Score : 300 points
Problem Statement
Takahashi sent a string T consisting of lowercase English letters to Aoki. As a result, Aoki received a string T' consisting of lowercase English letters.
T' may have been altered from T. Specifically, exactly one of the following four conditions is known to hold.
- T' is equal to T.
- T' is a string obtained by inserting one lowercase English letter at one position (possibly the beginning and end) in T.
- T' is a string obtained by deleting one character from T.
- T' is a string obtained by changing one character in T to another lowercase English letter.
You are given the string T' received by Aoki and N strings S_1, S_2, \ldots, S_N consisting of lowercase English letters. Find all the strings among S_1, S_2, \ldots, S_N that could equal the string T sent by Takahashi.
Constraints
- N is an integer.
- 1 \leq N \leq 5 \times 10^5
- S_i and T' are strings of length between 1 and 5 \times 10^5, inclusive, consisting of lowercase English letters.
- The total length of S_1, S_2, \ldots, S_N is at most 5 \times 10^5.
Input
The input is given from Standard Input in the following format:
N T' S_1 S_2 \vdots S_N
Output
Let (i_1, i_2, \ldots, i_K) be the sequence of indices of all the strings among S_1, S_2, \ldots, S_N that could be equal to T, in ascending order. Print the length K of this sequence, and the sequence itself, in the following format:
K i_1 i_2 \ldots i_K
Sample Input 1
5 ababc ababc babc abacbc abdbc abbac
Sample Output 1
4 1 2 3 4
Among S_1, S_2, \ldots, S_5, the strings that could be equal to T are S_1, S_2, S_3, S_4, as explained below.
- S_1 could be equal to T, because T' =
ababcis equal to S_1 =ababc. - S_2 could be equal to T, because T' =
ababcis obtained by inserting the letteraat the beginning of S_2 =babc. - S_3 could be equal to T, because T' =
ababcis obtained by deleting the fourth charactercfrom S_3 =abacbc. - S_4 could be equal to T, because T' =
ababcis obtained by changing the third characterdin S_4 =abdbctob. - S_5 could not be equal to T, because if we take S_5 =
abbacas T, then T' =ababcdoes not satisfy any of the four conditions in the problem statement.
Sample Input 2
1 aoki takahashi
Sample Output 2
0
Sample Input 3
9 atcoder atoder atcode athqcoder atcoder tacoder jttcoder atoder atceoder atcoer
Sample Output 3
6 1 2 4 7 8 9
実行時間制限: 2.5 sec / メモリ制限: 1024 MiB
配点 : 400 点
問題文
座標平面上に 1 から N の番号がついた N 人の人がいます。
人 1 は原点にいます。
次の形式の情報が M 個与えられます。
- 人 A_i から見て、人 B_i は、x 軸正方向に X_i、y 軸正方向に Y_i 離れた位置にいる
それぞれの人がいる座標を求めてください。一意に定まらないときはそのことを報告してください。
制約
- 1 \leq N \leq 2\times 10^5
- 0 \leq M \leq 2\times 10^5
- 1\leq A_i, B_i \leq N
- A_i \neq B_i
- -10^9 \leq X_i,Y_i \leq 10^9
- 入力は全て整数である
- 与えられる情報は矛盾しない
入力
入力は以下の形式で標準入力から与えられる。
N M A_1 B_1 X_1 Y_1 \vdots A_M B_M X_M Y_M
出力
N 行出力せよ。
人 i のいる座標が一意に定まらないとき、i 行目には undecidable と出力せよ。
人 i のいる座標が (s_i,t_i) と一意に定まるとき、i 行目には s_i,t_i をこの順に空白区切りで出力せよ。
入力例 1
3 2 1 2 2 1 1 3 -1 -2
出力例 1
0 0 2 1 -1 -2
3 人の位置関係は下図のようになっています。

入力例 2
3 2 2 1 -2 -1 2 3 -3 -3
出力例 2
0 0 2 1 -1 -2
3 人の位置関係は下図のようになっています。

入力例 3
5 7 1 2 0 0 1 2 0 0 2 3 0 0 3 1 0 0 2 1 0 0 3 2 0 0 4 5 0 0
出力例 3
0 0 0 0 0 0 undecidable undecidable
同じ情報が複数回与えられたり、同じ座標に複数の人がいることもあります。
Score : 400 points
Problem Statement
There are N people numbered 1 to N on a coordinate plane.
Person 1 is at the origin.
You are given M pieces of information in the following form:
- From person A_i's perspective, person B_i is X_i units away in the positive x-direction and Y_i units away in the positive y-direction.
Determine the coordinates of each person. If the coordinates of a person cannot be uniquely determined, report that fact.
Constraints
- 1 \leq N \leq 2\times 10^5
- 0 \leq M \leq 2\times 10^5
- 1\leq A_i, B_i \leq N
- A_i \neq B_i
- -10^9 \leq X_i,Y_i \leq 10^9
- All input values are integers.
- The given information is consistent.
Input
The input is given from Standard Input in the following format:
N M A_1 B_1 X_1 Y_1 \vdots A_M B_M X_M Y_M
Output
Print N lines.
If the coordinates of person i cannot be uniquely determined, the i-th line should contain undecidable.
If they can be uniquely determined as (s_i,t_i), the i-th line should contain s_i and t_i in this order, separated by a space.
Sample Input 1
3 2 1 2 2 1 1 3 -1 -2
Sample Output 1
0 0 2 1 -1 -2
The figure below shows the positional relationship of the three people.

Sample Input 2
3 2 2 1 -2 -1 2 3 -3 -3
Sample Output 2
0 0 2 1 -1 -2
The figure below shows the positional relationship of the three people.

Sample Input 3
5 7 1 2 0 0 1 2 0 0 2 3 0 0 3 1 0 0 2 1 0 0 3 2 0 0 4 5 0 0
Sample Output 3
0 0 0 0 0 0 undecidable undecidable
The same piece of information may be given multiple times, and multiple people may be at the same coordinates.