No.2519 Coins in Array
タグ : / 解いたユーザー数 65
作問者 :
MasKoaTS
/ テスター :
fky_
Problem Statement
There is a sequence $a$ of non-negative integers, initialized as $a=(A_{1}, A_{2}, \dots, A_{N})$.
Also, define $f(x,y)$ as the minimum non-negative integer $k$ satisfying the following condition.
If no such value exists, let $f(x,y) = 0$.
For every integer $z$ greater than or equal to $k$, there exists a pair of non-negative integers $(p,q)$ such that $z = p x + q y$.
You will now perform the following operation on $a$ exactly $N - 1$ times.
Choose $1$ pair of integers $(i, j)$ satisfying $1 \leq i, j \leq |a|$, $i \neq j$, and $\boldsymbol{ f(a_{i}, a_{j}) \leq 10^{18} }$,
then delete the $2$ elements $a_{i}, a_{j}$ from $a$ and append $1$ copy of $f(a_{i}, a_{j})$ to the end.Here, $a_{x}$ denotes the $x$-th $(x \geq 1)$ element from the front of $a$, and "deleting $a_{x}$ from $a$" means
removing $a_{x}$ from $a$ and shifting the remaining elements toward the front of the sequence while preserving their order.
Find the minimum possible value of the only $1$ element contained in $a$ after the $N-1$ operations.
It can be proved that, under the constraints of this problem, there exists at least $1$ way to perform the $N - 1$ operations.
As described in the "Output" section below, output the answer together with the operations.
Constraints
$2 \leq N \leq 2 \times 10^{5}$
$0 \leq A_{i} \leq 2 \times 10^{5}$ $(1 \leq i \leq N)$
All input values are integers.
Input
The input is given in the following format.
$N$
$A_{1}$ $A_{2}$ $\cdots$ $A_{N}$
Line $1$ contains $N$.
Line $2$ contains $A_{1}, A_{2}, \dots, A_{N}$ in this order, separated by half-width spaces.
Output
Output the answer in the following format, $1$ line at a time, for a total of $N$ lines.
$M$
$i_{1}$ $j_{1}$
$i_{2}$ $j_{2}$
$\vdots$
$i_{N-1}$ $j_{N-1}$
First, on line $1$, output the minimum value $M$ of the element finally contained in $a$.
Then, on lines $2, 3, \dots, N$, output a way of performing the $N-1$ operations such that the element finally contained in $a$ is $M$.
On line $k+1$ $(1 \leq k \leq N-1)$, output the pair of integers $(i, j) = (i_{k}, j_{k})$ chosen in the $k$-th operation, as $i_{k}, j_{k}$ in this order, separated by a half-width space.
Here, immediately before performing the $k$-th $(1 \leq k \leq N-1)$ operation, all of the following conditions must hold.
$1 \leq i_{k}, j_{k} \leq |a|$
$i_{k} \neq j_{k}$
$\boldsymbol{ f(a_{ i_{k} }, a_{ j_{k} }) \leq 10^{18} }$
Note that if the output fails to satisfy at least $1$ of the above requirements, the submission will not be judged as
AC.
If there are multiple correct answers satisfying all of the above requirements, any of them will be judged as
AC.
Sample
Sample 1
Input
2 3 5
Output
8 1 2
For every integer $z$ greater than or equal to $8$, there exists a pair of non-negative integers $(p,q)$ such that $z = 3 p + 5 q$, so $f(3,5) = 8$.
Therefore, in operation number $1$, you can choose $(i, j) = (1, 2)$, delete the $2$ elements $a_{1}=3, a_{2}=5$ from $a$, and append $f(3,5) = 8$ to the end.
If there are multiple correct answers, you may output any of them.
For example, the following output is also judged as AC.
8 2 1
Sample 2
Input
2 100 100
Output
0 1 2
For any integer $k$, there exists an integer $z$ such that, for every pair of non-negative integers $(p,q)$,
$z \geq k$ and $z \neq 100 p + 100 q$ hold, so $f(100, 100) = 0$.
Sample 3
Input
6 173448 104807 158459 62861 173448 173448
Output
0 1 5 4 5 2 3 1 3 1 2
The following output is also judged as AC.
0 1 5 5 2 3 4 1 2 2 1
The following output is judged as WA, because the integer appended to $a$ in operation number $3$ exceeds $10^{18}$.
0 1 2 5 1 1 4 3 1 1 2
Sample 4
Input
3 199993 199997 199999
Output
7999440010999938 1 2 1 2
The element finally contained in $a$ may not fit in a 32-bit integer type.
Also, the value output on line $1$ must be the minimum possible value of the only $1$ element contained in $a$ after the $N - 1$ operations.
Therefore, the following output is judged as WA.
7999440010999944 3 1 1 2
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。