結果

問題 No.1017 Reiwa Sequence
ユーザー minato
提出日時 2020-04-19 19:31:20
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 469 ms / 2,000 ms
コード長 1,455 bytes
コンパイル時間 2,117 ms
コンパイル使用メモリ 185,536 KB
実行使用メモリ 28,672 KB
最終ジャッジ日時 2024-07-03 09:00:06
合計ジャッジ時間 41,806 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 50
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
#define ln '\n'
constexpr long long MOD = 1000000007LL;
//constexpr long long MOD = 998244353LL;
typedef long long ll;
typedef unsigned long long ull; 
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
template<class T, class U> inline bool chmax(T &a, U b) { if (a < b) { a = b; return true;} return false; }
template<class T, class U> inline bool chmin(T &a, U b) { if (a > b) { a = b; return true;} return false; }
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int N; cin >> N;
    vector<int> A(N);
    rep(i,N) cin >> A[i];

    int M = min(N,22);
    vector<int> ans(N);
    map<int, int> dic;
    for (int mask = 1; mask < (1<<M); mask++) {
        int val = 0;
        rep(i,M) {
            if (mask&(1<<i)) val += A[i];
        }
        if (dic.count(val)) {
            int num = dic[val];
            rep(i,M) {
                if (mask&(1<<i)) ans[i] = A[i];
                if (num&(1<<i)) ans[i] = -A[i];
            }
            cout << "Yes" << ln;
            for (auto i : ans) cout << i << " ";
            cout << ln;
            return 0;
        } else dic.emplace(val,mask);
    }

    cout << "No" << ln;
}
0