結果

問題 No.2104 Multiply-Add
ユーザー 👑 KazunKazun
提出日時 2022-10-21 22:36:51
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 1,126 bytes
コンパイル時間 396 ms
コンパイル使用メモリ 86,344 KB
実行使用メモリ 831,968 KB
最終ジャッジ日時 2023-09-13 22:53:04
合計ジャッジ時間 7,945 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,308 KB
testcase_01 AC 72 ms
71,096 KB
testcase_02 AC 73 ms
70,808 KB
testcase_03 AC 73 ms
71,164 KB
testcase_04 AC 74 ms
71,296 KB
testcase_05 AC 72 ms
70,856 KB
testcase_06 AC 72 ms
71,316 KB
testcase_07 AC 73 ms
70,992 KB
testcase_08 AC 73 ms
71,120 KB
testcase_09 AC 72 ms
71,336 KB
testcase_10 AC 72 ms
71,164 KB
testcase_11 AC 74 ms
71,112 KB
testcase_12 AC 72 ms
71,116 KB
testcase_13 AC 73 ms
71,336 KB
testcase_14 AC 73 ms
70,856 KB
testcase_15 AC 72 ms
70,940 KB
testcase_16 AC 73 ms
71,152 KB
testcase_17 AC 73 ms
71,112 KB
testcase_18 AC 71 ms
71,168 KB
testcase_19 AC 72 ms
70,744 KB
testcase_20 AC 72 ms
70,732 KB
testcase_21 MLE -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

def operate(x,y,T):
        for t,k in T:
            if t==1:
                x+=k*y
            else:
                y+=k*x
        return x,y

def solve():
    from math import gcd

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

    if gcd(a,b)==0:
        print(0)
        return

    def euclid(a,b):
        res=[]
        while a and b:
            if abs(a)>abs(b):
                k=-a//b
                res.append((1,k))
                a+=k*b
            else:
                k=-(b//a)
                res.append((2,k))
                b+=k*a
        return res

    T1=euclid(a,b); a2,b2=operate(a,b,T1)
    T2=euclid(c,d); c2,d2=operate(c,d,T2)

    T3=[]
    if a2==0:
        a2,b2=b2,a2
        T3=[(1,1),(2,-1)]

    T4=[]
    if c2==0:
        c2,d2=d2,c2
        T4=[(1,1),(2,-1)]

    T5=[]
    if a2*c2<0:
        T5=[(2,-2),(1,1),(2,-2)]

    T2=[(t,-k) for t,k in T2][::-1]
    T4=[(t,-k) for t,k in T4][::-1]

    T=T1+T3+T5+T4+T2

    print(len(T))
    for t,k in T:
        print(t,k)

#==================================================
solve()
0