結果

問題 No.1243 約数加算
ユーザー simansiman
提出日時 2020-10-05 05:16:52
言語 Ruby
(3.3.0)
結果
AC  
実行時間 86 ms / 2,000 ms
コード長 446 bytes
コンパイル時間 58 ms
コンパイル使用メモリ 11,412 KB
実行使用メモリ 15,540 KB
最終ジャッジ日時 2023-09-27 01:34:56
合計ジャッジ時間 1,773 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 80 ms
15,084 KB
testcase_01 AC 84 ms
15,216 KB
testcase_02 AC 83 ms
15,292 KB
testcase_03 AC 82 ms
15,088 KB
testcase_04 AC 84 ms
15,428 KB
testcase_05 AC 86 ms
15,332 KB
testcase_06 AC 86 ms
15,540 KB
testcase_07 AC 84 ms
15,444 KB
testcase_08 AC 86 ms
15,392 KB
testcase_09 AC 80 ms
15,296 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:5: warning: assigned but unused variable - la
Syntax OK

ソースコード

diff #

T = gets.to_i

def solver(a, b)
  ans = []
  la = a.bit_length
  lb = b.bit_length

  l = [*0...lb].reverse.find { |i| a[i] != b[i] }

  l.times do |i|
    if a[i] == 1
      ans << 2.pow(i)
      a += 2.pow(i)
    end
  end

  (lb - 2).downto(0) do |i|
    if b[i] == 1 && a[i] == 0
      ans << 2.pow(i)
      a += 2.pow(i)
    end
  end

  puts ans.size
  puts ans.join(' ')
end

T.times do
  a, b = gets.split.map(&:to_i)

  solver(a, b)
end
0