結果

問題 No.1298 OR XOR
ユーザー norioc
提出日時 2024-08-06 01:08:51
言語 Elixir
(1.18.1)
結果
AC  
実行時間 576 ms / 2,000 ms
コード長 722 bytes
コンパイル時間 6,106 ms
コンパイル使用メモリ 60,744 KB
実行使用メモリ 54,476 KB
最終ジャッジ日時 2024-08-06 01:09:07
合計ジャッジ時間 11,759 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 13
権限があれば一括ダウンロードができます

ソースコード

diff #

defmodule Main do
  def input, do: IO.read(:line) |> String.trim
  def ii, do: input() |> String.to_integer
  def li, do: input() |> String.split |> Enum.map(&String.to_integer/1)
  def yn(b), do: IO.puts(if b, do: "Yes", else: "No")

  import Bitwise, only: [bxor: 2, &&&: 2, >>>: 2]

  def bin(n), do: :io_lib.format("~.2b", [n])

  # 最下位ビット
  def lsb(x), do: x &&& -x

  def main do
    n = ii()

    if bit_count(n) == 1 do
      IO.puts "#{-1} #{-1} #{-1}"
    else
      b = lsb(n)
      x = bxor(n, b)
      IO.puts "#{n} #{b} #{x}"
    end
  end

  def bit_count(0), do: 0
  def bit_count(x) do
    if (x &&& 1) == 1 do
      1 + bit_count(x >>> 1)
    else
      bit_count(x >>> 1)
    end
  end

end
0