結果

問題 No.1017 Reiwa Sequence
ユーザー kappybarkappybar
提出日時 2020-04-06 21:29:20
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 764 ms / 2,000 ms
コード長 1,158 bytes
コンパイル時間 1,791 ms
コンパイル使用メモリ 177,824 KB
実行使用メモリ 69,168 KB
最終ジャッジ日時 2023-09-16 07:03:03
合計ジャッジ時間 24,568 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,384 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 4 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 6 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 3 ms
4,380 KB
testcase_15 AC 4 ms
4,376 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 11 ms
5,476 KB
testcase_18 AC 3 ms
4,380 KB
testcase_19 AC 629 ms
69,024 KB
testcase_20 AC 691 ms
68,868 KB
testcase_21 AC 689 ms
68,940 KB
testcase_22 AC 685 ms
68,940 KB
testcase_23 AC 586 ms
69,168 KB
testcase_24 AC 569 ms
69,024 KB
testcase_25 AC 534 ms
68,888 KB
testcase_26 AC 454 ms
69,168 KB
testcase_27 AC 405 ms
45,656 KB
testcase_28 AC 498 ms
52,764 KB
testcase_29 AC 9 ms
4,976 KB
testcase_30 AC 18 ms
6,404 KB
testcase_31 AC 52 ms
11,768 KB
testcase_32 AC 241 ms
36,140 KB
testcase_33 AC 6 ms
4,380 KB
testcase_34 AC 246 ms
36,092 KB
testcase_35 AC 2 ms
4,380 KB
testcase_36 AC 2 ms
4,376 KB
testcase_37 AC 282 ms
36,308 KB
testcase_38 AC 2 ms
4,380 KB
testcase_39 AC 270 ms
36,136 KB
testcase_40 AC 764 ms
69,076 KB
testcase_41 AC 676 ms
69,000 KB
testcase_42 AC 710 ms
68,968 KB
testcase_43 AC 693 ms
69,004 KB
testcase_44 AC 34 ms
4,376 KB
testcase_45 AC 669 ms
68,968 KB
testcase_46 AC 595 ms
69,152 KB
testcase_47 AC 484 ms
69,044 KB
testcase_48 AC 55 ms
4,380 KB
testcase_49 AC 53 ms
4,380 KB
testcase_50 AC 56 ms
4,376 KB
testcase_51 AC 1 ms
4,380 KB
testcase_52 AC 602 ms
68,376 KB
testcase_53 AC 105 ms
19,752 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
using ll =  long long ;
using P = pair<int,int> ;
const int INF = 1e9;
const int MOD = 1000000007;

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    int k = min(n,22);
    vector<bool> ans;
    int s_sum;
    bool ok = false;
    map<int,vector<bool>> sum;
    rep(bit,1<<k){
        int s = 0;
        vector<bool> flg(k,false);
        rep(i,k){
            if(bit >> i & 1){
                s += a[i];
                flg[i] = true;
            }
        }
        if(sum.find(s) == sum.end()) sum[s] = flg;
        else{
            ans = flg;
            s_sum = s;
            ok = true;
            break;
        }
    }
    if(!ok){
        cout << "No" << endl;
        return 0;
    }
    else{
        cout << "Yes" << endl;
    }

    rep(i,k){
        if(ans[i] && sum[s_sum][i]) a[i] = 0;
        else if(ans[i]);
        else if(sum[s_sum][i]) a[i] = -a[i];
        else a[i] = 0;
    }

    if(k != n){
        for(int i=k;i<n;i++) a[i] = 0;
    }

    rep(i,n) cout << a[i] << " ";
    cout << endl;

    return 0;
}
0