結果

問題 No.2104 Multiply-Add
ユーザー 👑 rin204rin204
提出日時 2022-10-28 14:42:59
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 79 ms / 2,000 ms
コード長 909 bytes
コンパイル時間 404 ms
コンパイル使用メモリ 87,140 KB
実行使用メモリ 71,712 KB
最終ジャッジ日時 2023-09-19 07:15:47
合計ジャッジ時間 5,374 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,344 KB
testcase_01 AC 74 ms
71,480 KB
testcase_02 AC 72 ms
71,516 KB
testcase_03 AC 75 ms
71,540 KB
testcase_04 AC 73 ms
71,664 KB
testcase_05 AC 75 ms
71,508 KB
testcase_06 AC 76 ms
71,468 KB
testcase_07 AC 78 ms
71,444 KB
testcase_08 AC 75 ms
71,712 KB
testcase_09 AC 74 ms
71,328 KB
testcase_10 AC 75 ms
71,480 KB
testcase_11 AC 73 ms
71,388 KB
testcase_12 AC 75 ms
71,436 KB
testcase_13 AC 76 ms
71,692 KB
testcase_14 AC 76 ms
71,668 KB
testcase_15 AC 76 ms
71,284 KB
testcase_16 AC 78 ms
71,388 KB
testcase_17 AC 74 ms
71,416 KB
testcase_18 AC 77 ms
71,496 KB
testcase_19 AC 76 ms
71,368 KB
testcase_20 AC 75 ms
71,372 KB
testcase_21 AC 77 ms
71,492 KB
testcase_22 AC 78 ms
71,368 KB
testcase_23 AC 74 ms
71,568 KB
testcase_24 AC 74 ms
71,416 KB
testcase_25 AC 77 ms
71,700 KB
testcase_26 AC 78 ms
71,164 KB
testcase_27 AC 74 ms
71,184 KB
testcase_28 AC 76 ms
71,372 KB
testcase_29 AC 79 ms
71,552 KB
testcase_30 AC 75 ms
71,164 KB
testcase_31 AC 75 ms
71,372 KB
testcase_32 AC 75 ms
71,384 KB
testcase_33 AC 74 ms
71,480 KB
testcase_34 AC 77 ms
71,164 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from math import gcd

a, b, c, d = map(int, input().split())
if abs(gcd(a, b)) != abs(gcd(c, d)):
    print(-1)
    exit()


def solve(x, y):
    ans = []
    while x != 0 and y != 0:
        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

    if y == 0:
        ans.append((2, 1))
        ans.append((1, -1))
        x, y = y, x

    if y < 0:
        ans.append((1, 1))
        ans.append((2, -2))
        ans.append((1, 1))
        
    return ans

A = solve(a, b)
B = solve(c, d)

rev = [(1, 1), (2, -2), (1, 1)]
ans = A[:]

for t, b_ in B[::-1]:
    ans.append((t, -b_))

print(len(ans))
for row in ans:
    print(*row)


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

assert (x, y) == (c, d), ((x, y), (c, d))
0