結果

問題 No.1017 Reiwa Sequence
ユーザー knshnbknshnb
提出日時 2020-04-06 17:58:37
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,835 bytes
コンパイル時間 2,249 ms
コンパイル使用メモリ 204,988 KB
実行使用メモリ 425,684 KB
最終ジャッジ日時 2023-09-16 06:54:09
合計ジャッジ時間 24,477 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 81 ms
150,640 KB
testcase_01 AC 56 ms
108,720 KB
testcase_02 AC 45 ms
87,388 KB
testcase_03 AC 132 ms
235,076 KB
testcase_04 AC 44 ms
87,356 KB
testcase_05 AC 69 ms
129,644 KB
testcase_06 AC 56 ms
108,428 KB
testcase_07 AC 45 ms
87,236 KB
testcase_08 AC 43 ms
87,292 KB
testcase_09 AC 176 ms
298,268 KB
testcase_10 AC 274 ms
424,860 KB
testcase_11 AC 157 ms
277,148 KB
testcase_12 AC 277 ms
424,988 KB
testcase_13 AC 281 ms
424,960 KB
testcase_14 AC 159 ms
277,224 KB
testcase_15 AC 173 ms
298,468 KB
testcase_16 AC 159 ms
277,280 KB
testcase_17 AC 208 ms
340,528 KB
testcase_18 AC 160 ms
277,160 KB
testcase_19 AC 276 ms
424,960 KB
testcase_20 AC 282 ms
424,976 KB
testcase_21 AC 290 ms
424,980 KB
testcase_22 AC 290 ms
425,072 KB
testcase_23 AC 275 ms
424,976 KB
testcase_24 AC 259 ms
424,980 KB
testcase_25 AC 269 ms
424,896 KB
testcase_26 AC 258 ms
424,988 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 284 ms
424,924 KB
testcase_30 AC 283 ms
425,040 KB
testcase_31 AC 275 ms
424,792 KB
testcase_32 WA -
testcase_33 AC 260 ms
424,888 KB
testcase_34 WA -
testcase_35 AC 251 ms
424,944 KB
testcase_36 AC 278 ms
424,952 KB
testcase_37 WA -
testcase_38 AC 255 ms
424,788 KB
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 AC 259 ms
425,452 KB
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 AC 299 ms
425,640 KB
testcase_49 AC 270 ms
425,684 KB
testcase_50 AC 269 ms
425,360 KB
testcase_51 AC 32 ms
66,328 KB
testcase_52 WA -
testcase_53 AC 257 ms
424,872 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 = 18;
const Int S = 18 * 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;
            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