結果

問題 No.1017 Reiwa Sequence
ユーザー MisterMister
提出日時 2020-04-03 22:01:44
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 67 ms / 2,000 ms
コード長 1,222 bytes
コンパイル時間 911 ms
コンパイル使用メモリ 129,048 KB
実行使用メモリ 20,016 KB
最終ジャッジ日時 2024-04-23 14:40:36
合計ジャッジ時間 33,007 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
18,784 KB
testcase_01 AC 7 ms
18,764 KB
testcase_02 AC 6 ms
18,720 KB
testcase_03 AC 6 ms
18,760 KB
testcase_04 AC 7 ms
18,764 KB
testcase_05 AC 6 ms
18,720 KB
testcase_06 AC 7 ms
18,744 KB
testcase_07 AC 7 ms
18,736 KB
testcase_08 AC 6 ms
18,728 KB
testcase_09 AC 8 ms
18,676 KB
testcase_10 AC 8 ms
18,712 KB
testcase_11 AC 7 ms
18,712 KB
testcase_12 AC 8 ms
18,692 KB
testcase_13 AC 7 ms
18,768 KB
testcase_14 AC 8 ms
18,836 KB
testcase_15 AC 6 ms
18,680 KB
testcase_16 AC 6 ms
18,704 KB
testcase_17 AC 8 ms
18,692 KB
testcase_18 AC 6 ms
18,720 KB
testcase_19 AC 52 ms
18,764 KB
testcase_20 AC 50 ms
18,716 KB
testcase_21 AC 51 ms
18,704 KB
testcase_22 AC 50 ms
18,700 KB
testcase_23 AC 50 ms
18,760 KB
testcase_24 AC 50 ms
18,780 KB
testcase_25 AC 50 ms
18,784 KB
testcase_26 AC 51 ms
18,800 KB
testcase_27 AC 35 ms
18,792 KB
testcase_28 AC 39 ms
18,816 KB
testcase_29 AC 7 ms
18,680 KB
testcase_30 AC 8 ms
18,760 KB
testcase_31 AC 12 ms
18,784 KB
testcase_32 AC 28 ms
18,796 KB
testcase_33 AC 6 ms
18,716 KB
testcase_34 AC 28 ms
18,572 KB
testcase_35 AC 6 ms
18,836 KB
testcase_36 AC 6 ms
18,684 KB
testcase_37 AC 29 ms
18,756 KB
testcase_38 AC 7 ms
18,812 KB
testcase_39 AC 28 ms
18,744 KB
testcase_40 AC 67 ms
19,436 KB
testcase_41 AC 66 ms
19,508 KB
testcase_42 AC 66 ms
19,480 KB
testcase_43 AC 66 ms
19,516 KB
testcase_44 AC 20 ms
19,528 KB
testcase_45 AC 65 ms
19,440 KB
testcase_46 AC 64 ms
19,416 KB
testcase_47 AC 64 ms
19,392 KB
testcase_48 AC 30 ms
19,932 KB
testcase_49 AC 29 ms
20,016 KB
testcase_50 AC 31 ms
19,856 KB
testcase_51 AC 7 ms
18,692 KB
testcase_52 AC 48 ms
18,696 KB
testcase_53 AC 17 ms
18,696 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

constexpr int X = 4000000;

void solve() {
    int n;
    std::cin >> n;

    std::vector<int> xs(n);
    for (auto& x : xs) std::cin >> x;

    int m = std::min(n, 22);
    std::vector<int> idxs(X, -1), ss(n, 0);
    bool ok = false;

    for (int b = 0; b < (1 << m); ++b) {
        int s = 0;
        for (int i = 0; i < m; ++i) {
            if ((b >> i) & 1) s += xs[i];
        }

        if (idxs[s] == -1) {
            idxs[s] = b;
        } else {
            for (int i = 0; i < m; ++i) {
                if ((idxs[s] >> i) & 1) ss[i] = 1;
            }
            for (int i = 0; i < m; ++i) {
                if ((b >> i) & 1) {
                    ss[i] = (ss[i] == 1 ? 0 : -1);
                }
            }

            ok = true;
            break;
        }
    }

    if (!ok) {
        std::cout << "No" << std::endl;
    } else {
        std::cout << "Yes" << std::endl;
        for (int i = 0; i < n; ++i) std::cout << xs[i] * ss[i] << " ";
        std::cout << std::endl;
    }
}

int main() {
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
    std::ios::sync_with_stdio(false);

    solve();

    return 0;
}
0