結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 78 ms
15,260 KB
testcase_01 AC 78 ms
15,248 KB
testcase_02 AC 79 ms
15,172 KB
testcase_03 AC 78 ms
15,284 KB
testcase_04 AC 80 ms
15,224 KB
testcase_05 AC 78 ms
15,144 KB
testcase_06 AC 78 ms
15,284 KB
testcase_07 AC 76 ms
15,072 KB
testcase_08 AC 78 ms
15,228 KB
testcase_09 AC 77 ms
15,012 KB
testcase_10 AC 78 ms
15,068 KB
testcase_11 AC 77 ms
15,092 KB
testcase_12 AC 77 ms
15,084 KB
testcase_13 AC 78 ms
15,132 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

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

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

    answer = ""

    63.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