結果

問題 No.64 XORフィボナッチ数列
ユーザー 14番14番
提出日時 2016-04-08 02:37:08
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 28 ms / 5,000 ms
コード長 2,747 bytes
コンパイル時間 892 ms
コンパイル使用メモリ 112,092 KB
実行使用メモリ 27,988 KB
最終ジャッジ日時 2024-04-14 22:27:24
合計ジャッジ時間 2,011 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
26,160 KB
testcase_01 AC 27 ms
23,964 KB
testcase_02 AC 28 ms
24,244 KB
testcase_03 AC 27 ms
27,988 KB
testcase_04 AC 27 ms
24,092 KB
testcase_05 AC 28 ms
23,836 KB
testcase_06 AC 28 ms
23,972 KB
testcase_07 AC 27 ms
24,492 KB
testcase_08 AC 28 ms
24,348 KB
testcase_09 AC 28 ms
25,276 KB
testcase_10 AC 28 ms
25,404 KB
testcase_11 AC 28 ms
25,536 KB
testcase_12 AC 26 ms
26,080 KB
testcase_13 AC 28 ms
25,280 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;
using System.Collections.Generic;
using System.Text;

public class Program
{
    public void Proc(){
        
        Reader.IsDebug = false;
        
        string[] inpt = Reader.ReadLine().Split(' ');
        
        long[] numList = new long[100000000];
        numList[0] = long.Parse(inpt[0]);
        numList[1] = long.Parse(inpt[1]);

        long lastIdx = long.Parse(inpt[2]);
        
        Dictionary<long, long> dic = new Dictionary<long, long>();
        
        long i = 2;
        while (i <= lastIdx)
        {
            int idx = (int)(i % numList.Length);
            int idx1 = idx - 1;
            int idx2 = idx - 2;
            if(idx1 < 0) {
                idx1 = numList.Length - 1;
                idx2 = idx1 - 1;
            }
            if(idx2 < 0) {
                idx2 = numList.Length - 1;
            }
            long newNum = numList[idx2]^numList[idx1];
            if(dic.ContainsKey(newNum)) {
                 long loopLen = dic[newNum] - i;
                 long tmp = (lastIdx - i) % loopLen;
                 i = lastIdx - tmp;
                 idx = (int)(i % numList.Length);
                 long tmp1 = numList[idx1];
                 idx1 = idx - 1;
                 if(idx1 < 0) {
                     idx1 = numList.Length - 1;
                 }
                 numList[idx1] = tmp1;
            } else
            {
                dic.Add(newNum, i);
            }
            numList[idx] = newNum;

            i++;
        }
        
        Console.WriteLine(numList[(int)(lastIdx % numList.Length)]);
        
        
                
    }
    
    
    
    public static void Main(string[] args)
    {
        Program prg = new Program();
        prg.Proc();
    }
}

class Reader
{
    public static bool IsDebug = true;
    
    private static System.IO.StringReader sr;
    
    public static string ReadLine() {
        if(IsDebug) {
            if(sr == null) {
                sr = new System.IO.StringReader(initStr.Trim());
            }
            return sr.ReadLine();
        } else {
            return Console.ReadLine();
        }
    }
    
    public static int[] GetInt(char delimiter = ' ', bool mustTrim = false) {
        string src = ReadLine();
        if(mustTrim) {
            src = src.Trim();
        }
        string[] inpt = src.Split(delimiter);
        int[] ret = new int[inpt.Length];
        for(int i=0; i<inpt.Length; i++) {
            string item = inpt[i];
            if(mustTrim) {
                item = item.Trim();
            }
            ret[i] = int.Parse(item);
        }
        return ret;
    }
    
    private static string initStr = @"

720562261715868625 644575869710016571 169747221609816093



";
}

0