結果

問題 No.2104 Multiply-Add
ユーザー tassei903tassei903
提出日時 2022-10-21 23:29:49
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,805 bytes
コンパイル時間 528 ms
コンパイル使用メモリ 86,956 KB
実行使用メモリ 71,484 KB
最終ジャッジ日時 2023-09-13 23:36:44
合計ジャッジ時間 5,371 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,384 KB
testcase_01 AC 74 ms
71,300 KB
testcase_02 AC 70 ms
71,248 KB
testcase_03 AC 72 ms
71,348 KB
testcase_04 AC 74 ms
71,472 KB
testcase_05 AC 72 ms
71,336 KB
testcase_06 AC 76 ms
71,296 KB
testcase_07 AC 72 ms
71,204 KB
testcase_08 AC 73 ms
70,992 KB
testcase_09 AC 73 ms
71,132 KB
testcase_10 AC 72 ms
71,332 KB
testcase_11 AC 72 ms
71,452 KB
testcase_12 AC 72 ms
71,252 KB
testcase_13 AC 73 ms
71,168 KB
testcase_14 AC 73 ms
71,416 KB
testcase_15 AC 73 ms
71,136 KB
testcase_16 AC 72 ms
71,300 KB
testcase_17 WA -
testcase_18 AC 73 ms
71,296 KB
testcase_19 AC 74 ms
71,464 KB
testcase_20 AC 74 ms
71,276 KB
testcase_21 AC 71 ms
71,484 KB
testcase_22 AC 70 ms
71,228 KB
testcase_23 AC 72 ms
71,208 KB
testcase_24 AC 71 ms
71,060 KB
testcase_25 AC 73 ms
71,328 KB
testcase_26 AC 73 ms
71,244 KB
testcase_27 AC 72 ms
71,368 KB
testcase_28 AC 72 ms
71,456 KB
testcase_29 AC 72 ms
71,248 KB
testcase_30 AC 72 ms
71,164 KB
testcase_31 AC 75 ms
71,392 KB
testcase_32 AC 74 ms
71,024 KB
testcase_33 AC 72 ms
71,476 KB
testcase_34 AC 76 ms
71,328 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = lambda :sys.stdin.readline()[:-1]
ni = lambda :int(input())
na = lambda :list(map(int,input().split()))
yes = lambda :print("yes");Yes = lambda :print("Yes");YES = lambda : print("YES")
no = lambda :print("no");No = lambda :print("No");NO = lambda : print("NO")
#######################################################################

A,B,C,D = na()
a,b,c,d = A,B,C,D
if a == 0 and b == 0:
    if c== 0 and d == 0:
        print(0)
    else:
        print(-1)
    exit()
elif c == 0 and d == 0:
    print(-1)
    exit()
l = []
r = []
if a != 0:
    if a > 0:
        k = (-b)//a + 1
        l.append((2, k))
    else:
        k = (b-a-1)//(-a)-1
        l.append((2, k))
    b += a * k
if b != 0:
    if b > 0:
        k = (-a)//b + 1
        l.append((1, k))
    else:
        k = (a-b-1)//(-b)-1
        l.append((1, k))
    a += b * k

if c != 0:
    if c > 0:
        k = (-d)//c + 1
        r.append((2, -k))
    else:
        k = (d-c-1)//(-c)-1
        r.append((2, -k))
    d += c * k
if d != 0:
    if d > 0:
        k = (-c)//d + 1
        r.append((1, -k))
    else:
        k = (c-d-1)//(-d)-1
        r.append((1, -k))
    c += d * k

def f(x,y):
    if x >= y:
        return x % y, y, x//y, 1
    return x, y % x, y//x, 2


while a and b:
    a, b, x, y = f(a, b)
    #print(a, b)
    l.append((y, -x))

if a == 0:
    l.append((1, 1))
    l.append((2, -1))
    a = b
    b = 0

while c and d:
    c, d, x, y = f(c, d)
    r.append((y, x))
    #print(c, d)
if c == 0:
    r.append((1, -1))
    r.append((2, 1))
    c = d
    d = 0

if a != c:
    print(-1)
    exit()
#print()
ans = l + r[::-1]
print(len(ans))
for i in ans:
    print(*i)
""" print()
x,y = A,B
for p, q in ans:
    print(x,y)
    if p == 1:
        x += y * q
    else:
        y += x * q
print(x, y) """
0