結果

問題 No.1017 Reiwa Sequence
ユーザー ocatocat
提出日時 2020-04-04 17:36:06
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 76 ms / 2,000 ms
コード長 1,286 bytes
コンパイル時間 2,376 ms
コンパイル使用メモリ 167,016 KB
実行使用メモリ 49,952 KB
最終ジャッジ日時 2023-09-16 06:01:47
合計ジャッジ時間 14,911 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 14 ms
49,268 KB
testcase_01 AC 15 ms
48,980 KB
testcase_02 AC 14 ms
49,032 KB
testcase_03 AC 14 ms
48,984 KB
testcase_04 AC 14 ms
49,036 KB
testcase_05 AC 15 ms
49,048 KB
testcase_06 AC 15 ms
48,984 KB
testcase_07 AC 15 ms
49,080 KB
testcase_08 AC 15 ms
48,988 KB
testcase_09 AC 14 ms
48,984 KB
testcase_10 AC 15 ms
49,200 KB
testcase_11 AC 15 ms
49,032 KB
testcase_12 AC 20 ms
48,968 KB
testcase_13 AC 20 ms
49,008 KB
testcase_14 AC 15 ms
49,104 KB
testcase_15 AC 14 ms
49,200 KB
testcase_16 AC 15 ms
48,984 KB
testcase_17 AC 15 ms
49,152 KB
testcase_18 AC 15 ms
49,108 KB
testcase_19 AC 17 ms
49,152 KB
testcase_20 AC 18 ms
48,988 KB
testcase_21 AC 18 ms
48,968 KB
testcase_22 AC 18 ms
49,068 KB
testcase_23 AC 20 ms
48,964 KB
testcase_24 AC 18 ms
49,024 KB
testcase_25 AC 17 ms
48,980 KB
testcase_26 AC 18 ms
49,072 KB
testcase_27 AC 17 ms
49,164 KB
testcase_28 AC 17 ms
48,980 KB
testcase_29 AC 16 ms
49,068 KB
testcase_30 AC 16 ms
49,088 KB
testcase_31 AC 17 ms
49,268 KB
testcase_32 AC 17 ms
48,984 KB
testcase_33 AC 15 ms
48,988 KB
testcase_34 AC 17 ms
49,036 KB
testcase_35 AC 16 ms
49,092 KB
testcase_36 AC 16 ms
48,988 KB
testcase_37 AC 17 ms
49,044 KB
testcase_38 AC 15 ms
48,992 KB
testcase_39 AC 17 ms
49,240 KB
testcase_40 AC 56 ms
49,372 KB
testcase_41 AC 56 ms
49,388 KB
testcase_42 AC 54 ms
49,644 KB
testcase_43 AC 55 ms
49,320 KB
testcase_44 AC 53 ms
49,312 KB
testcase_45 AC 54 ms
49,328 KB
testcase_46 AC 53 ms
49,368 KB
testcase_47 AC 53 ms
49,480 KB
testcase_48 AC 73 ms
49,952 KB
testcase_49 AC 72 ms
49,896 KB
testcase_50 AC 76 ms
49,884 KB
testcase_51 AC 15 ms
48,984 KB
testcase_52 AC 18 ms
48,984 KB
testcase_53 AC 15 ms
48,980 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll = long long;

const int DPMX = 4194304;
const int REVMX = 3300001;
ll dp[DPMX];
int rev[REVMX];

int main() {
    fill_n(dp, DPMX, 0);
    fill_n(rev, REVMX, -1);

    int N;
    cin >> N;
    vector<int> A(N);
    for (int i=0; i<N; ++i) cin >> A[i];

    int M = min(N, 22);
    for (int i=1; i<=M; ++i) {
        int l = 1 << (i-1);
        int r = 1 << i;
        for (int j=l; j<r; ++j) {
            dp[j] = dp[j - l] + A[i-1];
        }
    }

    int S = -1, T;
    for (int i=1; i<(1<<M); ++i) {
        if (rev[dp[i]] >= 0) {
            S = rev[dp[i]];
            T = i;
            break;
        }
        rev[dp[i]] = i;
    }

    if (S < 0) {
        cout << "No" << endl;
    } else {
        vector<int> ans(N, 0);
        for (int i=0; i<M; ++i) {
            bool sb = (S >> i) & 1;
            bool tb = (T >> i) & 1;
            if ( ! (sb ^ tb)) continue;
            else if (sb) ans[i] = A[i] * (-1);
            else if (tb) ans[i] = A[i];
        }
        cout << "Yes" << endl;
        for (int i=0; i<N; ++i) {
            cout << ans[i] << (i == N-1 ? "\n" : " ");
        }
        assert(accumulate(ans.begin(), ans.end(), 0) == 0);
    }
    return 0;
}
0