結果

問題 No.1017 Reiwa Sequence
ユーザー tempura_pptempura_pp
提出日時 2020-04-03 22:06:36
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,203 ms / 2,000 ms
コード長 1,920 bytes
コンパイル時間 1,166 ms
コンパイル使用メモリ 121,164 KB
実行使用メモリ 23,456 KB
最終ジャッジ日時 2023-09-16 01:54:24
合計ジャッジ時間 26,431 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 8 ms
22,488 KB
testcase_01 AC 8 ms
22,492 KB
testcase_02 AC 7 ms
22,524 KB
testcase_03 AC 9 ms
22,488 KB
testcase_04 AC 7 ms
22,492 KB
testcase_05 AC 8 ms
22,560 KB
testcase_06 AC 8 ms
22,548 KB
testcase_07 AC 7 ms
22,552 KB
testcase_08 AC 7 ms
22,556 KB
testcase_09 AC 8 ms
22,484 KB
testcase_10 AC 10 ms
22,508 KB
testcase_11 AC 9 ms
22,496 KB
testcase_12 AC 20 ms
22,504 KB
testcase_13 AC 48 ms
22,488 KB
testcase_14 AC 9 ms
22,548 KB
testcase_15 AC 7 ms
22,464 KB
testcase_16 AC 8 ms
22,512 KB
testcase_17 AC 8 ms
22,644 KB
testcase_18 AC 8 ms
22,484 KB
testcase_19 AC 15 ms
22,548 KB
testcase_20 AC 14 ms
22,472 KB
testcase_21 AC 13 ms
22,516 KB
testcase_22 AC 14 ms
22,532 KB
testcase_23 AC 13 ms
22,492 KB
testcase_24 AC 13 ms
22,528 KB
testcase_25 AC 14 ms
22,548 KB
testcase_26 AC 13 ms
22,532 KB
testcase_27 AC 11 ms
22,488 KB
testcase_28 AC 11 ms
22,420 KB
testcase_29 AC 10 ms
22,484 KB
testcase_30 AC 8 ms
22,416 KB
testcase_31 AC 9 ms
22,652 KB
testcase_32 AC 10 ms
22,452 KB
testcase_33 AC 8 ms
22,468 KB
testcase_34 AC 11 ms
22,544 KB
testcase_35 AC 9 ms
22,496 KB
testcase_36 AC 10 ms
22,492 KB
testcase_37 AC 12 ms
22,564 KB
testcase_38 AC 9 ms
22,492 KB
testcase_39 AC 10 ms
22,528 KB
testcase_40 AC 1,195 ms
22,748 KB
testcase_41 AC 1,191 ms
23,020 KB
testcase_42 AC 1,194 ms
22,992 KB
testcase_43 AC 1,193 ms
22,824 KB
testcase_44 AC 1,190 ms
23,008 KB
testcase_45 AC 1,193 ms
22,820 KB
testcase_46 AC 1,195 ms
23,016 KB
testcase_47 AC 1,192 ms
22,756 KB
testcase_48 AC 1,203 ms
23,456 KB
testcase_49 AC 1,200 ms
23,240 KB
testcase_50 AC 1,197 ms
23,444 KB
testcase_51 AC 7 ms
22,484 KB
testcase_52 AC 10 ms
22,528 KB
testcase_53 AC 10 ms
22,480 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
constexpr int inf=1e9+7;
constexpr ll longinf=1LL<<60 ;
constexpr ll mod=1e9+7 ;

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    vector<int> a(n);
    rep(i,n)cin>>a[i];
    int m = min(30,n);
    int ml = m/2, mr = (m+1)/2;
    vector<int> cnt(5000000,-1);
    int all = 1;
    rep(i,ml)all*=3;
    rep(i,all){
        int tmp = i;
        int s = 2500000;
        int k=0;
        while(tmp){
            int c=tmp%3;
            if(c==2)s-=a[k];
            if(c==1)s+=a[k];
            tmp/=3;
            ++k;
        }
        cnt[s]=i;
    }
    rep(i,mr-ml)all*=3;
    rep(i,all){
        int tmp = i;
        int s = 2500000;
        int k=ml;
        while(tmp){
            int c=tmp%3;
            if(c==2)s+=a[k];
            if(c==1)s-=a[k];
            tmp/=3;
            ++k;
        }
        if(cnt[s]!=-1 && (cnt[s]!=0 ||i!=0)){
            cout<<"Yes"<<endl;
            int t = cnt[s];
            rep(j,ml){
                int c=t%3;
                if(c==2)cout<<-a[j]<<" ";
                else if(c==1)cout<<a[j]<<" ";
                else cout<<"0 ";
                t/=3;
            }
            rep(j,mr){
                int c=i%3;
                if(c==2)cout<<-a[ml+j]<<" ";
                else if(c==1)cout<<a[ml+j]<<" ";
                else cout<<"0 ";
                i/=3;
            }
            rep(j,n-m)cout<<0<<" ";
            cout<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
    return 0;
}
0