結果

問題 No.64 XORフィボナッチ数列
ユーザー simansiman
提出日時 2015-01-10 23:56:27
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 640 bytes
コンパイル時間 75 ms
コンパイル使用メモリ 11,552 KB
実行使用メモリ 15,344 KB
最終ジャッジ日時 2023-09-03 23:02:39
合計ジャッジ時間 2,333 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 82 ms
15,020 KB
testcase_01 AC 84 ms
15,060 KB
testcase_02 AC 84 ms
15,132 KB
testcase_03 AC 81 ms
15,128 KB
testcase_04 AC 83 ms
15,328 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 82 ms
15,340 KB
testcase_13 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

class A
  def initialize
    f0, f1, n = gets.chomp.split(' ').map(&:to_i)

    f0 = "%019b" % [f0]
    f1 = "%019b" % [f1]

    answer = ""

    18.downto(0) do |index|
      ch1 = f0[index]
      ch2 = f1[index]

      if ch1 == '0' && ch2 == '0'
        answer << '0'
      elsif ch1 == '0' && ch2 == '1'
        answer << ['1','0','1'][(n-2)%3]
      elsif ch1 == '1' && ch2 == '0'
        answer << ['1','1','0'][(n-2)%3]
      else
        answer << ['0','1','1'][(n-2)%3]
      end
    end

    if n == 0
      puts f0.to_i(2)
    elsif n == 1
      puts f1.to_i(2)
    else
      puts answer.reverse.to_i(2)
    end
  end
end

A.new
0