結果

問題 No.1243 約数加算
ユーザー simansiman
提出日時 2020-10-05 05:15:56
言語 Ruby
(3.3.0)
結果
TLE  
実行時間 -
コード長 477 bytes
コンパイル時間 507 ms
コンパイル使用メモリ 11,184 KB
実行使用メモリ 167,860 KB
最終ジャッジ日時 2023-09-27 01:34:47
合計ジャッジ時間 6,554 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 79 ms
15,256 KB
testcase_01 AC 81 ms
15,208 KB
testcase_02 AC 81 ms
15,104 KB
testcase_03 AC 83 ms
15,140 KB
testcase_04 AC 85 ms
15,456 KB
testcase_05 AC 88 ms
15,476 KB
testcase_06 AC 88 ms
15,356 KB
testcase_07 AC 83 ms
15,296 KB
testcase_08 AC 87 ms
15,424 KB
testcase_09 TLE -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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] }
  idx = 0

  while a[l] == 0
    if a[idx] == 1
      ans << 2.pow(idx)
      a += 2.pow(idx)
    end

    idx += 1
  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