結果

問題 No.2104 Multiply-Add
ユーザー titiatitia
提出日時 2022-10-24 00:30:32
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 17 ms / 2,000 ms
コード長 1,058 bytes
コンパイル時間 455 ms
コンパイル使用メモリ 10,844 KB
実行使用メモリ 8,444 KB
最終ジャッジ日時 2023-09-15 08:22:03
合計ジャッジ時間 2,979 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
8,072 KB
testcase_01 AC 16 ms
8,444 KB
testcase_02 AC 16 ms
8,364 KB
testcase_03 AC 16 ms
8,144 KB
testcase_04 AC 16 ms
8,208 KB
testcase_05 AC 17 ms
8,028 KB
testcase_06 AC 17 ms
8,080 KB
testcase_07 AC 17 ms
8,112 KB
testcase_08 AC 16 ms
8,108 KB
testcase_09 AC 16 ms
8,120 KB
testcase_10 AC 17 ms
8,072 KB
testcase_11 AC 17 ms
8,112 KB
testcase_12 AC 16 ms
8,104 KB
testcase_13 AC 17 ms
8,036 KB
testcase_14 AC 16 ms
8,212 KB
testcase_15 AC 16 ms
8,208 KB
testcase_16 AC 16 ms
8,028 KB
testcase_17 AC 17 ms
8,140 KB
testcase_18 AC 17 ms
8,076 KB
testcase_19 AC 16 ms
8,144 KB
testcase_20 AC 16 ms
8,112 KB
testcase_21 AC 16 ms
8,076 KB
testcase_22 AC 16 ms
8,072 KB
testcase_23 AC 16 ms
8,204 KB
testcase_24 AC 16 ms
8,100 KB
testcase_25 AC 17 ms
8,380 KB
testcase_26 AC 17 ms
8,076 KB
testcase_27 AC 16 ms
8,288 KB
testcase_28 AC 17 ms
8,292 KB
testcase_29 AC 17 ms
8,408 KB
testcase_30 AC 16 ms
8,344 KB
testcase_31 AC 17 ms
8,284 KB
testcase_32 AC 16 ms
8,420 KB
testcase_33 AC 16 ms
8,332 KB
testcase_34 AC 17 ms
8,288 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

a,b,c,d=map(int,input().split())

if a==c and b==d:
    print(0)
    exit()

if a==b==0 or c==d==0:
    print(-1)
    exit()

X=[(a,b)]

while a!=0 and b!=0:
    if abs(a)>abs(b):
        a=a%b
        X.append((a,b))
    else:
        b=b%a
        X.append((a,b))
        

Y=[(c,d)]
while c!=0 and d!=0:
    if abs(c)>abs(d):
        c=c%d
        Y.append((c,d))
    else:
        d=d%c
        Y.append((c,d))

k=-1
for a in X[-1]:
    if a!=0:
        k=a

l=-1
for a in Y[-1]:
    if a!=0:
        l=a

if abs(k)!=abs(l):
    print(-1)
    exit()

if len(X)==1:
    X.append(X[-1])

if len(Y)==1:
    Y.append(Y[-1])

if X[-1]==Y[-1]:
    X=X+Y[::-1][1:]
else:
    X[-1]=(k,k)
    X.append((k,l))
    X.append((l,l))
    X=X+Y[::-1][1:]
    

ANS=[]

for i in range(len(X)-1):
    a,b=X[i]
    c,d=X[i+1]

    if a==c:
        x=(d-b)//a

        ANS.append((2,x))

    else:
        x=(c-a)//b

        ANS.append((1,x))

print(len(ANS))
for x,y in ANS:
    print(x,y)

        
        
        
        
    
0