結果

問題 No.1017 Reiwa Sequence
ユーザー commycommy
提出日時 2022-09-19 01:00:29
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 55 ms / 2,000 ms
コード長 2,414 bytes
コンパイル時間 662 ms
コンパイル使用メモリ 81,744 KB
実行使用メモリ 17,188 KB
最終ジャッジ日時 2023-08-23 18:29:44
合計ジャッジ時間 13,084 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
15,928 KB
testcase_01 AC 7 ms
15,808 KB
testcase_02 AC 6 ms
15,812 KB
testcase_03 AC 7 ms
15,936 KB
testcase_04 AC 6 ms
15,888 KB
testcase_05 AC 7 ms
15,868 KB
testcase_06 AC 7 ms
15,936 KB
testcase_07 AC 6 ms
15,768 KB
testcase_08 AC 7 ms
15,812 KB
testcase_09 AC 7 ms
15,864 KB
testcase_10 AC 7 ms
15,932 KB
testcase_11 AC 7 ms
15,940 KB
testcase_12 AC 7 ms
15,868 KB
testcase_13 AC 6 ms
15,796 KB
testcase_14 AC 7 ms
15,928 KB
testcase_15 AC 8 ms
15,864 KB
testcase_16 AC 7 ms
15,840 KB
testcase_17 AC 8 ms
15,932 KB
testcase_18 AC 8 ms
15,936 KB
testcase_19 AC 42 ms
15,944 KB
testcase_20 AC 43 ms
15,876 KB
testcase_21 AC 42 ms
15,884 KB
testcase_22 AC 42 ms
15,868 KB
testcase_23 AC 42 ms
15,812 KB
testcase_24 AC 42 ms
15,836 KB
testcase_25 AC 42 ms
15,868 KB
testcase_26 AC 42 ms
15,892 KB
testcase_27 AC 30 ms
15,936 KB
testcase_28 AC 33 ms
15,932 KB
testcase_29 AC 8 ms
15,808 KB
testcase_30 AC 9 ms
15,864 KB
testcase_31 AC 12 ms
15,944 KB
testcase_32 AC 24 ms
15,888 KB
testcase_33 AC 7 ms
16,092 KB
testcase_34 AC 25 ms
15,808 KB
testcase_35 AC 6 ms
15,872 KB
testcase_36 AC 6 ms
15,900 KB
testcase_37 AC 24 ms
15,932 KB
testcase_38 AC 6 ms
15,772 KB
testcase_39 AC 24 ms
16,024 KB
testcase_40 AC 55 ms
16,668 KB
testcase_41 AC 55 ms
16,716 KB
testcase_42 AC 54 ms
16,656 KB
testcase_43 AC 55 ms
16,728 KB
testcase_44 AC 19 ms
16,596 KB
testcase_45 AC 54 ms
16,664 KB
testcase_46 AC 54 ms
16,536 KB
testcase_47 AC 52 ms
16,804 KB
testcase_48 AC 29 ms
17,184 KB
testcase_49 AC 27 ms
17,088 KB
testcase_50 AC 29 ms
17,188 KB
testcase_51 AC 7 ms
15,872 KB
testcase_52 AC 42 ms
15,808 KB
testcase_53 AC 16 ms
15,816 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <iostream>
#include <numeric>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
#include <limits>

#define rep(i, a, b) for (int i = int(a); i < int(b); i++)
using namespace std;
using ll = long long int;  // NOLINT
using P = pair<ll, ll>;

// clang-format off
#ifdef _DEBUG_
#define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; debug_print(__VA_ARGS__); } while(false)
template<typename T, typename... Ts> void debug_print(const T &t, const Ts &...ts) { cerr << t; ((cerr << ", " << ts), ...); cerr << endl; }
#else
#define dump(...) do{ } while(false)
#endif
template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }
template<typename T> bool chmin(T &a, const T& b) { if (a > b) {a = b; return true; } return false; }
template<typename T> bool chmax(T &a, const T& b) { if (a < b) {a = b; return true; } return false; }
template<typename T, typename... Ts> void print(const T& t, const Ts&... ts) { cout << t; ((cout << ' ' << ts), ...); cout << '\n'; }
template<typename... Ts> void input(Ts&... ts) { (cin >> ... >> ts); }
template<typename T> istream &operator,(istream &in, T &t) { return in >> t; }
struct Inf { template<typename T> constexpr operator T() { return numeric_limits<T>::max() / 2; } };
// clang-format on

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin, n;
    vector<int> a(n);
    rep(i, 0, n) {
        cin, a[i];
    }
    const int nmax = 22;  // 150000n > 2^n
    const int bits = 1 << min(nmax, n);

    vector<int> sum(150000 * nmax, 0);
    rep(bit, 0, bits) {
        int s = 0;
        rep(i, 0, nmax) {
            if ((bit >> i) & 1) {
                s += a[i];
            }
        }
        if (sum[s]) {
            vector<int> b(n, 0);
            rep(i, 0, nmax) {
                if ((sum[s] >> i) & 1) {
                    b[i] = a[i];
                }
            }
            rep(i, 0, nmax) {
                if ((bit >> i) & 1) {
                    b[i] = -a[i];
                }
            }
            print("Yes");
            rep(i, 0, n) {
                cout << b[i] << " \n"[i + 1 == n];
            }
            return 0;
        }
        sum[s] = bit;
    }

    print("No");
    return 0;
}
0