No.2104 Multiply-Add
タグ : / 解いたユーザー数 63
作問者 :
Sumitacchan
/ テスター :
👑
hitonanode
Problem Statement
There are $2$ variables $x,y$, and initially $(x,y)=(a,b)$.
You may perform the following operations in any order, up to $1000$ times in total (possibly $0$ times).
- Operation $1$ : Choose an integer $k\ (-10^9 \le k \le 10^9)$ and add $k \times y$ to $x$.
- Operation $2$ : Choose an integer $k\ (-10^9 \le k \le 10^9)$ and add $k \times x$ to $y$.
Determine whether it is possible to make $(x,y)=(c,d)$ by the above operations, and if it is possible, show one such sequence of operations.
Constraints
- $-10^8 \le a,b,c,d \le 10^8$
- All inputs are integers.
Input
The input is given from standard input in the following format.
$a\ \ b\ \ c\ \ d$
Output
If it is impossible to make $(x,y)=(c,d)$, print $-1$.
If it is possible to make $(x,y)=(c,d)$, print such a sequence of operations in the following format (if there are multiple sequences of operations satisfying the conditions, you may print any of them).
$N$ $t_1\ \ k_1$ $t_2\ \ k_2$ $\vdots$ $t_N\ \ k_N$Here, $N$ is the number of operations, and $t_i,k_i\ (1\le i\le N)$ are the type of the $i$-th operation and the value of $k$ chosen in it, respectively.
Each of them must be an integer satisfying the following conditions.
- $0 \le N\le 1000$
- $t_i=1$ or $t_i=2$
- $-10^9\le k_i \le 10^9$
Sample
Sample 1
Input
5 1 -10 19
Output
4 1 3 2 1 1 -2 2 -1
With the $4$ operations, $(x,y)$ changes as follows.
$(5,1) \rightarrow (8,1) \rightarrow (8,9) \rightarrow (-10,9) \rightarrow (-10,19)$
Sample 2
Input
0 0 1 -1
Output
-1
No matter how many operations are performed, $(x,y)=(0,0)$ remains unchanged.
Sample 3
Input
123 456 123 456
Output
0
$(x,y)=(c,d)$ is satisfied from the beginning.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。