Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 150 点
問題文
N 頂点の単純無向グラフ G があり、グラフの頂点には 1,2,\ldots, N の番号が付けられています。
G の隣接行列 (A_{i,j}) が与えられます。すなわち、G は A_{i,j} = 1 であるとき、またそのときに限り頂点 i と頂点 j を結ぶ辺を持ちます。
i = 1, 2, \ldots, N について、頂点 i と直接結ばれている頂点の番号を昇順に出力してください。
ただし、頂点 i と頂点 j が直接結ばれているとは、頂点 i と頂点 j を結ぶ辺が存在することをいいます。
制約
- 2 \leq N \leq 100
- A_{i,j} \in \lbrace 0,1 \rbrace
- A_{i,i} = 0
- A_{i,j} = A_{j,i}
- 入力される値はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N A_{1,1} A_{1,2} \ldots A_{1,N} A_{2,1} A_{2,2} \ldots A_{2,N} \vdots A_{N,1} A_{N,2} \ldots A_{N,N}
出力
N 行出力せよ。 i 行目には頂点 i と直接結ばれている頂点の番号を昇順に空白区切りで出力せよ。
入力例 1
4 0 1 1 0 1 0 0 1 1 0 0 0 0 1 0 0
出力例 1
2 3 1 4 1 2
頂点 1 と直接結ばれている頂点は頂点 2, 3 です。したがって、1 行目には 2, 3 をこの順で出力します。
同様に、2 行目には 1, 4 をこの順に、3 行目には 1 を、4 行目には 2 を出力します。
入力例 2
2 0 0 0 0
出力例 2
G に辺が存在しないこともあります。
入力例 3
5 0 1 0 1 1 1 0 0 1 0 0 0 0 0 1 1 1 0 0 1 1 0 1 1 0
出力例 3
2 4 5 1 4 5 1 2 5 1 3 4
Score: 150 points
Problem Statement
There is a simple undirected graph G with N vertices labeled with numbers 1, 2, \ldots, N.
You are given the adjacency matrix (A_{i,j}) of G. That is, G has an edge connecting vertices i and j if and only if A_{i,j} = 1.
For each i = 1, 2, \ldots, N, print the numbers of the vertices directly connected to vertex i in ascending order.
Here, vertices i and j are said to be directly connected if and only if there is an edge connecting vertices i and j.
Constraints
- 2 \leq N \leq 100
- A_{i,j} \in \lbrace 0,1 \rbrace
- A_{i,i} = 0
- A_{i,j} = A_{j,i}
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N A_{1,1} A_{1,2} \ldots A_{1,N} A_{2,1} A_{2,2} \ldots A_{2,N} \vdots A_{N,1} A_{N,2} \ldots A_{N,N}
Output
Print N lines. The i-th line should contain the numbers of the vertices directly connected to vertex i in ascending order, separated by a space.
Sample Input 1
4 0 1 1 0 1 0 0 1 1 0 0 0 0 1 0 0
Sample Output 1
2 3 1 4 1 2
Vertex 1 is directly connected to vertices 2 and 3. Thus, the first line should contain 2 and 3 in this order.
Similarly, the second line should contain 1 and 4 in this order, the third line should contain 1, and the fourth line should contain 2.
Sample Input 2
2 0 0 0 0
Sample Output 2
G may have no edges.
Sample Input 3
5 0 1 0 1 1 1 0 0 1 0 0 0 0 0 1 1 1 0 0 1 1 0 1 1 0
Sample Output 3
2 4 5 1 4 5 1 2 5 1 3 4
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
英大文字および数字からなる 2 文字の文字列が N 個与えられます。i 個目の文字列は S_i です。
以下の 3 つの条件をすべて満たすか判定してください。
・すべての文字列に対して、1 文字目は H
, D
, C
, S
のどれかである。
・すべての文字列に対して、2 文字目は A
, 2
, 3
, 4
, 5
, 6
, 7
, 8
, 9
, T
, J
, Q
, K
のどれかである。
・すべての文字列は相異なる。つまり、i \neq j ならば S_i \neq S_j である。
制約
- 1 \leq N \leq 52
- S_i は英大文字および数字からなる 2 文字の文字列
入力
入力は以下の形式で標準入力から与えられる。
N S_1 S_2 \vdots S_N
出力
3 つの条件をすべて満たす場合は Yes
、そうでない場合は No
を出力せよ。
入力例 1
4 H3 DA D3 SK
出力例 1
Yes
このとき 3 つの条件をすべて満たすことが確認できます。
入力例 2
5 H3 DA CK H3 S7
出力例 2
No
S_1 と S_4 がともに H3
となってしまっているため、3 番目の条件に反します。
入力例 3
4 3H AD 3D KS
出力例 3
No
入力例 4
5 00 AA XX YY ZZ
出力例 4
No
Score : 200 points
Problem Statement
You are given N strings, each of length 2, consisting of uppercase English letters and digits. The i-th string is S_i.
Determine whether the following three conditions are all satisfied.
・For every string, the first character is one of H
, D
, C
, and S
.
・For every string, the second character is one of A
, 2
, 3
, 4
, 5
, 6
, 7
, 8
, 9
, T
, J
, Q
, K
.
・All strings are pairwise different. That is, if i \neq j, then S_i \neq S_j.
Constraints
- 1 \leq N \leq 52
- S_i is a string of length 2 consisting of uppercase English letters and digits.
Input
The input is given from Standard Input in the following format:
N S_1 S_2 \vdots S_N
Output
If the three conditions are all satisfied, print Yes
; otherwise, print No
.
Sample Input 1
4 H3 DA D3 SK
Sample Output 1
Yes
One can verify that the three conditions are all satisfied.
Sample Input 2
5 H3 DA CK H3 S7
Sample Output 2
No
Both S_1 and S_4 are H3
, violating the third condition.
Sample Input 3
4 3H AD 3D KS
Sample Output 3
No
Sample Input 4
5 00 AA XX YY ZZ
Sample Output 4
No
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
高橋君は武術家です。 武術家の覚えられる技は N 個あり、技 1, 2, \ldots, N と名前がついています。 1 \leq i \leq N について、技 i を習得するには時間 T_i の修練が必要で、 さらに、修練の開始時点で技 A_{i,1}, A_{i,2}, \ldots, A_{i,K_i} をすでに習得している必要があります。 ここで、1 \leq j \leq K_i について、A_{i,j} < i であることが保証されます。
高橋君は時刻 0 の時点で技を 1 つも覚えていません。 高橋君は同時に 1 つの技に対する修練しかできず、また、一度始めた修練を途中でやめることもできません。 高橋君が技 N を習得するのに必要な時間の最小値を求めてください。
制約
- 1 \leq N \leq 2\times 10^5
- 1 \leq T_i \leq 10^9
- 0 \leq K_i < i
- 1 \leq A_{i,j} < i
- \sum_{i=1}^N K_i \leq 2\times 10^5
- A_{i,1}, A_{i,2}, \ldots, A_{i,K_i} はすべて異なる。
- 入力は全て整数である。
入力
入力は以下の形式で標準入力から与えられる。
N T_1 K_1 A_{1,1} A_{1,2} \ldots A_{1,K_1} T_2 K_2 A_{2,1} A_{2,2} \ldots A_{2,K_2} \vdots T_N K_N A_{N,1} A_{N,2} \ldots A_{N,K_N}
出力
技 N を習得するのに必要な時間の最小値を出力せよ。
入力例 1
3 3 0 5 1 1 7 1 1
出力例 1
10
例えば高橋君は次のように行動することができます。
- 高橋君は時刻 0 に技 1 の修練を開始し、時刻 3 に技 1 を習得します。
- その後、時刻 3 に技 3 の修練を開始し、時刻 10 に技 3 を習得します。
このときが最短で、高橋君が技 3 を習得するのに必要な時間は 3+7=10 となります。 技 3 の習得のためには、技 2 を習得する必要はありません。
入力例 2
5 1000000000 0 1000000000 0 1000000000 0 1000000000 0 1000000000 4 1 2 3 4
出力例 2
5000000000
答えが 32 bit 整数に収まらないことがある事に注意してください。
Score : 300 points
Problem Statement
Takahashi is a martial artist. There are N moves that a martial artist can learn, called Move 1, 2, \ldots, N. For each 1 \leq i \leq N, it takes T_i minutes of practice to learn Move i. Additionally, at the beginning of that practice, all of the Moves A_{i,1}, A_{i,2}, \ldots, A_{i,K_i} must be already learned. Here, it is guaranteed that A_{i,j} < i for each 1 \leq j \leq K_i.
Takahashi has not learned any move at time 0. He cannot practice for more than one move simultaneously, nor can he stop a practice he has already started. Find the minimum number of minutes needed for Takahashi to learn Move N.
Constraints
- 1 \leq N \leq 2\times 10^5
- 1 \leq T_i \leq 10^9
- 0 \leq K_i < i
- 1 \leq A_{i,j} < i
- \sum_{i=1}^N K_i \leq 2\times 10^5
- A_{i,1}, A_{i,2}, \ldots, A_{i,K_i} are all distinct.
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N T_1 K_1 A_{1,1} A_{1,2} \ldots A_{1,K_1} T_2 K_2 A_{2,1} A_{2,2} \ldots A_{2,K_2} \vdots T_N K_N A_{N,1} A_{N,2} \ldots A_{N,K_N}
Output
Print the minimum number of minutes needed for Takahashi to learn Move N.
Sample Input 1
3 3 0 5 1 1 7 1 1
Sample Output 1
10
Here is one possible plan for Takahashi.
- At time 0, start practicing for Move 1 to learn Move 1 at time 3.
- Then, at time 3, start practicing for Move 3 to learn Move 3 at time 10.
Here, Takahashi spends 3+7=10 minutes to learn Move 3, which is the fastest possible. Note that he does not need to learn Move 2 to learn Move 3.
Sample Input 2
5 1000000000 0 1000000000 0 1000000000 0 1000000000 0 1000000000 4 1 2 3 4
Sample Output 2
5000000000
Note that the answer may not fit into a 32-bit integer.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
回転テーブルの周りに人 0、人 1、\ldots、人 N-1 がこの順番で反時計回りに等間隔で並んでいます。また、人 i の目の前には料理 p_i が置かれています。
あなたは次の操作を 0 回以上何度でも行うことが出来ます。
- 回転テーブルを反時計回りに 1 周の \frac{1}{N} だけ回す。これによって、(この操作の直前に)人 i の目の前にあった料理は人 (i+1) \bmod N の目の前に移動する。
操作を完了させた後において、人 i は料理 i が人 (i-1) \bmod N、人 i、人 (i+1) \bmod N のいずれかの目の前に置かれていると喜びます。
喜ぶ人数の最大値を求めてください。
a \bmod m とは
整数 a と正整数 m に対し、a \bmod m は a-x が m の倍数となるような 0 以上 m 未満の整数 x を表します。(このような x は一意に定まることが証明できます)制約
- 3 \leq N \leq 2 \times 10^5
- 0 \leq p_i \leq N-1
- i \neq j ならば p_i \neq p_j
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N p_0 \ldots p_{N-1}
出力
答えを出力せよ。
入力例 1
4 1 2 0 3
出力例 1
4
操作を 1 回行うと下の画像のようになります。
この時、4 人が喜ぶことを以下のように確かめられます。
- 人 0 は料理 0 が人 3\ (=(0-1) \bmod 4) の目の前に置かれているので喜びます。
- 人 1 は料理 1 が人 1\ (=1) の目の前に置かれているので喜びます。
- 人 2 は料理 2 が人 2\ (=2) の目の前に置かれているので喜びます。
- 人 3 は料理 3 が人 0\ (=(3+1) \bmod 4) の目の前に置かれているので喜びます。
5 人以上が喜ぶことは無いため、答えは 4 です。
入力例 2
3 0 1 2
出力例 2
3
入力例 3
10 3 9 6 1 7 2 8 0 5 4
出力例 3
5
Score : 300 points
Problem Statement
Person 0, Person 1, \ldots, and Person (N-1) are sitting around a turntable in their counterclockwise order, evenly spaced. Dish p_i is in front of Person i on the table.
You may perform the following operation 0 or more times:
- Rotate the turntable by one N-th of a counterclockwise turn. As a result, the dish that was in front of Person i right before the rotation is now in front of Person (i+1) \bmod N.
When you are finished, Person i is happy if Dish i is in front of Person (i-1) \bmod N, Person i, or Person (i+1) \bmod N.
Find the maximum possible number of happy people.
What is a \bmod m?
For an integer a and a positive integer m, a \bmod m denotes the integer x between 0 and (m-1) (inclusive) such that (a-x) is a multiple of m. (It can be proved that such x is unique.)Constraints
- 3 \leq N \leq 2 \times 10^5
- 0 \leq p_i \leq N-1
- p_i \neq p_j if i \neq j.
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N p_0 \ldots p_{N-1}
Output
Print the answer.
Sample Input 1
4 1 2 0 3
Sample Output 1
4
The figure below shows the table after one operation.
Here, there are four happy people:
- Person 0 is happy because Dish 0 is in front of Person 3\ (=(0-1) \bmod 4);
- Person 1 is happy because Dish 1 is in front of Person 1\ (=1);
- Person 2 is happy because Dish 2 is in front of Person 2\ (=2);
- Person 3 is happy because Dish 3 is in front of Person 0\ (=(3+1) \bmod 4).
There cannot be five or more happy people, so the answer is 4.
Sample Input 2
3 0 1 2
Sample Output 2
3
Sample Input 3
10 3 9 6 1 7 2 8 0 5 4
Sample Output 3
5
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 400 点
問題文
xy -平面上の N 個の円が与えられます。 i = 1, 2, \ldots, N について、i 番目の円は点 (x_i, y_i) を中心とする半径 r_i の円です。
N 個の円のうち少なくとも 1 つ以上の円の円周上にある点のみを通って、点 (s_x, s_y) から点 (t_x, t_y) に行くことができるかどうかを判定してください。
制約
- 1 \leq N \leq 3000
- -10^9 \leq x_i, y_i \leq 10^9
- 1 \leq r_i \leq 10^9
- (s_x, s_y) は N 個の円のうち少なくとも 1 つ以上の円の円周上にある
- (t_x, t_y) は N 個の円のうち少なくとも 1 つ以上の円の円周上にある
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N s_x s_y t_x t_y x_1 y_1 r_1 x_2 y_2 r_2 \vdots x_N y_N r_N
出力
点 (s_x, s_y) から点 (t_x, t_y) に行くことができる場合は Yes
を、そうでない場合は No
を出力せよ。
ジャッジは英小文字と英大文字を厳密に区別することに注意せよ。
入力例 1
4 0 -2 3 3 0 0 2 2 0 2 2 3 1 -3 3 3
出力例 1
Yes
例えば、下記の経路で点 (0, -2) から点 (3, 3) へ行くことができます。
- 点 (0, -2) から 1 つ目の円の円周上を反時計回りに通って点 (1, -\sqrt{3}) へ行く。
- 点 (1, -\sqrt{3}) から 2 つ目の円の円周上を時計回りに通って点 (2, 2) へ行く。
- 点 (2, 2) から 3 つ目の円の円周上を反時計回りに通って点 (3, 3) へ行く。
よって、Yes
を出力します。
入力例 2
3 0 1 0 3 0 0 1 0 0 2 0 0 3
出力例 2
No
少なくとも 1 つ以上の円の円周上にある点のみを通って点 (0, 1) から点 (0, 3) に行くことはできないので No
を出力します。
Score : 400 points
Problem Statement
You are given N circles on the xy-coordinate plane. For each i = 1, 2, \ldots, N, the i-th circle is centered at (x_i, y_i) and has a radius of r_i.
Determine whether it is possible to get from (s_x, s_y) to (t_x, t_y) by only passing through points that lie on the circumference of at least one of the N circles.
Constraints
- 1 \leq N \leq 3000
- -10^9 \leq x_i, y_i \leq 10^9
- 1 \leq r_i \leq 10^9
- (s_x, s_y) lies on the circumference of at least one of the N circles.
- (t_x, t_y) lies on the circumference of at least one of the N circles.
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N s_x s_y t_x t_y x_1 y_1 r_1 x_2 y_2 r_2 \vdots x_N y_N r_N
Output
If it is possible to get from (s_x, s_y) to (t_x, t_y), print Yes
; otherwise, print No
.
Note that the judge is case-sensitive.
Sample Input 1
4 0 -2 3 3 0 0 2 2 0 2 2 3 1 -3 3 3
Sample Output 1
Yes
Here is one way to get from (0, -2) to (3, 3).
- From (0, -2), pass through the circumference of the 1-st circle counterclockwise to reach (1, -\sqrt{3}).
- From (1, -\sqrt{3}), pass through the circumference of the 2-nd circle clockwise to reach (2, 2).
- From (2, 2), pass through the circumference of the 3-rd circle counterclockwise to reach (3, 3).
Thus, Yes
should be printed.
Sample Input 2
3 0 1 0 3 0 0 1 0 0 2 0 0 3
Sample Output 2
No
It is impossible to get from (0, 1) to (0, 3) by only passing through points on the circumference of at least one of the circles, so No
should be printed.