結果
| 問題 |
No.195 フィボナッチ数列の理解(2)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-06-04 18:32:44 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,890 bytes |
| コンパイル時間 | 1,841 ms |
| コンパイル使用メモリ | 174,756 KB |
| 実行使用メモリ | 10,020 KB |
| 最終ジャッジ日時 | 2024-11-29 18:54:29 |
| 合計ジャッジ時間 | 32,930 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 13 WA * 5 TLE * 4 |
ソースコード
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef vector<double> Vec;
typedef vector<Vec> Mat;
typedef pair<ll,ll> P;
typedef pair<double,ll> Pd;
typedef priority_queue<P,vector<P>,greater<P>> P_queue;
typedef priority_queue<Pd,vector<Pd>,greater<Pd>> Pd_queue;
const ll MOD=998244353;
const ll mod=1000000007;
const ll INF=1e15;
const double DEL=1e-3;
vec dx={1,0,-1,0};
vec dy={0,1,0,-1};
#define REP(i,a,b) for(int i=(int)a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define mp make_pair
#define ALL(a) a.begin(),a.end()
#define SORT(a) sort(ALL(a))
#define U_ERASE(V) V.erase(unique(ALL(V)), V.end());
#define ADD(a,b) a=(a+b)%mod
#define CHECK cout<<"arrived"<<endl
vec A={1,0},B={0,1};
mat K={{1,1},{1,0}};
ll X,Y,Z,N;
ll Solving(ll a, ll x, ll n){
if(n<=0) return -1;
ll P=x-(a*A[n]);
if(P<B[n]) return -1;
if(P%B[n]) return -1;
return P/B[n];
}
bool hantei(ll a, ll b, ll x, ll y){
if(x>y) return hantei(a,b,y,x);
rep(i,N) {
if(a*A[i]+b*B[i]==x){
REP(j,i,N){
if(a*A[j]+b*B[j]==y) return true;
if(a*A[j]+b*B[j]>y) return false;
}
}
if(a*A[i]+b*B[i]>x) return false;
}
return false;
}
P Solve(){
REP(j,1,Y+1){
for(int i=N-1;i>=0;i--) {
ll A=Solving(j,X,i);
if(A>=0){
if(hantei(j,A,Y,Z)) return mp(j,A);
}
}
}
return mp(-1,-1);
}
int main(){
REP(i,2,120){
A.pb(A[i-1]+A[i-2]);
B.pb(B[i-1]+B[i-2]);
if(B[i]>1e9+10) break;
}
N=B.size();
cin>>X>>Y>>Z;
if(Y<X) swap(X,Y);
if(Z<Y) swap(Y,Z);
if(Y<X) swap(X,Y);
P ans=Solve();
if(ans.first<0) cout<<-1<<endl;
else cout<<ans.first<<' '<<ans.second<<endl;
}