結果

問題 No.1017 Reiwa Sequence
ユーザー satashunsatashun
提出日時 2020-05-15 01:53:08
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,527 bytes
コンパイル時間 2,101 ms
コンパイル使用メモリ 199,484 KB
実行使用メモリ 311,016 KB
最終ジャッジ日時 2023-09-16 08:43:22
合計ジャッジ時間 22,565 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 25 ms
26,040 KB
testcase_01 WA -
testcase_02 AC 11 ms
13,704 KB
testcase_03 AC 44 ms
42,332 KB
testcase_04 AC 12 ms
15,860 KB
testcase_05 AC 22 ms
28,016 KB
testcase_06 AC 17 ms
21,972 KB
testcase_07 AC 12 ms
15,880 KB
testcase_08 AC 12 ms
15,980 KB
testcase_09 AC 72 ms
104,556 KB
testcase_10 AC 183 ms
176,752 KB
testcase_11 AC 65 ms
97,696 KB
testcase_12 AC 273 ms
250,816 KB
testcase_13 AC 278 ms
255,348 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 197 ms
245,256 KB
testcase_28 AC 189 ms
237,112 KB
testcase_29 AC 204 ms
234,692 KB
testcase_30 AC 210 ms
243,780 KB
testcase_31 AC 189 ms
224,784 KB
testcase_32 AC 177 ms
222,940 KB
testcase_33 AC 136 ms
173,916 KB
testcase_34 AC 175 ms
242,816 KB
testcase_35 AC 163 ms
197,884 KB
testcase_36 AC 206 ms
244,748 KB
testcase_37 AC 170 ms
231,948 KB
testcase_38 AC 172 ms
221,392 KB
testcase_39 AC 183 ms
232,120 KB
testcase_40 AC 311 ms
299,620 KB
testcase_41 AC 334 ms
296,352 KB
testcase_42 AC 323 ms
311,016 KB
testcase_43 AC 304 ms
309,896 KB
testcase_44 AC 157 ms
127,148 KB
testcase_45 AC 292 ms
304,468 KB
testcase_46 AC 284 ms
305,460 KB
testcase_47 AC 276 ms
289,256 KB
testcase_48 AC 247 ms
211,320 KB
testcase_49 AC 161 ms
98,504 KB
testcase_50 AC 180 ms
127,444 KB
testcase_51 WA -
testcase_52 AC 158 ms
247,964 KB
testcase_53 AC 161 ms
183,444 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using pii = pair<int, int>;
template <class T>
using V = vector<T>;
template <class T>
using VV = V<V<T>>;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for (int i = m; i < (n); i++)
#define ALL(c) (c).begin(), (c).end()

constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }

template <class T, class U>
void chmin(T& t, const U& u) {
    if (t > u) t = u;
}
template <class T, class U>
void chmax(T& t, const U& u) {
    if (t < u) t = u;
}

template <class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
    os << "(" << p.first << "," << p.second << ")";
    return os;
}

template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "{";
    rep(i, v.size()) {
        if (i) os << ",";
        os << v[i];
    }
    os << "}";
    return os;
}

#ifdef LOCAL
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << H;
    debug_out(T...);
}
#define debug(...) \
    cerr << __LINE__ << " [" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl
#else
#define debug(...) (void(0))
#define dump(x) (void(0))
#endif

const int B = 150000 * 11 + 5;
const int SZ = B * 2;

bool dp[24][SZ];
int pre[24][SZ];

int main() {
    dp[0][B] = 1;
    int N;
    cin >> N;
    V<int> A(N), ans(N);
    rep(i, N) { cin >> A[i]; }
    int now = 0;
    rep(i, min(N, 23)) {
        rep(j, SZ) {
            if (dp[i][j]) {
                if (j + A[i] < SZ) {
                    dp[i + 1][j + A[i]] = 1;
                    pre[i + 1][j + A[i]] = j;
                }
                dp[i + 1][j] = 1;
                pre[i + 1][j] = j;
                if (j - A[i] >= 0) {
                    dp[i + 1][j - A[i]] = 1;
                    pre[i + 1][j - A[i]] = j;
                }
            }
        }
        now++;
    }

    if (!dp[now][B]) {
        puts("No");
        return 0;
    }

    int p = now, v = B;
    rep(t, now) {
        int nx = pre[p][v];
        --p;
        if (nx < v) {
            ans[p] = 1;
        } else if (nx > v) {
            ans[p] = -1;
        } else {
            ans[p] = 0;
        }
        v = nx;
    }

    puts("Yes");
    rep(i, N) { printf("%d%c", ans[i] * A[i], i == N - 1 ? '\n' : ' '); }

    return 0;
}
0