結果

問題 No.2104 Multiply-Add
ユーザー kou_kkkkou_kkk
提出日時 2023-08-30 20:31:51
言語 Nim
(2.0.2)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,144 bytes
コンパイル時間 4,370 ms
コンパイル使用メモリ 72,916 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-30 20:31:58
合計ジャッジ時間 6,731 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 1 ms
4,380 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 1 ms
4,376 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 1 ms
4,376 KB
testcase_31 AC 1 ms
4,376 KB
testcase_32 AC 1 ms
4,376 KB
testcase_33 AC 1 ms
4,380 KB
testcase_34 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import algorithm, math, sequtils, strutils

proc pp(x, y: int): auto =
  (0 - x.pred div y, succ x.pred mod y)
proc mp(x, y: int): auto =
 let n = (x.abs.succ / y).ceil.int
 (n, x + y * n)
proc mm(x, y: int): auto =
  let n = 0 - (x.abs.succ / y.abs).ceil.int
  (n, x + y * n)

template t(name, v1, v2, cmd): untyped =
  block:
    (n, `v1`) = `name`(`v1`, `v2`)
    list.add [`cmd`, n]
    continue

proc minAndList(x, y: int): auto =
  var
    list: seq[array[2, int]]
    a = x
    b = y
  while a < 0 or a != b:
    var n: int
    if a == 0:
      a = abs b
      list.add [1, b.cmp 0]
      continue
    if b == 0:
      b = abs a
      list.add [2, a.cmp 0]
      continue
    if a < 0 and b < 0: t(mm, a, b, 1)
    if a < 0: t(mp, a, b, 1)
    if b < 0: t(mp, b, a, 2)
    if a > b: t(pp, a, b, 1)
    if a < b: t(pp, b, a, 2)
  (a, list)

var a, b, c, d: int
(a, b, c, d) = stdin.readLine.split.map parseInt

var
  (min1, list1) = minAndList(a, b)
  (min2, list2) = minAndList(c, d)

if min1 != min2:
  echo -1
  quit()

reverse list2
list2.applyIt [it[0], -it[1]]

let ans = list1 & list2
echo len ans
for xs in ans:
  echo xs.join " "
0