結果
| 問題 |
No.64 XORフィボナッチ数列
|
| コンテスト | |
| ユーザー |
14番
|
| 提出日時 | 2016-04-08 02:37:08 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
AC
|
| 実行時間 | 29 ms / 5,000 ms |
| コード長 | 2,747 bytes |
| コンパイル時間 | 943 ms |
| コンパイル使用メモリ | 114,564 KB |
| 実行使用メモリ | 26,076 KB |
| 最終ジャッジ日時 | 2024-10-04 02:38:11 |
| 合計ジャッジ時間 | 2,135 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 11 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
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
";
}
14番