結果

問題 No.64 XORフィボナッチ数列
ユーザー Yoshitada IkedaYoshitada Ikeda
提出日時 2023-01-15 08:59:46
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 16 ms / 5,000 ms
コード長 1,421 bytes
コンパイル時間 111 ms
コンパイル使用メモリ 10,912 KB
実行使用メモリ 8,400 KB
最終ジャッジ日時 2023-08-27 16:53:58
合計ジャッジ時間 1,107 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
8,376 KB
testcase_01 AC 16 ms
8,272 KB
testcase_02 AC 16 ms
8,236 KB
testcase_03 AC 16 ms
8,284 KB
testcase_04 AC 15 ms
8,368 KB
testcase_05 AC 15 ms
8,400 KB
testcase_06 AC 15 ms
8,380 KB
testcase_07 AC 16 ms
8,328 KB
testcase_08 AC 15 ms
8,392 KB
testcase_09 AC 15 ms
8,296 KB
testcase_10 AC 15 ms
8,304 KB
testcase_11 AC 15 ms
8,272 KB
testcase_12 AC 15 ms
8,248 KB
testcase_13 AC 15 ms
8,296 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def to2(num):
    bList = []
    if num == 0:
        return [0]

    while num > 0:
        bList.append(num % 2)
        num = num // 2
    
    return bList

def to10(numList):
    r = 0
    n = len(numList)
    for i in range(n):
        r = r + numList[i] * (2 ** i)
    return r

def xorList(f0List, f1List, num):
    len0 = len(f0List)
    len1 = len(f1List)
    length = 0
    if len0 > len1:
        length = len0
        for i in range(len0 - len1):
            f1List.append(0)

    elif len1 > len0:
        length = len1
        for i in range(len1 - len0):
            f0List.append(0)
    else:
        length = len0
    
    rList = []
    for i in range(length):
        if f0List[i] == 0 and f1List[i] == 0:
            rList.append(0)
        elif f0List[i] == 1 and f1List[i] == 0:
            if num % 3 == 1:
                rList.append(0)
            else:
                rList.append(1)
        elif f0List[i] == 0 and f1List[i] == 1:
            if num % 3 == 0:
                rList.append(0)
            else:
                rList.append(1)
        else:
            if num % 3 == 2:
                rList.append(0)
            else:
                rList.append(1)
    
    return rList

f0, f1, n = map(int, input().split())

rbList = []
if n == 0:
    r = f0
elif n == 1:
    r = f1
else:
    f0b = to2(f0)
    f1b = to2(f1)
    rList = xorList(f0b, f1b, n)
    r = to10(rList)

print(r)
0