結果

問題 No.1017 Reiwa Sequence
ユーザー knshnbknshnb
提出日時 2020-04-06 18:01:15
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,876 bytes
コンパイル時間 1,995 ms
コンパイル使用メモリ 204,680 KB
実行使用メモリ 471,428 KB
最終ジャッジ日時 2023-09-16 06:59:27
合計ジャッジ時間 25,591 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 85 ms
158,840 KB
testcase_01 AC 59 ms
114,216 KB
testcase_02 AC 47 ms
91,936 KB
testcase_03 AC 139 ms
247,996 KB
testcase_04 AC 47 ms
91,928 KB
testcase_05 AC 72 ms
136,584 KB
testcase_06 AC 60 ms
114,364 KB
testcase_07 AC 47 ms
92,020 KB
testcase_08 AC 46 ms
92,204 KB
testcase_09 AC 183 ms
314,720 KB
testcase_10 AC 311 ms
470,716 KB
testcase_11 AC 169 ms
292,368 KB
testcase_12 AC 311 ms
470,828 KB
testcase_13 AC 311 ms
470,780 KB
testcase_14 AC 165 ms
292,604 KB
testcase_15 AC 183 ms
314,656 KB
testcase_16 AC 168 ms
292,624 KB
testcase_17 AC 216 ms
359,200 KB
testcase_18 AC 167 ms
292,708 KB
testcase_19 AC 319 ms
470,712 KB
testcase_20 AC 322 ms
470,748 KB
testcase_21 AC 328 ms
470,740 KB
testcase_22 AC 325 ms
470,780 KB
testcase_23 AC 317 ms
470,692 KB
testcase_24 AC 299 ms
470,772 KB
testcase_25 AC 306 ms
470,736 KB
testcase_26 AC 292 ms
470,676 KB
testcase_27 AC 312 ms
470,704 KB
testcase_28 AC 310 ms
470,776 KB
testcase_29 AC 320 ms
470,740 KB
testcase_30 AC 324 ms
470,744 KB
testcase_31 AC 315 ms
470,712 KB
testcase_32 AC 300 ms
470,632 KB
testcase_33 AC 285 ms
470,716 KB
testcase_34 AC 289 ms
470,644 KB
testcase_35 AC 284 ms
470,768 KB
testcase_36 AC 318 ms
470,676 KB
testcase_37 AC 288 ms
470,740 KB
testcase_38 AC 281 ms
470,768 KB
testcase_39 AC 306 ms
470,772 KB
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 AC 284 ms
471,040 KB
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 AC 322 ms
471,268 KB
testcase_49 AC 294 ms
471,428 KB
testcase_50 AC 295 ms
471,276 KB
testcase_51 AC 34 ms
69,824 KB
testcase_52 AC 299 ms
470,824 KB
testcase_53 AC 296 ms
470,648 KB
権限があれば一括ダウンロードができます

ソースコード

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 = 19;
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