結果

問題 No.1017 Reiwa Sequence
ユーザー hedwig100
提出日時 2020-04-05 18:22:39
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 1,214 ms / 2,000 ms
コード長 1,210 bytes
コンパイル時間 1,659 ms
コンパイル使用メモリ 172,692 KB
実行使用メモリ 129,444 KB
最終ジャッジ日時 2024-07-03 08:22:07
合計ジャッジ時間 52,729 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 50
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i ++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
const ll MOD = 1e9 + 7;
const ll INF = 1e10;
const vector<int> dy = {-1,0,1,0};
const vector<int> dx = {0,1,0,-1};

int main() {
    int k; cin >> k;
    int n = min(22,k);
    vector<int> a(k);
    rep(i,k) cin >> a[i];
    
    vector<vector<int>> tot(3300005);
    for (int bit = 0;bit < (1 << n); bit ++ ) {
        int tmp = 0;
        rep(i,n) {
            if ((bit>>i)&1) {
                tmp += a[i];
            }
        }
        tot[tmp].push_back(bit);
    }

    int p = 0,m = 0;
    for (int i = 1; i < 3300005; i++) {
        if (tot[i].size() > 1) {
            p = tot[i][0];
            m = tot[i][1];
            break;
        }
    }

    if (p == 0) {
        cout << "No" << endl;
        return 0;
    }

    for (int i = 0; i < n; i ++) {
        if ((p>>i)&1 && (m>>i)&1) a[i] = 0;
        else if ((p>>i)&1) continue;
        else if ((m>>i)&1) a[i] = -a[i];
        else a[i] = 0;
    }
    
    cout << "Yes" << endl;
    rep(i,n) cout << a[i] << ' ';
    rep(i,max(k - n,0)) cout << 0 << ' ';
    cout << '\n';
}
0