Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
上下左右に広がる N\times N のマス目があり、最初全てのマスは白く塗られています。このマス目の上から i 行目、左から j 列目のマスを (i,j) で表します。
高橋君は 1 以上 N 以下の整数 A, B を持っており、次のような操作を行います。
- \max(1-A,1-B)\leq k\leq \min(N-A,N-B) をみたす全ての整数 k について、(A+k,B+k) を黒く塗る。
- \max(1-A,B-N)\leq k\leq \min(N-A,B-1) をみたす全ての整数 k について、(A+k,B-k) を黒く塗る。
この操作を行った後のマス目について、P\leq i\leq Q かつ R\leq j\leq S をみたす各マス (i,j) がそれぞれ何色で塗られているか求めてください。
制約
- 1 \leq N \leq 10^{18}
- 1 \leq A \leq N
- 1 \leq B \leq N
- 1 \leq P \leq Q \leq N
- 1 \leq R \leq S \leq N
- (Q-P+1)\times(S-R+1)\leq 3\times 10^5
- 入力は全て整数である。
入力
入力は以下の形式で標準入力から与えられる。
N A B P Q R S
出力
Q-P+1 行出力せよ。
各行は # と . のみからなる長さ S-R+1 の文字列であり、
i 行目の文字列の j 番目の文字が
# であることは (P+i-1,R+j-1) が黒く塗られていることを、
. であることは (P+i-1,R+j-1) が白く塗られていることをさす。
入力例 1
5 3 2 1 5 1 5
出力例 1
...#. #.#.. .#... #.#.. ...#.
1 つめの操作で (2,1), (3,2), (4,3), (5,4) の 4 マスが、
2 つめの操作で (4,1), (3,2), (2,3), (1,4) の 4 マスが黒く塗られます。
よって、P=1, Q=5, R=1, S=5 より、上のように出力します。
入力例 2
5 3 3 4 5 2 5
出力例 2
#.#. ...#
操作によって、
(1,1), (1,5), (2,2), (2,4), (3,3), (4,2), (4,4), (5,1), (5,5) の 9 マスが
黒く塗られます。
P=4, Q=5, R=2, S=5 より、上のように出力します。
入力例 3
1000000000000000000 999999999999999999 999999999999999999 999999999999999998 1000000000000000000 999999999999999998 1000000000000000000
出力例 3
#.# .#. #.#
入力が 32 bit 整数型に収まらないことがあることに注意してください。
Score : 300 points
Problem Statement
There is an N\times N grid with horizontal rows and vertical columns, where all squares are initially painted white. Let (i,j) denote the square at the i-th row and j-th column.
Takahashi has integers A and B, which are between 1 and N (inclusive). He will do the following operations.
- For every integer k such that \max(1-A,1-B)\leq k\leq \min(N-A,N-B), paint (A+k,B+k) black.
- For every integer k such that \max(1-A,B-N)\leq k\leq \min(N-A,B-1), paint (A+k,B-k) black.
In the grid after these operations, find the color of each square (i,j) such that P\leq i\leq Q and R\leq j\leq S.
Constraints
- 1 \leq N \leq 10^{18}
- 1 \leq A \leq N
- 1 \leq B \leq N
- 1 \leq P \leq Q \leq N
- 1 \leq R \leq S \leq N
- (Q-P+1)\times(S-R+1)\leq 3\times 10^5
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N A B P Q R S
Output
Print Q-P+1 lines.
Each line should contain a string of length S-R+1 consisting of # and ..
The j-th character of the string in the i-th line should be # to represent that (P+i-1, R+j-1) is painted black, and . to represent that (P+i-1, R+j-1) is white.
Sample Input 1
5 3 2 1 5 1 5
Sample Output 1
...#. #.#.. .#... #.#.. ...#.
The first operation paints the four squares (2,1), (3,2), (4,3), (5,4) black, and the second paints the four squares (4,1), (3,2), (2,3), (1,4) black.
Thus, the above output should be printed, since P=1, Q=5, R=1, S=5.
Sample Input 2
5 3 3 4 5 2 5
Sample Output 2
#.#. ...#
The operations paint the nine squares (1,1), (1,5), (2,2), (2,4), (3,3), (4,2), (4,4), (5,1), (5,5).
Thus, the above output should be printed, since P=4, Q=5, R=2, S=5.
Sample Input 3
1000000000000000000 999999999999999999 999999999999999999 999999999999999998 1000000000000000000 999999999999999998 1000000000000000000
Sample Output 3
#.# .#. #.#
Note that the input may not fit into a 32-bit integer type.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
1,2,\dots,N が 1 回ずつ現れる長さ N の数列を「長さ N の順列」と呼びます。
長さ N の順列 P = (p_1, p_2,\dots,p_N) が与えられるので、以下の条件を満たす長さ N の順列 Q = (q_1,\dots,q_N) を出力してください。
- 全ての i (1 \leq i \leq N) に対して Q の p_i 番目の要素が i である。
ただし、条件を満たす Q は必ずただ 1 つ存在することが証明できます。
制約
- 1 \leq N \leq 2 \times 10^5
- (p_1,p_2,\dots,p_N) は長さ N の順列である。
- 入力は全て整数である。
入力
入力は以下の形式で標準入力から与えられる。
N p_1 p_2 \dots p_N
出力
数列 Q を空白区切りで 1 行で出力せよ。
q_1 q_2 \dots q_N
入力例 1
3 2 3 1
出力例 1
3 1 2
以下に説明する通り、 Q=(3,1,2) は条件を満たす順列です。
- i = 1 のとき p_i = 2, q_2 = 1
- i = 2 のとき p_i = 3, q_3 = 2
- i = 3 のとき p_i = 1, q_1 = 3
入力例 2
3 1 2 3
出力例 2
1 2 3
全ての i (1 \leq i \leq N) に対して p_i = i が成り立つときは P = Q になります。
入力例 3
5 5 3 2 4 1
出力例 3
5 3 2 4 1
Score : 300 points
Problem Statement
We will call a sequence of length N where each of 1,2,\dots,N occurs once as a permutation of length N.
Given a permutation of length N, P = (p_1, p_2,\dots,p_N), print a permutation of length N, Q = (q_1,\dots,q_N), that satisfies the following condition.
- For every i (1 \leq i \leq N), the p_i-th element of Q is i.
It can be proved that there exists a unique Q that satisfies the condition.
Constraints
- 1 \leq N \leq 2 \times 10^5
- (p_1,p_2,\dots,p_N) is a permutation of length N (defined in Problem Statement).
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N p_1 p_2 \dots p_N
Output
Print the sequence Q in one line, with spaces in between.
q_1 q_2 \dots q_N
Sample Input 1
3 2 3 1
Sample Output 1
3 1 2
The permutation Q=(3,1,2) satisfies the condition, as follows.
- For i = 1, we have p_i = 2, q_2 = 1.
- For i = 2, we have p_i = 3, q_3 = 2.
- For i = 3, we have p_i = 1, q_1 = 3.
Sample Input 2
3 1 2 3
Sample Output 2
1 2 3
If p_i = i for every i (1 \leq i \leq N), we will have P = Q.
Sample Input 3
5 5 3 2 4 1
Sample Output 3
5 3 2 4 1
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 350 点
問題文
xy 平面に対し、レーザを照射しながら線分を印字する印字機があります。
- 印字開始時、レーザ照射位置は座標 (0, 0) にある。
-
線分を印字する際は、以下の流れに従う。
- まず、レーザ照射位置を線分の端点のうちどちらか 1 つに移動させる。
- どちらの端点から描画を始めてもよい。
- その後、レーザ照射位置のある端点からもう一方の端点まで、レーザを照射しながらレーザ照射位置を一直線に移動させる。
- 線分の途中で印字を中止することは許されない。
- まず、レーザ照射位置を線分の端点のうちどちらか 1 つに移動させる。
-
レーザを照射していない時、レーザ照射位置は 1 秒あたり速度 S で任意の方向に移動できる。
- レーザを照射している時、レーザ照射位置は 1 秒あたり速度 T で印字中の線分に沿って移動できる。
- レーザ照射位置の移動にかかる時間以外の所要時間は無視できる。
高橋君はこの印字機で N 本の線分を印字したいです。
そのうち i 本目の線分は、座標 (A_i, B_i) と座標 (C_i, D_i) を結びます。
なお、複数の線分が重なっていることがありますが、全ての線分についてその都度重なっている部分を印字する必要があります。
うまく印字機を操作したとき、全ての線分を印字完了するまでにかかる最小の時間は何秒ですか?
制約
- 入力は全て整数
- 1 \le N \le 6
- 1 \le T \le S \le 1000
- -1000 \le A_i,B_i,C_i,D_i \le 1000
- (A_i,B_i) \neq (C_i,D_i) ( 1 \le i \le N )
入力
入力は以下の形式で標準入力から与えられる。
N S T A_1 B_1 C_1 D_1 \vdots A_N B_N C_N D_N
出力
答えを出力せよ。
なお、真の値との絶対誤差または相対誤差が 10^{-6} 以下であれば正解として扱われる。
入力例 1
3 2 1 1 3 2 1 0 2 0 0 3 0 2 0
出力例 1
6.44317475868633722080
- レーザを照射しながらレーザ照射位置を (0,0) から (0,2) まで移動させ、 2 本目の線分を描画する。
- この描画に要する時間は 2 秒である。
- レーザを照射せずレーザ照射位置を (0,2) から (1,3) まで移動させる。
- この移動に要する時間は \sqrt{2}/2 秒である。
- レーザを照射しながらレーザ照射位置を (1,3) から (2,1) まで移動させ、 1 本目の線分を描画する。
- この描画に要する時間は \sqrt{5} 秒である。
- レーザを照射せずレーザ照射位置を (2,1) から (2,0) まで移動させる。
- この移動に要する時間は 1/2 秒である。
-
レーザを照射しながらレーザ照射位置を (2,0) から (3,0) まで移動させ、 3 本目の線分を描画する。
- この描画に要する時間は 1 秒である。
-
全体の所要時間は 2 + (\sqrt{2}/2) + \sqrt{5} + (1/2) + 1\approx 6.443175 秒です。
入力例 2
2 1 1 0 0 10 10 0 2 2 0
出力例 2
20.97056274847714058517
入力例 3
6 3 2 -1000 -1000 1000 1000 1000 -1000 -1000 1000 -1000 -1000 1000 1000 1000 -1000 -1000 1000 1000 1000 -1000 -1000 -1000 1000 1000 -1000
出力例 3
9623.35256169626864153344
複数の線分が重なっていますが、全ての線分についてその都度重なっている部分を印字する必要があります。
入力例 4
6 10 8 1000 1000 -1000 -1000 1000 -1000 -1000 -1000 -1000 1000 1000 1000 -1000 1000 -1000 -1000 1000 1000 1000 -1000 1000 -1000 -1000 1000
出力例 4
2048.52813742385702910909
Score : 350 points
Problem Statement
There is a printing machine that prints line segments on the xy-plane by emitting a laser.
- At the start of printing, the laser position is at coordinate (0, 0).
-
When printing a line segment, the procedure below is followed.
- First, move the laser position to one of the endpoints of the line segment.
- One may start drawing from either endpoint.
- Then, move the laser position in a straight line from the current endpoint to the other endpoint while emitting the laser.
- It is not allowed to stop printing in the middle of a line segment.
- First, move the laser position to one of the endpoints of the line segment.
-
When not emitting the laser, the laser position can move in any direction at a speed of S units per second.
- When emitting the laser, the laser position can move along the line segment being printed at a speed of T units per second.
- The time required for operations other than moving the laser position can be ignored.
Takahashi wants to print N line segments using this printing machine.
The i-th line segment connects coordinates (A_i, B_i) and (C_i, D_i).
Some line segments may overlap, in which case he needs to print the overlapping parts for each line segment separately.
What is the minimum number of seconds required to complete printing all the line segments when he operates the printing machine optimally?
Constraints
- All input values are integers.
- 1 \le N \le 6
- 1 \le T \le S \le 1000
- -1000 \le A_i,B_i,C_i,D_i \le 1000
- (A_i,B_i) \neq (C_i,D_i) ( 1 \le i \le N )
Input
The input is given from Standard Input in the following format:
N S T A_1 B_1 C_1 D_1 \vdots A_N B_N C_N D_N
Output
Print the answer.
Your output will be considered correct if the absolute or relative error from the true value does not exceed 10^{-6}.
Sample Input 1
3 2 1 1 3 2 1 0 2 0 0 3 0 2 0
Sample Output 1
6.44317475868633722080
- Emit the laser while moving the laser position from (0,0) to (0,2), printing the second line segment.
- This takes 2 seconds.
- Move the laser position from (0,2) to (1,3) without emitting the laser.
- This takes \sqrt{2}/2 seconds.
- Emit the laser while moving the laser position from (1,3) to (2,1), printing the first line segment.
- This takes \sqrt{5} seconds.
- Move the laser position from (2,1) to (2,0) without emitting the laser.
- This takes 1/2 second.
- Emit the laser while moving the laser position from (2,0) to (3,0), printing the third line segment.
- This takes 1 second.
- The total time taken is 2 + (\sqrt{2}/2) + \sqrt{5} + (1/2) + 1 \approx 6.443175 seconds.
Sample Input 2
2 1 1 0 0 10 10 0 2 2 0
Sample Output 2
20.97056274847714058517
Sample Input 3
6 3 2 -1000 -1000 1000 1000 1000 -1000 -1000 1000 -1000 -1000 1000 1000 1000 -1000 -1000 1000 1000 1000 -1000 -1000 -1000 1000 1000 -1000
Sample Output 3
9623.35256169626864153344
Multiple line segments overlap here, and you need to print the overlapping parts for each line segment separately.
Sample Input 4
6 10 8 1000 1000 -1000 -1000 1000 -1000 -1000 -1000 -1000 1000 1000 1000 -1000 1000 -1000 -1000 1000 1000 1000 -1000 1000 -1000 -1000 1000
Sample Output 4
2048.52813742385702910909
Time Limit: 2.5 sec / Memory Limit: 1024 MiB
配点 : 500 点
問題文
1,2,\ldots,N の番号のついた N 人の候補者で選挙が行われています。K 票の投票があり、現在一部の開票作業が行なわれました。
これまでの開票作業では、i 番目の候補者に A_i 票が入りました。
全ての票が開票された後、i 番目 (1 \leq i \leq N) の候補者はその候補者より多く票を獲得した候補者が M 人未満であるとき、かつその時に限り当選します。複数の候補者が当選することもあります。
各候補者が当選を確定させるためには残りの票のうち最小で何票追加で票が必要か求めてください。
より厳密には、i = 1,2,\ldots,N に対して次の問題を解いてください。
次の条件を満たす K - \displaystyle{\sum_{i=1}^{N}} A_i 以下の非負整数 X が存在するか判定し、存在するならその最小値を求めてください。
- これ以降の開票作業で i 番目の候補者へ X 票入るなら、i 番目の候補者は必ず当選する。
制約
- 1 \leq M \leq N \leq 2 \times 10^5
- 1 \leq K \leq 10^{12}
- 0 \leq A_i \leq 10^{12}
- \displaystyle{\sum_{i=1}^{N} A_i} \leq K
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N M K A_1 A_2 \ldots A_N
出力
候補者 i が当選を確定させるために必要な票数を C_i としたとき、C_1,C_2,\ldots,C_N を空白区切りで出力せよ。
ただし、候補者 i がすでに当選を確定させている場合は C_i=0、候補者 i が当選を確定させることができない場合は C_i=-1 とします。
入力例 1
5 2 16 3 1 4 1 5
出力例 1
2 -1 1 -1 0
すでに 14 票の開票が終了しており、残りの票数は 2 票です。
答えるべき C は (2, -1, 1, -1, 0) です。たとえば:
- 候補者 1 は追加で 2 票得ることで当選を確定することができます。追加で 1 票獲得することでは当選を確定することができないので、C_1 = 2 です。
- 候補者 2 はどのようにしても(例えば、残り 2 票をすべて獲得しても)当選することが不可能なので、 C_2 = -1 です。
入力例 2
12 1 570 81 62 17 5 5 86 15 7 79 26 6 28
出力例 2
79 89 111 117 117 74 112 116 80 107 117 106
Score : 500 points
Problem Statement
An election is being held with N candidates numbered 1, 2, \ldots, N. There are K votes, some of which have been counted so far.
Up until now, candidate i has received A_i votes.
After all ballots are counted, candidate i (1 \leq i \leq N) will be elected if and only if the number of candidates who have received more votes than them is less than M. There may be multiple candidates elected.
For each candidate, find the minimum number of additional votes they need from the remaining ballots to guarantee their victory regardless of how the other candidates receive votes.
Formally, solve the following problem for each i = 1,2,\ldots,N.
Determine if there is a non-negative integer X not exceeding K - \displaystyle{\sum_{i=1}^{N}} A_i satisfying the following condition. If it exists, find the minimum possible such integer.
- If candidate i receives X additional votes, then candidate i will always be elected.
Constraints
- 1 \leq M \leq N \leq 2 \times 10^5
- 1 \leq K \leq 10^{12}
- 0 \leq A_i \leq 10^{12}
- \displaystyle{\sum_{i=1}^{N} A_i} \leq K
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N M K A_1 A_2 \ldots A_N
Output
Let C_i be the minimum number of additional votes candidate i needs from the remaining ballots to guarantee their victory regardless of how other candidates receive votes. Print C_1, C_2, \ldots, C_N separated by spaces.
If candidate i has already secured their victory, then let C_i = 0. If candidate i cannot secure their victory under any circumstances, then let C_i = -1.
Sample Input 1
5 2 16 3 1 4 1 5
Sample Output 1
2 -1 1 -1 0
14 votes have been counted so far, and 2 votes are left.
The C to output is (2, -1, 1, -1, 0). For example:
- Candidate 1 can secure their victory by obtaining 2 more votes, while not by obtaining 1 more vote. Thus, C_1 = 2.
- Candidate 2 can never (even if they obtain 2 more votes) secure their victory, so C_2 = -1.
Sample Input 2
12 1 570 81 62 17 5 5 86 15 7 79 26 6 28
Sample Output 2
79 89 111 117 117 74 112 116 80 107 117 106
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 500 点
問題文
AtCoder Land で高橋君と青木君はイチゴの乗ったケーキを食べることになりました。
AtCoder Landのケーキは円形で、N 個の半径方向の切れ込みによって N 個の扇形ピースに区切られています。
切れ込みを時計回りの順に切れ込み 1, 切れ込み 2, \ldots, 切れ込み N と番号をふったとき、時計回りに切れ込み i (1 \leq i \leq N-1) から切れ込み i+1 までの間の部分をピース i と呼びます。また、時計回りに切れ込み N から切れ込み 1 までの間の部分をピース N と呼びます。
ピース i (1 \leq i \leq N) の上には A_i 個のイチゴが乗っています。
高橋君と青木君はこれから以下のゲームをします。
- まず、高橋君が N 個の切れ込みのなかから 1 つを選ぶ。選んだ切れ込みを切れ込み i とする。
- 次に、青木君が高橋君の選んだ切れ込み以外の N-1 個の切れ込みのなかから 1 つを選ぶ。選んだ切れ込みを切れ込み j とする。
- 高橋君は切れ込み i から時計回りに見ていって、切れ込み j までの範囲のピースをすべてもらう。
- 青木君は、残りのピースをすべてもらう。
- 高橋君がもらったピースの 1 ピースあたりのイチゴの個数の平均値が青木君がもらったピースの 1 ピースあたりのイチゴの個数の平均値以上であるとき、高橋君の勝ちです。そうでないとき、青木君の勝ちです。
青木君が勝つために最適な切れ込みを選ぶとき、高橋君は必ず勝つためにはどの切れ込みを選べばよいか求めてください。そのような切れ込みが、存在しないときは -1 を、複数存在する場合はそのうち番号が最小のものを答えてください。
制約
- 2 \leq N \leq 5 \times 10^{5}
- 0 \leq A_i \leq 5 \times 10^{5}
- 入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N A_1 A_2 \ldots A_N
出力
答えとなる切れ込みの番号を出力せよ。答えとなる切れ込みが存在しない場合は -1 を出力せよ。
入力例 1
3 3 8 5
出力例 1
2
高橋君が切れ込み 1 を選んだ時、青木君は切れ込み 2 を選ぶと高橋君はピース 1 のみを、青木君はピース 2,3 をもらいます。高橋君のもらったピースの上に乗ってるイチゴの個数の平均値は 3、青木君のもらったピースの上に乗ってるイチゴの個数の平均値は 6.5 です。よって青木君が勝ちます。
高橋君が切れ込み 2 を選んだ時、青木君はどの切れ込みを選んでも高橋君が勝ちます。よって、答えは 2 です。
入力例 2
15 4096 64 512 1 256 16384 8 1024 2048 2 128 32 4 16 8192
出力例 2
15