結果

問題 No.2104 Multiply-Add
ユーザー ShirotsumeShirotsume
提出日時 2022-10-22 00:43:25
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,434 bytes
コンパイル時間 279 ms
コンパイル使用メモリ 87,000 KB
実行使用メモリ 79,644 KB
最終ジャッジ日時 2023-09-14 00:38:23
合計ジャッジ時間 6,491 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,452 KB
testcase_01 AC 72 ms
71,436 KB
testcase_02 AC 71 ms
71,576 KB
testcase_03 AC 75 ms
71,508 KB
testcase_04 AC 70 ms
71,544 KB
testcase_05 AC 72 ms
71,332 KB
testcase_06 AC 69 ms
71,456 KB
testcase_07 AC 70 ms
71,668 KB
testcase_08 AC 71 ms
71,204 KB
testcase_09 AC 71 ms
71,352 KB
testcase_10 AC 71 ms
71,456 KB
testcase_11 AC 71 ms
71,196 KB
testcase_12 AC 69 ms
71,396 KB
testcase_13 AC 68 ms
71,692 KB
testcase_14 AC 66 ms
71,448 KB
testcase_15 AC 67 ms
71,264 KB
testcase_16 AC 70 ms
71,356 KB
testcase_17 AC 72 ms
71,436 KB
testcase_18 AC 72 ms
71,508 KB
testcase_19 AC 71 ms
71,400 KB
testcase_20 AC 72 ms
71,464 KB
testcase_21 AC 72 ms
71,748 KB
testcase_22 AC 70 ms
71,456 KB
testcase_23 AC 70 ms
71,400 KB
testcase_24 AC 71 ms
71,324 KB
testcase_25 WA -
testcase_26 AC 72 ms
71,468 KB
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
testcase_33 RE -
testcase_34 AC 70 ms
71,404 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 i % 2:
        k = x // y
        ans.append((1, -k))
        x -= k * y
    else:
        k = y // x
        ans.append((2, -k))
        y -= k * x
if x == 0:
    ans.append((1, 1))
    x += y
    ans.append((2, -1))
    y -= x
if x < 0:
    ans.append((2, -1))
    y -= x
    ans.append((1, 1))
    x += y
    ans.append((1, 1))
    x += y
    ans.append((2, -1))
    y -= x
ans2 = []
x = c
y = d
for i in range(200):
    if x * y == 0:
        break
    if i % 2:
        k = x // y
        ans2.append((1, k))
        x -= k * y
    else:
        k = y // x
        ans2.append((2, k))
        y -= k * x
if x == 0:
    ans2.append((1, -1))
    x += y
    ans2.append((2, 1))
    y -= x
if x < 0:
    ans2.append((2, 1))
    y -= x
    ans2.append((1, -1))
    x += y
    ans2.append((1, -1))
    x += y
    ans2.append((2, 1))
    y -= x
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