結果

問題 No.1017 Reiwa Sequence
ユーザー knshnbknshnb
提出日時 2020-04-06 18:03:41
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
(最新)
J_TLE  
(最初)
実行時間 -
コード長 1,876 bytes
コンパイル時間 2,182 ms
コンパイル使用メモリ 205,168 KB
実行使用メモリ 622,544 KB
最終ジャッジ日時 2023-09-16 06:58:33
合計ジャッジ時間 28,721 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 99 ms
183,708 KB
testcase_01 AC 70 ms
132,024 KB
testcase_02 AC 52 ms
106,320 KB
testcase_03 AC 159 ms
286,556 KB
testcase_04 AC 54 ms
106,276 KB
testcase_05 AC 85 ms
157,776 KB
testcase_06 AC 68 ms
131,896 KB
testcase_07 AC 55 ms
106,364 KB
testcase_08 AC 53 ms
106,376 KB
testcase_09 AC 219 ms
363,992 KB
testcase_10 MLE -
testcase_11 AC 192 ms
338,528 KB
testcase_12 MLE -
testcase_13 MLE -
testcase_14 AC 194 ms
338,204 KB
testcase_15 AC 213 ms
364,060 KB
testcase_16 AC 194 ms
338,320 KB
testcase_17 AC 254 ms
415,520 KB
testcase_18 AC 193 ms
338,216 KB
testcase_19 MLE -
testcase_20 MLE -
testcase_21 MLE -
testcase_22 MLE -
testcase_23 MLE -
testcase_24 MLE -
testcase_25 MLE -
testcase_26 MLE -
testcase_27 MLE -
testcase_28 MLE -
testcase_29 MLE -
testcase_30 MLE -
testcase_31 MLE -
testcase_32 MLE -
testcase_33 MLE -
testcase_34 MLE -
testcase_35 MLE -
testcase_36 MLE -
testcase_37 MLE -
testcase_38 MLE -
testcase_39 MLE -
testcase_40 MLE -
testcase_41 MLE -
testcase_42 MLE -
testcase_43 MLE -
testcase_44 MLE -
testcase_45 MLE -
testcase_46 MLE -
testcase_47 MLE -
testcase_48 MLE -
testcase_49 MLE -
testcase_50 MLE -
testcase_51 AC 38 ms
80,288 KB
testcase_52 MLE -
testcase_53 MLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>  // clang-format off
using Int = int;
#define REP_(i, a_, b_, a, b, ...) for (Int i = (a), lim##i = (b); i < lim##i; i++)
#define REP(i, ...) REP_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
struct SetupIO { SetupIO() { std::cin.tie(nullptr), std::ios::sync_with_stdio(false), std::cout << std::fixed << std::setprecision(13); } } setup_io;
#ifndef _MY_DEBUG
#define dump(...)
#endif  // clang-format on

/**
 *    author:  knshnb
 *    created: Mon Apr  6 17:27:48 JST 2020
 **/

template <class T, class S> T make_vec(S x) { return x; }
template <class T, class... Ts> auto make_vec(size_t n, Ts... ts) {
    return std::vector<decltype(make_vec<T>(ts...))>(n, make_vec<T>(ts...));
}

const Int K = 22;
const Int S = K * 150001;
signed main() {
    Int n;
    std::cin >> n;
    std::vector<Int> a(n);
    REP(i, n) std::cin >> a[i];
    Int m = std::min(n, K);
    auto dp = make_vec<Int>(m + 1, 2 * S + 1, 0);
    dp[0][S] = 1;
    REP(i, m) {
        auto dp1 = dp[i].begin() + S, dp2 = dp[i + 1].begin() + S;
        REP(j, -S, S) {
            if (dp1[j] == 0) continue;
            dp1[j] = std::min(3, dp1[j]);
            dp2[j] += dp1[j];
            dp2[j + a[i]] += dp1[j];
            dp2[j - a[i]] += dp1[j];
        }
    }
    if (dp[m][S] == 1) {
        std::cout << "No" << std::endl;
        return 0;
    }
    Int curj = 0;
    std::vector<Int> b(n);
    for (int i = m - 1; i >= 0; i--) {
        auto dp1 = dp[i].begin() + S, dp2 = dp[i + 1].begin() + S;
        if (dp1[curj - a[i]] > 0) {
            b[i] = a[i];
            curj -= a[i];
        } else if (dp1[curj + a[i]] > 0) {
            b[i] = -a[i];
            curj += a[i];
        } else {
            b[i] = 0;
        }
    }
    assert(curj == 0);
    std::cout << "Yes" << std::endl;
    for (Int x : b) std::cout << x << " ";
    std::cout << std::endl;
}
0