結果

問題 No.3162 Five Two Three
ユーザー Rubikun
提出日時 2025-05-23 19:57:31
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 3,324 bytes
コンパイル時間 1,949 ms
コンパイル使用メモリ 201,984 KB
実行使用メモリ 7,848 KB
最終ジャッジ日時 2025-05-23 19:57:42
合計ジャッジ時間 9,333 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 103 WA * 84
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pair<int,int>>
#define vll vector<pair<ll,ll>>
#define vvi vector<vector<int>>
#define vvl vector<vector<ll>>
#define vvii vector<vector<pair<int,int>>>
#define vvll vector<vector<pair<ll,ll>>>
#define vst vector<string>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define mkunique(x) sort(all(x));(x).erase(unique(all(x)),(x).end())
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=998244353,MAX=300005;
const ll INF=15LL<<55;

void check4(vl S){
    for(int i=1;i<=2;i++){
        if(abs(S[i-1]-S[i+1])!=S[i]) return;
    }
    cout<<4<<endl;
    for(ll x:S) cout<<x<<" ";
    cout<<endl;
    exit(0);
}

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll X,Y,Z;cin>>X>>Y>>Z;
    
    if(abs(X-Y)==Z){
        cout<<3<<endl;
        cout<<X<<" "<<Z<<" "<<Y<<endl;
        return 0;
    }
    check4({X,Z,abs(X+Z),Y});
    check4({X,Z,abs(X-Z),Y});
    check4({X,abs(Y+Z),Z,Y});
    check4({X,abs(Y-Z),Z,Y});
    
    for(ll K=5;K<=100;K++){
        if(X){
            ll L=0,R=X;
            while(R-L>1){
                ll M=(L+R)/2;
                vl S={X,M,X-M,X};
                for(int t=4;t<K;t++){
                    ll ne=S[t-1]+S[t-2];
                    chmin(ne,INF);
                    S.pb(ne);
                }
                if(S.back()>=Y) L=M;
                else R=M;
            }
            ll M=L;
            vl S={X,M,X-M,X};
            for(int t=4;t<K;t++){
                ll ne=S[t-1]+S[t-2];
                chmin(ne,INF);
                S.pb(ne);
            }
            bool a=false,b=false;
            for(int i=1;i<si(S)-1;i++){
                if(S[i]==Z) a=true;
            }
            if(S.back()==Y) b=true;
            if(a&&b){
                cout<<K<<endl;
                for(ll a:S) cout<<a<<" ";
                cout<<endl;
                return 0;
            }
        }
        
        {
            ll L=-1,R=Y+1;
            while(R-L>1){
                ll M=(L+R)/2;
                vl S={X,M};
                for(int t=2;t<K;t++){
                    ll ne=S[t-1]+S[t-2];
                    chmin(ne,INF);
                    S.pb(ne);
                }
                if(S.back()>=Y) R=M;
                else L=M;
            }
            //cout<<K<<" "<<R<<endl;
            ll M=R;
            vl S={X,M};
            for(int t=2;t<K;t++){
                ll ne=S[t-1]+S[t-2];
                chmin(ne,INF);
                S.pb(ne);
            }
            bool a=false,b=false;
            for(int i=1;i<si(S)-1;i++){
                if(S[i]==Z) a=true;
            }
            if(S.back()==Y) b=true;
            if(a&&b){
                cout<<K<<endl;
                for(ll a:S) cout<<a<<" ";
                cout<<endl;
                return 0;
            }
        }
    }
    
    cout<<-1<<"\n";
}


0