結果

問題 No.1017 Reiwa Sequence
ユーザー knshnbknshnb
提出日時 2020-04-06 18:00:28
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
(最新)
J_TLE  
(最初)
実行時間 -
コード長 1,877 bytes
コンパイル時間 2,171 ms
コンパイル使用メモリ 204,636 KB
実行使用メモリ 425,540 KB
最終ジャッジ日時 2023-09-16 06:52:53
合計ジャッジ時間 25,163 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 80 ms
150,712 KB
testcase_01 AC 56 ms
108,468 KB
testcase_02 AC 43 ms
87,460 KB
testcase_03 AC 133 ms
234,960 KB
testcase_04 AC 44 ms
87,368 KB
testcase_05 AC 68 ms
129,720 KB
testcase_06 AC 56 ms
108,592 KB
testcase_07 AC 44 ms
87,300 KB
testcase_08 AC 45 ms
87,356 KB
testcase_09 AC 177 ms
298,248 KB
testcase_10 AC 278 ms
424,984 KB
testcase_11 AC 159 ms
277,272 KB
testcase_12 AC 280 ms
424,856 KB
testcase_13 AC 279 ms
424,824 KB
testcase_14 AC 158 ms
277,216 KB
testcase_15 AC 174 ms
298,332 KB
testcase_16 AC 161 ms
277,320 KB
testcase_17 AC 208 ms
340,712 KB
testcase_18 AC 161 ms
277,228 KB
testcase_19 AC 284 ms
424,928 KB
testcase_20 AC 287 ms
424,864 KB
testcase_21 AC 290 ms
425,088 KB
testcase_22 AC 289 ms
424,824 KB
testcase_23 AC 281 ms
424,860 KB
testcase_24 AC 265 ms
424,868 KB
testcase_25 AC 280 ms
424,840 KB
testcase_26 AC 261 ms
424,936 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 291 ms
424,860 KB
testcase_30 AC 288 ms
424,948 KB
testcase_31 AC 285 ms
424,940 KB
testcase_32 WA -
testcase_33 AC 254 ms
424,880 KB
testcase_34 WA -
testcase_35 AC 249 ms
424,940 KB
testcase_36 AC 285 ms
424,860 KB
testcase_37 WA -
testcase_38 AC 251 ms
424,812 KB
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 AC 261 ms
425,140 KB
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 AC 295 ms
425,392 KB
testcase_49 AC 265 ms
425,392 KB
testcase_50 AC 266 ms
425,540 KB
testcase_51 AC 33 ms
66,324 KB
testcase_52 WA -
testcase_53 AC 257 ms
424,976 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;
            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