結果

問題 No.1017 Reiwa Sequence
ユーザー finefine
提出日時 2020-04-04 00:38:10
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 432 ms / 2,000 ms
コード長 1,132 bytes
コンパイル時間 1,629 ms
コンパイル使用メモリ 174,084 KB
実行使用メモリ 44,080 KB
最終ジャッジ日時 2023-09-16 05:10:11
合計ジャッジ時間 19,331 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 5 ms
5,356 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 11 ms
19,868 KB
testcase_13 AC 10 ms
19,400 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 3 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 7 ms
4,380 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 395 ms
29,640 KB
testcase_20 AC 415 ms
29,692 KB
testcase_21 AC 420 ms
29,720 KB
testcase_22 AC 406 ms
29,740 KB
testcase_23 AC 340 ms
29,628 KB
testcase_24 AC 322 ms
29,676 KB
testcase_25 AC 289 ms
29,636 KB
testcase_26 AC 262 ms
29,644 KB
testcase_27 AC 236 ms
20,980 KB
testcase_28 AC 292 ms
23,632 KB
testcase_29 AC 8 ms
5,896 KB
testcase_30 AC 11 ms
6,280 KB
testcase_31 AC 30 ms
7,988 KB
testcase_32 AC 136 ms
17,332 KB
testcase_33 AC 7 ms
5,428 KB
testcase_34 AC 124 ms
17,332 KB
testcase_35 AC 3 ms
5,092 KB
testcase_36 AC 4 ms
5,124 KB
testcase_37 AC 143 ms
17,312 KB
testcase_38 AC 3 ms
5,096 KB
testcase_39 AC 155 ms
17,308 KB
testcase_40 AC 432 ms
44,012 KB
testcase_41 AC 385 ms
43,952 KB
testcase_42 AC 407 ms
44,080 KB
testcase_43 AC 388 ms
43,936 KB
testcase_44 AC 15 ms
19,400 KB
testcase_45 AC 383 ms
43,944 KB
testcase_46 AC 340 ms
44,028 KB
testcase_47 AC 263 ms
44,008 KB
testcase_48 AC 18 ms
19,536 KB
testcase_49 AC 18 ms
19,436 KB
testcase_50 AC 17 ms
19,412 KB
testcase_51 AC 1 ms
4,380 KB
testcase_52 AC 333 ms
29,408 KB
testcase_53 AC 60 ms
11,224 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

using ll = long long;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    int n = min(N, 22);
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }

    vector<int> dp(1 << n, 0);
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < (1 << i); ++j) {
            dp[j | (1 << i)] = dp[j] + a[i];
        }
    }

    map<int, int> memo;
    int cand1 = -1, cand2 = -1;
    for (int i = 0; i < (1 << n); ++i) {
        if (memo.find(dp[i]) != memo.end()) {
            cand1 = memo[dp[i]];
            cand2 = i;
            break;
        }
        memo[dp[i]] = i;
    }

    if (cand1 == -1) {
        cout << "No\n";
        return 0;
    }

    int is = cand1 & cand2;
    cand1 ^= is;
    cand2 ^= is;

    cout << "Yes\n";
    for (int i = 0; i < N; ++i) {
        if (i >= n) cout << 0;
        else {
            if (cand1 >> i & 1) cout << a[i];
            else if (cand2 >> i & 1) cout << -a[i];
            else cout << 0;
        }
        cout << " \n"[i + 1 == N];
    }
    return 0;
}
0