結果
| 問題 |
No.195 フィボナッチ数列の理解(2)
|
| コンテスト | |
| ユーザー |
koyumeishi
|
| 提出日時 | 2015-05-25 23:52:11 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 2,230 bytes |
| コンパイル時間 | 692 ms |
| コンパイル使用メモリ | 85,892 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-07-06 08:32:34 |
| 合計ジャッジ時間 | 2,376 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 RE * 1 |
| other | AC * 14 WA * 1 RE * 7 |
ソースコード
#include <iostream>
#include <vector>
#include <cstdio>
#include <sstream>
#include <map>
#include <string>
#include <algorithm>
#include <queue>
#include <cmath>
#include <set>
#include <functional>
#include "assert.h"
using namespace std;
vector<long long> get_fibonacci_sequence(){
//fibonacci 1,1,2,3,5,...
vector<long long> f = {1,0,1,1};
for(int i=f.size(); f.back() < 1000000000; i++){
f.push_back( f[i-1] + f[i-2] );
}
return f;
}
/*
fi fi+1 0 | A x
fj fj+1 0 | B = y
fk fk+1 0 | 0 z
*/
pair<long long, long long> solver(long long x, long long y , vector<long long>& f, int i, int j){
long long p = f[i] * y - f[j] * x;
long long q = f[i] * f[j+1] - f[i+1] * f[j];
if(q == 0) return {1LL<<60, 1LL<<60};
if(p%q != 0) return {1LL<<60, 1LL<<60};
long long B = p/q;
if(B <= 0) return {1LL<<60, 1LL<<60};
long long s = x - f[i+1] * B;
if(f[i] == 0) return {1LL<<60, 1LL<<60};
if(s%f[i] != 0) return {1LL<<60, 1LL<<60};
long long A = s/f[i];
if(A <= 0) return {1LL<<60, 1LL<<60};
return {A,B};
}
int main(){
vector<long long> f = get_fibonacci_sequence();
long long x,y,z;
cin >> x >> y >> z;
pair<long long, long long> ans = {1LL<<60, 1LL<<60};
if(x==y && y==z){
assert(false);
for(int i=0; i<f.size()-1; i++){
pair<long long,long long> p;
p.first = 1;
long long s = x-f[i];
if(f[i+1] == 0) continue;
if(s%f[i+1] != 0) continue;
p.second = s/f[i+1];
if(p.second <= 0) continue;
//cerr << p.first << " " << p.second << endl;
for(int k=0; k<f.size()-1; k++){
for(int k=0; k<f.size()-1; k++){
if(f[k] * p.first + f[k+1] * p.second != z) continue;
ans = min(p, ans);
}
}
}
}else{
if(x==y){
swap(x,z);
}
for(int i=0; i<f.size()-1; i++){
for(int j=0; j<f.size()-1; j++){
auto p = solver(x,y, f, i,j);
if(p >= pair<long long, long long>{1LL<<60, 1LL<<60}) continue;
//cerr << p.first << " " << p.second << endl;
for(int k=0; k<f.size()-1; k++){
if(f[k] * p.first + f[k+1] * p.second != z) continue;
ans = min(p, ans);
}
}
}
}
if(ans >= pair<long long,long long>{1LL<<60, 1LL<<60}){
cout << -1 << endl;
}else{
cout << ans.first << " " << ans.second << endl;
}
return 0;
}
koyumeishi