結果
問題 |
No.1017 Reiwa Sequence
|
ユーザー |
|
提出日時 | 2020-04-06 17:55:01 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
MLE
|
実行時間 | - |
コード長 | 1,841 bytes |
コンパイル時間 | 2,326 ms |
コンパイル使用メモリ | 199,356 KB |
最終ジャッジ日時 | 2025-01-09 14:38:34 |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 6 MLE * 44 |
ソースコード
#include <bits/stdc++.h> // clang-format off using Int = long long; #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; }