結果

問題 No.643 Two Operations No.2
ユーザー maimai
提出日時 2018-02-02 21:51:54
言語 Ruby
(3.2.2)
結果
AC  
実行時間 84 ms / 2,000 ms
コード長 341 bytes
コンパイル時間 80 ms
コンパイル使用メモリ 11,284 KB
実行使用メモリ 15,260 KB
最終ジャッジ日時 2023-08-30 02:08:41
合計ジャッジ時間 2,034 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 82 ms
15,108 KB
testcase_01 AC 82 ms
15,128 KB
testcase_02 AC 81 ms
15,140 KB
testcase_03 AC 84 ms
15,260 KB
testcase_04 AC 81 ms
15,124 KB
testcase_05 AC 81 ms
15,164 KB
testcase_06 AC 81 ms
15,140 KB
testcase_07 AC 81 ms
15,124 KB
testcase_08 AC 81 ms
15,236 KB
testcase_09 AC 81 ms
15,168 KB
testcase_10 AC 80 ms
15,032 KB
testcase_11 AC 79 ms
15,224 KB
testcase_12 AC 81 ms
15,136 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

def ascan; gets.split.map(&:to_i);end

def solve(x, y, depth=0)
    return nil if depth > 4
    return 0 if x == y
    a = solve(y, x, depth+1)
    b = solve(x+y, x-y, depth+1)
    return nil if !a && !b
    return (a||b)+1 if !a || !b
    return [a,b].min+1
end

while cin = gets
    x,y = cin.split.map(&:to_i)
    p solve(x,y) || -1
end

0