結果

問題 No.1017 Reiwa Sequence
ユーザー knshnbknshnb
提出日時 2020-04-06 18:04:12
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 1,876 bytes
コンパイル時間 2,219 ms
コンパイル使用メモリ 203,700 KB
実行使用メモリ 519,504 KB
最終ジャッジ日時 2023-09-16 07:00:47
合計ジャッジ時間 28,404 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 91 ms
166,960 KB
testcase_01 AC 62 ms
120,068 KB
testcase_02 AC 50 ms
96,868 KB
testcase_03 AC 149 ms
260,916 KB
testcase_04 AC 49 ms
97,012 KB
testcase_05 AC 75 ms
143,704 KB
testcase_06 AC 61 ms
120,220 KB
testcase_07 AC 49 ms
96,816 KB
testcase_08 AC 50 ms
96,872 KB
testcase_09 AC 192 ms
331,212 KB
testcase_10 AC 356 ms
495,188 KB
testcase_11 AC 178 ms
307,700 KB
testcase_12 MLE -
testcase_13 MLE -
testcase_14 AC 174 ms
307,600 KB
testcase_15 AC 197 ms
331,208 KB
testcase_16 AC 172 ms
307,604 KB
testcase_17 AC 232 ms
378,096 KB
testcase_18 AC 176 ms
307,780 KB
testcase_19 AC 348 ms
495,280 KB
testcase_20 AC 353 ms
495,408 KB
testcase_21 AC 357 ms
495,268 KB
testcase_22 AC 358 ms
495,216 KB
testcase_23 AC 360 ms
495,280 KB
testcase_24 AC 329 ms
495,292 KB
testcase_25 AC 341 ms
495,196 KB
testcase_26 AC 321 ms
495,360 KB
testcase_27 AC 349 ms
495,216 KB
testcase_28 AC 344 ms
495,216 KB
testcase_29 AC 355 ms
495,348 KB
testcase_30 AC 351 ms
495,084 KB
testcase_31 AC 338 ms
495,244 KB
testcase_32 AC 326 ms
495,280 KB
testcase_33 AC 314 ms
495,284 KB
testcase_34 AC 317 ms
495,332 KB
testcase_35 AC 320 ms
495,304 KB
testcase_36 AC 356 ms
495,272 KB
testcase_37 AC 324 ms
495,148 KB
testcase_38 AC 315 ms
495,368 KB
testcase_39 AC 330 ms
495,308 KB
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 35 ms
73,380 KB
testcase_52 AC 324 ms
495,272 KB
testcase_53 AC 321 ms
495,292 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 = 20;
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