結果

問題 No.2104 Multiply-Add
ユーザー ShirotsumeShirotsume
提出日時 2022-10-22 00:44:45
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 76 ms / 2,000 ms
コード長 1,453 bytes
コンパイル時間 289 ms
コンパイル使用メモリ 87,204 KB
実行使用メモリ 71,800 KB
最終ジャッジ日時 2023-09-14 00:39:25
合計ジャッジ時間 4,798 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
71,432 KB
testcase_01 AC 72 ms
71,240 KB
testcase_02 AC 70 ms
71,388 KB
testcase_03 AC 72 ms
71,512 KB
testcase_04 AC 71 ms
71,460 KB
testcase_05 AC 71 ms
71,760 KB
testcase_06 AC 71 ms
71,388 KB
testcase_07 AC 70 ms
71,432 KB
testcase_08 AC 71 ms
71,436 KB
testcase_09 AC 73 ms
71,404 KB
testcase_10 AC 71 ms
71,456 KB
testcase_11 AC 76 ms
71,708 KB
testcase_12 AC 73 ms
71,384 KB
testcase_13 AC 72 ms
71,460 KB
testcase_14 AC 71 ms
71,600 KB
testcase_15 AC 71 ms
71,632 KB
testcase_16 AC 69 ms
71,440 KB
testcase_17 AC 70 ms
71,200 KB
testcase_18 AC 73 ms
71,412 KB
testcase_19 AC 71 ms
71,408 KB
testcase_20 AC 70 ms
71,800 KB
testcase_21 AC 71 ms
71,512 KB
testcase_22 AC 69 ms
71,588 KB
testcase_23 AC 72 ms
71,304 KB
testcase_24 AC 69 ms
71,512 KB
testcase_25 AC 71 ms
71,764 KB
testcase_26 AC 72 ms
71,280 KB
testcase_27 AC 72 ms
71,332 KB
testcase_28 AC 70 ms
71,728 KB
testcase_29 AC 71 ms
71,356 KB
testcase_30 AC 69 ms
71,200 KB
testcase_31 AC 70 ms
71,708 KB
testcase_32 AC 72 ms
71,500 KB
testcase_33 AC 72 ms
71,664 KB
testcase_34 AC 70 ms
71,424 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 and gcd(c, d) > 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