結果

問題 No.2104 Multiply-Add
ユーザー flygonflygon
提出日時 2022-10-21 23:42:57
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,174 bytes
コンパイル時間 299 ms
コンパイル使用メモリ 87,152 KB
実行使用メモリ 79,440 KB
最終ジャッジ日時 2023-09-13 23:49:33
合計ジャッジ時間 5,654 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,400 KB
testcase_01 AC 78 ms
71,172 KB
testcase_02 AC 75 ms
71,364 KB
testcase_03 AC 78 ms
71,692 KB
testcase_04 AC 79 ms
71,332 KB
testcase_05 AC 77 ms
71,492 KB
testcase_06 AC 76 ms
71,396 KB
testcase_07 AC 77 ms
71,408 KB
testcase_08 AC 75 ms
71,416 KB
testcase_09 AC 77 ms
71,392 KB
testcase_10 AC 75 ms
71,428 KB
testcase_11 AC 75 ms
71,668 KB
testcase_12 AC 75 ms
71,392 KB
testcase_13 AC 76 ms
71,372 KB
testcase_14 AC 74 ms
71,176 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 RE -
testcase_18 AC 77 ms
71,516 KB
testcase_19 AC 78 ms
71,428 KB
testcase_20 AC 80 ms
71,364 KB
testcase_21 AC 79 ms
71,452 KB
testcase_22 AC 78 ms
71,304 KB
testcase_23 AC 78 ms
71,528 KB
testcase_24 RE -
testcase_25 AC 75 ms
71,416 KB
testcase_26 AC 76 ms
71,368 KB
testcase_27 AC 78 ms
71,420 KB
testcase_28 AC 77 ms
71,208 KB
testcase_29 AC 76 ms
71,400 KB
testcase_30 AC 75 ms
71,352 KB
testcase_31 AC 77 ms
71,360 KB
testcase_32 AC 76 ms
71,220 KB
testcase_33 AC 74 ms
71,528 KB
testcase_34 AC 76 ms
71,504 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

a,b,c,d = map(int,input().split())
c,d,a,b = a,b,c,d
from math import gcd
if gcd(a,b) != gcd(c,d):
  print(-1)
  exit()
cd = [[c,d]]
ab = [[a,b]]

if c == 0 and d < 0:
  cd.append([abs(d),0])
  c, d = cd[-1]
elif c < 0 and d == 0:
  cd.append([0,abs(c)])
  c, d = cd[-1]
if a == 0 and b < 0:
  ab.append([abs(b),0])
  a,b = ab[-1]
elif a < 0 and b == 0:
  ab.append([0,abs(a)])
  a,b = ab[-1]

if c < 0:
  c = c + (abs(c)//abs(d)+1)*abs(d)
  cd.append([c,d])
if d < 0:
  d = d + (abs(d)//c+1)*c
  cd.append([c,d])
while c != 0 and d != 0:
  if c < d:
    d %= c
    cd.append([c,d])
  else:
    c %= d
    cd.append([c,d])
  
if a < 0:
  a = a + (abs(a)//abs(b)+1)*abs(b)
  ab.append([a,b])
if b < 0:
  b = b + (abs(b)//a+1)*a
  ab.append([a,b])
while a != 0 and b != 0:
  if a < b:
    b %= a
    ab.append([a,b])
  else:
    a %= b
    ab.append([a,b])
if ab[-1] == cd[-1]:
  ab.pop()
  cd += ab[::-1]
else:
  ab.append([max(ab[-1]), max(ab[-1])])
  cd += ab[::-1]
print(len(cd)-1)
for i in range(1,len(cd)):
  c,d = cd[i]
  if c == cd[i-1][0]:
    dd = cd[i-1][1]
    tmp = (d - dd)//c
    print(2, tmp)
  else:
    cc = cd[i-1][0]
    tmp = (c-cc)//d
    print(1, tmp)

0