Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
別世界の AtCoder で開催されている AtCoder Big Contest では、 10^{16} 問の問題が一度に出題されます。
問題の ID は 1 問目から順に A
, B
, ..., Z
, AA
, AB
, ..., ZZ
, AAA
, ... と付けられています。
つまり、 ID は以下の順番で付けられています。
- 長さ 1 の英大文字からなる文字列を辞書順に並べたもの
- 長さ 2 の英大文字からなる文字列を辞書順に並べたもの
- 長さ 3 の英大文字からなる文字列を辞書順に並べたもの
- ...
このコンテストに含まれる問題の ID である文字列 S が与えられるので、それが何問目か答えてください。
制約
- S は AtCoder Big Contest に含まれる問題の ID として正しい
入力
入力は以下の形式で標準入力から与えられる。
S
出力
答えを整数として出力せよ。
入力例 1
AB
出力例 1
28
ID が AB
である問題は、 AtCoder Big Contest の 28 問目です。
入力例 2
C
出力例 2
3
ID が C
である問題は、 AtCoder Big Contest の 3 問目です。
入力例 3
BRUTMHYHIIZP
出力例 3
10000000000000000
ID が BRUTMHYHIIZP
である問題は、 AtCoder Big Contest の 10^{16} 問目、すなわち最終問題です。
Score : 300 points
Problem Statement
In a parallel universe, AtCoder holds AtCoder Big Contest, where 10^{16} problems are given at once.
The IDs of the problems are as follows, from the 1-st problem in order: A
, B
, ..., Z
, AA
, AB
, ..., ZZ
, AAA
, ...
In other words, the IDs are given in the following order:
- the strings of length 1 consisting of uppercase English letters, in lexicographical order;
- the strings of length 2 consisting of uppercase English letters, in lexicographical order;
- the strings of length 3 consisting of uppercase English letters, in lexicographical order;
- ...
Given a string S that is an ID of a problem given in this contest, find the index of the problem. (See also Samples.)
Constraints
- S is a valid ID of a problem given in AtCoder Big Contest.
Input
The input is given from Standard Input in the following format:
S
Output
Print the answer as an integer.
Sample Input 1
AB
Sample Output 1
28
The problem whose ID is AB
is the 28-th problem of AtCoder Big Contest, so 28 should be printed.
Sample Input 2
C
Sample Output 2
3
The problem whose ID is C
is the 3-rd problem of AtCoder Big Contest, so 3 should be printed.
Sample Input 3
BRUTMHYHIIZP
Sample Output 3
10000000000000000
The problem whose ID is BRUTMHYHIIZP
is the
10^{16}-th (last) problem of AtCoder Big Contest, so 10^{16} should be printed as an integer.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
高橋君は N 日間の鉄道旅行を計画しています。
高橋君はそれぞれの日について、運賃の通常料金を払うか、1 日周遊パスを 1 枚使用するか選ぶことができます。
ここで、1\leq i\leq N について、i 日目の旅行にかかる運賃の通常料金は F_i 円です。
一方、1 日周遊パスは D 枚セットで P 円で発売されており、何セットでも購入することが可能ですが、D 枚単位でしか購入することができません。
また、購入したパスは 1 枚ずつ好きな日に使うことができ、旅行が終了した時点で余っていても構いません。
N 日間の旅行でかかる金額、すなわち 1 日周遊パスの購入にかかった代金と、1 日周遊パスを利用しなかった日における運賃の通常料金の合計金額の和としてあり得る最小値を求めてください。
制約
- 1\leq N\leq 2\times 10^5
- 1\leq D\leq 2\times 10^5
- 1\leq P\leq 10^9
- 1\leq F_i\leq 10^9
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N D P F_1 F_2 \ldots F_N
出力
N 日間の旅行でかかる金額としてあり得る最小値を出力せよ。
入力例 1
5 2 10 7 1 6 3 6
出力例 1
20
1 日周遊パスを 1 セットだけ購入し、1 日目と 3 日目に使用すると、合計金額は (10\times 1)+(0+1+0+3+6)=20 となり、このときかかる金額が最小となります。
よって、20 を出力します。
入力例 2
3 1 10 1 2 3
出力例 2
6
3 日間すべてにおいて運賃の通常料金を支払ったときに最小となります。
入力例 3
8 3 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000
出力例 3
3000000000
1 日周遊パスを 3 セット購入し、8 日間すべてにおいて 1 日周遊パスを利用したときに最小となります。
答えが 32 bit 整数型に収まらないことがあることに注意してください。
Score : 300 points
Problem Statement
Takahashi is planning an N-day train trip.
For each day, he can pay the regular fare or use a one-day pass.
Here, for 1\leq i\leq N, the regular fare for the i-th day of the trip is F_i yen.
On the other hand, a batch of D one-day passes is sold for P yen. You can buy as many passes as you want, but only in units of D.
Each purchased pass can be used on any day, and it is fine to have some leftovers at the end of the trip.
Find the minimum possible total cost for the N-day trip, that is, the cost of purchasing one-day passes plus the total regular fare for the days not covered by one-day passes.
Constraints
- 1\leq N\leq 2\times 10^5
- 1\leq D\leq 2\times 10^5
- 1\leq P\leq 10^9
- 1\leq F_i\leq 10^9
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N D P F_1 F_2 \ldots F_N
Output
Print the minimum possible total cost for the N-day trip.
Sample Input 1
5 2 10 7 1 6 3 6
Sample Output 1
20
If he buys just one batch of one-day passes and uses them for the first and third days, the total cost will be (10\times 1)+(0+1+0+3+6)=20, which is the minimum cost needed.
Thus, print 20.
Sample Input 2
3 1 10 1 2 3
Sample Output 2
6
The minimum cost is achieved by paying the regular fare for all three days.
Sample Input 3
8 3 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000
Sample Output 3
3000000000
The minimum cost is achieved by buying three batches of one-day passes and using them for all eight days.
Note that the answer may not fit into a 32-bit integer type.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 400 点
問題文
長さ N の数列 A=(A_1,A_2,\ldots,A_N) が与えられます。
以下の 2 条件をともに満たすような整数の組 (i,j,k) の個数を求めてください。
- 1\leq i \lt j \lt k \leq N
- A_i,A_j,A_k は相異なる
制約
- 3 \leq N \leq 2\times 10^5
- 1 \leq A_i \leq 2\times 10^5
- 入力に含まれる値は全て整数である
入力
入力は以下の形式で標準入力から与えられる。
N A_1 A_2 \ldots A_N
出力
答えを出力せよ。
入力例 1
4 3 1 4 1
出力例 1
2
条件を満たす整数の組 (i,j,k) は (1,2,3),(1,3,4) の 2 つです。
入力例 2
10 99999 99998 99997 99996 99995 99994 99993 99992 99991 99990
出力例 2
120
入力例 3
15 3 1 4 1 5 9 2 6 5 3 5 8 9 7 9
出力例 3
355
Score : 400 points
Problem Statement
You are given a sequence of length N: A=(A_1,A_2,\ldots,A_N).
Find the number of triples (i,j,k) that satisfy both of the following conditions.
- 1\leq i \lt j \lt k \leq N
- A_i, A_j, and A_k are distinct.
Constraints
- 3 \leq N \leq 2\times 10^5
- 1 \leq A_i \leq 2\times 10^5
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N A_1 A_2 \ldots A_N
Output
Print the answer.
Sample Input 1
4 3 1 4 1
Sample Output 1
2
The two triples (i,j,k) satisfying the conditions are (1,2,3) and (1,3,4).
Sample Input 2
10 99999 99998 99997 99996 99995 99994 99993 99992 99991 99990
Sample Output 2
120
Sample Input 3
15 3 1 4 1 5 9 2 6 5 3 5 8 9 7 9
Sample Output 3
355
Time Limit: 3 sec / Memory Limit: 1024 MiB
配点 : 475 点
問題文
N 頂点 M 辺の無向グラフ G が与えられます。 i = 1, 2, \ldots, M について、i 番目の辺は頂点 u_i と頂点 v_i を結ぶ無向辺です。
N 頂点のグラフは、すべての i = 1, 2, \ldots, K について下記の条件が成り立つとき、良いグラフと呼ばれます。
- G 上で頂点 x_i と頂点 y_i を結ぶパスが存在しない。
与えられるグラフ G は良いグラフです。
Q 個の独立な質問が与えられるので、それらすべてに答えてください。 i = 1, 2, \ldots, Q について、i 番目の質問は
- 入力で与えられたグラフ G に頂点 p_i と頂点 q_i を結ぶ無向辺を 1 本追加して得られるグラフ G^{(i)} は良いグラフですか?
という質問です。
制約
- 2 \leq N \leq 2 \times 10^5
- 0 \leq M \leq 2 \times 10^5
- 1 \leq u_i, v_i \leq N
- 1 \leq K \leq 2 \times 10^5
- 1 \leq x_i, y_i \leq N
- x_i \neq y_i
- i \neq j \implies \lbrace x_i, y_i \rbrace \neq \lbrace x_j, y_j \rbrace
- すべての i = 1, 2, \ldots, K について次が成り立つ:頂点 x_i と頂点 y_i を結ぶパスは存在しない。
- 1 \leq Q \leq 2 \times 10^5
- 1 \leq p_i, q_i \leq N
- p_i \neq q_i
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N M u_1 v_1 u_2 v_2 \vdots u_M v_M K x_1 y_1 x_2 y_2 \vdots x_K y_K Q p_1 q_1 p_2 q_2 \vdots p_Q q_Q
出力
Q 行出力せよ。
i = 1, 2, \ldots, Q について、i 行目には i 番目の質問に対する答えを出力せよ。
具体的には、グラフ G^{(i)} が良いグラフである場合は Yes
を、良いグラフでない場合は No
を出力せよ。
入力例 1
6 6 1 2 2 3 2 3 3 1 5 4 5 5 3 1 5 2 6 4 3 4 2 5 2 6 5 6 5 4
出力例 1
No No Yes Yes
- 1 番目の質問に関して、グラフ G^{(1)} は良いグラフではありません。なぜなら、頂点 x_1 = 1 と頂点 y_1 = 5 を結ぶパス 1 \rightarrow 2 \rightarrow 5 を持つからです。よって、
No
と出力します。 - 2 番目の質問に関して、グラフ G^{(2)} は良いグラフではありません。なぜなら、頂点 x_2 = 2 と頂点 y_2 = 6 を結ぶパス 2 \rightarrow 6 を持つからです。よって、
No
と出力します。 - 3 番目の質問に関して、グラフ G^{(3)} は良いグラフです。よって、
Yes
と出力します。 - 4 番目の質問に関して、グラフ G^{(4)} は良いグラフです。よって、
Yes
と出力します。
この入力例のように、与えられるグラフ G が自己ループや多重辺を持つ場合があることに注意してください。
Score : 475 points
Problem Statement
You are given an undirected graph G with N vertices and M edges. For i = 1, 2, \ldots, M, the i-th edge is an undirected edge connecting vertices u_i and v_i.
A graph with N vertices is called good if the following condition holds for all i = 1, 2, \ldots, K:
- there is no path connecting vertices x_i and y_i in G.
The given graph G is good.
You are given Q independent questions. Answer all of them. For i = 1, 2, \ldots, Q, the i-th question is as follows.
- Is the graph G^{(i)} obtained by adding an undirected edge connecting vertices p_i and q_i to the given graph G good?
Constraints
- 2 \leq N \leq 2 \times 10^5
- 0 \leq M \leq 2 \times10^5
- 1 \leq u_i, v_i \leq N
- 1 \leq K \leq 2 \times 10^5
- 1 \leq x_i, y_i \leq N
- x_i \neq y_i
- i \neq j \implies \lbrace x_i, y_i \rbrace \neq \lbrace x_j, y_j \rbrace
- For all i = 1, 2, \ldots, K, there is no path connecting vertices x_i and y_i.
- 1 \leq Q \leq 2 \times 10^5
- 1 \leq p_i, q_i \leq N
- p_i \neq q_i
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N M u_1 v_1 u_2 v_2 \vdots u_M v_M K x_1 y_1 x_2 y_2 \vdots x_K y_K Q p_1 q_1 p_2 q_2 \vdots p_Q q_Q
Output
Print Q lines.
For i = 1, 2, \ldots, Q, the i-th line should contain the answer to the i-th question: Yes
if the graph G^{(i)} is good, and No
otherwise.
Sample Input 1
6 6 1 2 2 3 2 3 3 1 5 4 5 5 3 1 5 2 6 4 3 4 2 5 2 6 5 6 5 4
Sample Output 1
No No Yes Yes
- For the first question, the graph G^{(1)} is not good because it has a path 1 \rightarrow 2 \rightarrow 5 connecting vertices x_1 = 1 and y_1 = 5. Therefore, print
No
. - For the second question, the graph G^{(2)} is not good because it has a path 2 \rightarrow 6 connecting vertices x_2 = 2 and y_2 = 6. Therefore, print
No
. - For the third question, the graph G^{(3)} is good. Therefore, print
Yes
. - For the fourth question, the graph G^{(4)} is good. Therefore, print
Yes
.
As seen in this sample input, note that the given graph G may have self-loops or multi-edges.
Time Limit: 4 sec / Memory Limit: 1024 MiB
配点 : 525 点
問題文
右向きを x 軸正方向、上向きを y 軸正方向とする座標平面の原点にロボットがいます。ロボットは最初、x 軸正方向を向いています。
i=1,\ldots,N の順に以下の操作を行います:
- ロボットを右回りまたは左回りに 90 度回転させる。その後、ロボットは向いている方向に A_i 進む
回転方向を適切に選ぶことで、N 回の操作後にロボットがいる座標を (X,Y) にすることはできますか?
できるならば、各操作において、右回りと左回りのどちらを選べばよいか求めてください。
制約
- 1 \leq N \leq 80
- 1 \leq A_i \leq 10^7
- -10^9\leq X,Y \leq 10^9
- 入力は全て整数である
入力
入力は以下の形式で標準入力から与えられる。
N X Y A_1 \ldots A_N
出力
N 回の操作後にロボットがいる座標を (X,Y) にできないとき、No
と出力せよ。
N 回の操作後にロボットがいる座標を (X,Y) にできるとき、1行目に Yes
と出力し、2行目に次の条件を満たす長さ N の文字列 S を出力せよ。
条件: S は L
または R
のみからなり、S の i 番目の文字が L
ならば i 回目の操作においてロボットを左回りに、R
ならばロボットを右回りに回転させることで、N 回の操作後にロボットがいる座標を (X,Y) にできる。
答えが複数ある場合はどれを出力しても正解となる。
入力例 1
3 -2 4 3 2 1
出力例 1
Yes LLR
最初ロボットは (0,0) にいて、x 軸正方向を向いています。次の手順により、N 回の操作後にロボットがいる座標を (X,Y) にできます。
- 1 回目の操作:ロボットを左に 90 度回転させ、y 軸正方向を向かせる。ロボットは向いている方向に A_1=3 進み、ロボットのいる座標は (0,3) となる。
- 2 回目の操作:ロボットを左に 90 度回転させ、x 軸負方向を向かせる。ロボットは向いている方向に A_2=2 進み、ロボットのいる座標は (-2,3) となる。
- 3 回目の操作:ロボットを右に 90 度回転させ、y 軸正方向を向かせる。ロボットは向いている方向に A_3=1 進み、ロボットのいる座標は (-2,4) となる。
入力例 2
1 0 0 1
出力例 2
No
入力例 3
4 0 0 1 1 1 1
出力例 3
Yes LRRR
LLLL
や RRRR
などでも正解となります。
入力例 4
14 2543269 -1705099 3 14 159 2653 58979 323846 2643383 2795028 841971 69399 37510 58 20 9
出力例 4
Yes LLLLLLLLLRLRRR
Score : 525 points
Problem Statement
A robot is at the origin of a coordinate plane where the positive x-axis points to the right and the positive y-axis points upwards. Initially, the robot is facing the positive x-direction.
You will perform the following operation for i=1,\ldots,N in this order.
- Rotate the robot 90 degrees clockwise or counterclockwise. Then, the robot moves forward A_i units in the direction it is facing.
Can the direction of rotation be chosen so that the robot will be at the coordinates (X,Y) after the N operations?
If it is possible, determine which direction, clockwise or counterclockwise, should be chosen for each operation.
Constraints
- 1 \leq N \leq 80
- 1 \leq A_i \leq 10^7
- -10^9\leq X,Y \leq 10^9
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N X Y A_1 \ldots A_N
Output
If the robot cannot be at the coordinates (X,Y) after the N operations, print No
.
If the robot can be at the coordinates (X,Y) after the N operations, the first line should contain Yes
, and the second line should contain a string S of length N that satisfies the following condition.
Condition: S consists of L
and R
, and the following choices can put the robot at the coordinates (X,Y) after the N operations: in the i-th operation, rotate the robot counterclockwise if the i-th character of S is L
, and rotate it clockwise if it is R
.
If there are multiple solutions, you may print any of them.
Sample Input 1
3 -2 4 3 2 1
Sample Output 1
Yes LLR
Initially, the robot is at (0,0) and facing the positive x-direction. The following choices can put the robot at the coordinates (X,Y) after the N operations.
- First operation: Rotate the robot 90 degrees counterclockwise to face the positive y-direction. The robot moves forward A_1=3 units in the direction it is facing, and moves to (0,3).
- Second operation: Rotate the robot 90 degrees counterclockwise to face the negative x-direction. The robot moves forward A_2=2 units in the direction it is facing, and moves to (-2,3).
- Third operation: Rotate the robot 90 degrees clockwise to face the positive y-direction. The robot moves forward A_3=1 unit in the direction it is facing, and moves to (-2,4).
Sample Input 2
1 0 0 1
Sample Output 2
No
Sample Input 3
4 0 0 1 1 1 1
Sample Output 3
Yes LRRR
Outputs such as LLLL
and RRRR
are also accepted.
Sample Input 4
14 2543269 -1705099 3 14 159 2653 58979 323846 2643383 2795028 841971 69399 37510 58 20 9
Sample Output 4
Yes LLLLLLLLLRLRRR