結果

問題 No.1017 Reiwa Sequence
ユーザー sugarrrsugarrr
提出日時 2020-04-03 22:37:25
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 407 ms / 2,000 ms
コード長 4,217 bytes
コンパイル時間 2,542 ms
コンパイル使用メモリ 209,232 KB
実行使用メモリ 400,060 KB
最終ジャッジ日時 2023-09-16 03:33:47
合計ジャッジ時間 25,885 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 242 ms
355,064 KB
testcase_01 AC 220 ms
354,936 KB
testcase_02 AC 152 ms
355,200 KB
testcase_03 AC 153 ms
355,036 KB
testcase_04 AC 153 ms
354,936 KB
testcase_05 AC 153 ms
355,020 KB
testcase_06 AC 155 ms
354,896 KB
testcase_07 AC 152 ms
354,992 KB
testcase_08 AC 151 ms
354,900 KB
testcase_09 AC 155 ms
355,088 KB
testcase_10 AC 151 ms
355,060 KB
testcase_11 AC 152 ms
355,040 KB
testcase_12 AC 154 ms
355,832 KB
testcase_13 AC 152 ms
355,304 KB
testcase_14 AC 147 ms
355,048 KB
testcase_15 AC 152 ms
355,232 KB
testcase_16 AC 151 ms
355,164 KB
testcase_17 AC 162 ms
355,992 KB
testcase_18 AC 153 ms
355,096 KB
testcase_19 AC 407 ms
400,060 KB
testcase_20 AC 357 ms
399,972 KB
testcase_21 AC 370 ms
399,988 KB
testcase_22 AC 362 ms
399,960 KB
testcase_23 AC 353 ms
400,028 KB
testcase_24 AC 382 ms
399,952 KB
testcase_25 AC 357 ms
399,944 KB
testcase_26 AC 337 ms
399,948 KB
testcase_27 AC 197 ms
363,688 KB
testcase_28 AC 202 ms
366,092 KB
testcase_29 AC 179 ms
360,524 KB
testcase_30 AC 159 ms
357,292 KB
testcase_31 AC 176 ms
360,040 KB
testcase_32 AC 171 ms
359,880 KB
testcase_33 AC 150 ms
355,456 KB
testcase_34 AC 143 ms
355,220 KB
testcase_35 AC 145 ms
354,896 KB
testcase_36 AC 148 ms
354,988 KB
testcase_37 AC 143 ms
354,988 KB
testcase_38 AC 266 ms
376,444 KB
testcase_39 AC 160 ms
357,252 KB
testcase_40 AC 170 ms
361,828 KB
testcase_41 AC 170 ms
361,940 KB
testcase_42 AC 170 ms
361,660 KB
testcase_43 AC 175 ms
361,732 KB
testcase_44 AC 176 ms
361,792 KB
testcase_45 AC 179 ms
361,768 KB
testcase_46 AC 175 ms
361,708 KB
testcase_47 AC 174 ms
361,664 KB
testcase_48 AC 185 ms
358,452 KB
testcase_49 AC 174 ms
363,128 KB
testcase_50 AC 172 ms
358,452 KB
testcase_51 AC 149 ms
354,932 KB
testcase_52 AC 201 ms
365,252 KB
testcase_53 AC 385 ms
399,600 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
//#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
//#include "boost/multiprecision/cpp_int.hpp"
//typedef boost::multiprecision::cpp_int LL;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2

ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
typedef pair<dd,dd> d_d;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fi first
#define se second
#define endl "\n"
#define SORT(v) sort(v.begin(),v.end())
#define ERASE(v) v.erase(unique(v.begin(),v.end()),v.end())
#define POSL(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define POSU(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
//template<class T>void max(T a,T b){if(a<b)return b;else return a;}
//template<class T>void min(T a,T b){if(a>b)return b;else return a;}
//template<class T>bool Max(T&a, T b){if(a < b){a = b;return 1;}return 0;}
//template<class T>bool Min(T&a, T b){if(a > b){a = b;return 1;}return 0;}

//////////////////////////

#define M 15000005
vector<ll>fin[M];

vector<ll>X,Y;
ll ori[150005];
ll n;
void dfs(ll pos,vector<ll>v,ll sum){
    if(pos==n)return;
    if(X.size()>=1)return;
    dfs(pos+1,v,sum);
    if(X.size()>=1)return;
    v.pb(pos);
    ll newsum=sum+ori[pos];
    if(fin[newsum].size()>=1){
        X=v;
        Y=fin[newsum];
        return;
    }
    fin[newsum]=v;
    dfs(pos+1,v,newsum);
    if(X.size()>=1)return;
    v.pop_back();
}

int main(){fastio
    cin>>n;
    
    l_l a[n];
    rep(i,0,n-1){cin>>a[i].fi;a[i].se=i;ori[i]=a[i].fi;}
    sort(a,a+n);
    rep(i,0,n-2){
        if(a[i].fi==a[i+1].fi){
            ll x=a[i].se,y=a[i+1].se;
            cout<<"Yes"<<endl;
            rep(pos,0,n-1){
                if(pos==x)cout<<ori[pos]<<" ";
                else if(pos==y)cout<<-ori[pos]<<" ";
                else cout<<"0 ";
            }
            cout<<endl;
            return 0;
        }
    }
    
    if(n>=1000){
        ll N=300005;
        l_l dp[N];rep(i,0,N-1)dp[i]={-1,-1};
        rep(i,0,n-1){
            rep(j,i+1,n-1){
                ll c=ori[i]+ori[j];
                if(dp[c].fi!=-1){
                    cout<<"Yes"<<endl;
                    rep(pos,0,n-1){
                        if(pos==i||pos==j)cout<<ori[pos]<<" ";
                        else if(pos==dp[c].fi||pos==dp[c].se)cout<<-ori[pos]<<" ";
                        else cout<<"0 ";
                    }
                    cout<<endl;return 0;
                }
                dp[c]={i,j};
            }
        }
    }
    
    if(n>=100){
        ll ans[n];memset(ans,0,sizeof(ans));
        ll N=600005;
        vector<ll>dp[N];
        rep(i,0,n-1){
            rep(j,i+1,n-1){
                rep(k,j+1,n-1){
                    rep(l,k+1,n-1){
                        ll c=ori[i]+ori[j]+ori[k]+ori[l];
                        if(dp[c].size()>=1){
                            cout<<"Yes"<<endl;
                            for(auto x:dp[c]){
                                ans[x]++;
                            }
                            ans[i]--;ans[j]--;ans[k]--;ans[l]--;
                            
                            rep(pos,0,n-1){
                                cout<<ori[pos]*ans[pos]<<" ";
                            }cout<<endl;
                            return 0;
                        }
                        dp[c].pb(i);dp[c].pb(j);dp[c].pb(k);dp[c].pb(l);
                    }
                }
            }
        }
    }
    vector<ll>v;
    dfs(0,v,0);
    ll ans[n];memset(ans,0,sizeof(ans));

    if(X.size()>=1){
        cout<<"Yes"<<endl;
        for(auto x:X)ans[x]++;
        for(auto y:Y)ans[y]--;
        rep(pos,0,n-1){
            cout<<ori[pos]*ans[pos]<<" ";
        }cout<<endl;
        return 0;
    }
    cout<<"No"<<endl;
    
    return 0;
}
0