結果

問題 No.2104 Multiply-Add
ユーザー ShirotsumeShirotsume
提出日時 2022-10-21 23:45:17
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 1,887 bytes
コンパイル時間 341 ms
コンパイル使用メモリ 87,268 KB
実行使用メモリ 79,544 KB
最終ジャッジ日時 2023-09-13 23:51:46
合計ジャッジ時間 10,062 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 78 ms
71,684 KB
testcase_01 AC 76 ms
71,432 KB
testcase_02 AC 77 ms
71,468 KB
testcase_03 RE -
testcase_04 AC 78 ms
71,224 KB
testcase_05 AC 76 ms
71,352 KB
testcase_06 AC 77 ms
71,376 KB
testcase_07 RE -
testcase_08 AC 77 ms
71,380 KB
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 AC 75 ms
71,136 KB
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 AC 74 ms
71,420 KB
testcase_20 AC 75 ms
71,348 KB
testcase_21 AC 76 ms
71,340 KB
testcase_22 AC 74 ms
71,364 KB
testcase_23 AC 76 ms
71,456 KB
testcase_24 AC 74 ms
71,664 KB
testcase_25 WA -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
testcase_33 RE -
testcase_34 AC 74 ms
71,436 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = lambda: sys.stdin.readline().rstrip()
ii = lambda: int(input())
mi = lambda: map(int, input().split())
li = lambda: list(mi())
inf = 2 ** 63 - 1
mod = 998244353
from math import gcd
a, b, c, d = mi()

if gcd(a, b) == 0:
    print(-1)
    exit()
if gcd(c, d) % gcd(a, b):
    print(-1)
    exit()

ans = []

x = a
y = b

for i in range(200):
    if x * y == 0:
        break
    if abs(x) >= abs(y):
        k = x // y
        ans.append((1, -k))
        x -= k * y
    else:
        k = y // x
        ans.append((2, -k))
        y -= k * x

ans2 = []
x2 = c
y2 = d
for i in range(200):
    if x2 * y2 == 0:
        break
    if abs(x2) >= abs(y2):
        k = x2 // y2
        x2 -= k * y2
        ans2.append((1, k))
    else:

        k = y2 // x2
        y2 -= k * x2
        ans2.append((2, k))
#入れ替え
if x == 0 and x2 != 0:
    ans2.append((2, 1))
    y2 += x2
    ans2.append((1, -1))
    x2 -= y2
if y == 0 and y2 != 0:
    ans2.append((1, 1))
    x2 += y2
    ans2.append((2, -1))
    y2 += x2
#符号変え
if x * x2 < 0:
    ans2.append((2, -1))
    y2 -= x2
    ans2.append((1, 1))
    x2 += y2
if y * y2 < 0:
    ans2.append((1, -1))
    x2 -= y2
    ans2.append((2, 1))
    y2 += x2
if x == 0 and x2 != 0:
    ans2.append((2, 1))
    y2 += x2
    ans2.append((1, -1))
    x2 -= y2
if y == 0 and y2 != 0:
    ans2.append((1, 1))
    x2 += y2
    ans2.append((2, -1))
    y2 += x2
if x * x2 < 0:
    ans2.append((2, -1))
    y2 -= x2
    ans2.append((1, 1))
    x2 += y2
if y * y2 < 0:
    ans2.append((1, -1))
    x2 -= y2
    ans2.append((2, 1))
    y2 += x2
if x == 0 and x2 != 0:
    ans2.append((2, 1))
    y2 += x2
    ans2.append((1, -1))
    x2 -= y2
ans = ans + ans2[::-1]

x, y = a, b
for t, k in ans:
    if t == 1:
        x += y * k
    else:
        y += x * k
assert x == c and y == d

print(len(ans))
for t, k in ans:
    print(t, k)
0