結果
| 問題 |
No.64 XORフィボナッチ数列
|
| コンテスト | |
| ユーザー |
omu
|
| 提出日時 | 2015-11-09 14:27:48 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 5,000 ms |
| コード長 | 594 bytes |
| コンパイル時間 | 713 ms |
| コンパイル使用メモリ | 75,396 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-09-13 14:14:57 |
| 合計ジャッジ時間 | 1,336 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 11 |
ソースコード
#include <vector>
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <utility>
#include <map>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
int main(){
ll f0,f1,N;
cin >> f0 >> f1 >> N;
if(N == 0){ cout << f0 << endl; return 0;}
if(N == 1){ cout << f1 << endl; return 0;}
vector<ll> f(1000,0);
f[0] = f0; f[1] = f1;
map<P,ll> mp;
for(int i = 2;i <= N;i++){
if(mp.count(P(f[i-1],f[i-2]))){
N %= (i - mp[P(f[i-1],f[i-2])]);
}
f[i] = f[i-1] ^ f[i-2];
mp[P(f[i-1],f[i-2])] = i;
}
cout << f[N] << endl;
return 0;
}
omu