結果

問題 No.64 XORフィボナッチ数列
ユーザー 👑 obakyanobakyan
提出日時 2019-03-31 21:07:13
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,343 bytes
コンパイル時間 737 ms
コンパイル使用メモリ 75,696 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-05-02 01:11:34
合計ジャッジ時間 1,085 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 1 ms
5,376 KB
testcase_12 AC 1 ms
5,376 KB
testcase_13 AC 1 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstdlib>
#include <cstddef>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <iostream>
#include <iomanip>

int main(void)
{
	long f0, f1, n;
	std::cin >> f0 >> f1 >> n;
    std::vector<long> v0, v1;
    while(0 < f0){
        v0.push_back(f0 % 2);
        f0 /= 2;
    }
    while(0 < f1){
        v1.push_back(f1 % 2);
        f1 /= 2;
    }
    if(v0.size() < v1.size()){
        for(long i = v0.size(); i < (long)v1.size(); i++){
            v0.push_back(0);
        }
    } else if(v1.size() < v0.size()){
        for(long i = v1.size(); i < (long)v0.size(); i++){
            v1.push_back(0);
        }
    }
    long sz = v1.size();
    long res = 0;
    long mul = 1;
    for(long i = 0; i < sz; i++){
        // 1, 0, 1, 1, 0, ...
        // 0, 0, 0, ...
        long b0 = v0[i];
        long b1 = v1[i];
        if(b0  == 0){
            if(b1 == 1){
                if(n % 3 != 0){
                    res += mul;
                }
            }
        } else {
            if(b1 == 0){
                if(n % 3 != 1){
                    res += mul;
                }
            } else {
                if(n % 3 != 2){
                    res += mul;
                }
            }
        }
        mul *= 2;
    }
    std::cout << res << std::endl;
	return 0;
}

0