結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 24 ms
4,992 KB
testcase_01 WA -
testcase_02 AC 11 ms
5,060 KB
testcase_03 AC 41 ms
5,060 KB
testcase_04 AC 11 ms
5,064 KB
testcase_05 AC 21 ms
5,060 KB
testcase_06 AC 16 ms
5,064 KB
testcase_07 AC 11 ms
5,056 KB
testcase_08 AC 11 ms
5,060 KB
testcase_09 AC 76 ms
39,068 KB
testcase_10 AC 155 ms
114,328 KB
testcase_11 AC 66 ms
57,628 KB
testcase_12 AC 236 ms
188,048 KB
testcase_13 AC 216 ms
209,980 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 164 ms
255,140 KB
testcase_28 AC 159 ms
245,164 KB
testcase_29 AC 173 ms
247,388 KB
testcase_30 AC 179 ms
255,428 KB
testcase_31 AC 166 ms
234,916 KB
testcase_32 AC 149 ms
243,100 KB
testcase_33 AC 128 ms
198,044 KB
testcase_34 AC 141 ms
253,340 KB
testcase_35 AC 141 ms
255,160 KB
testcase_36 AC 172 ms
255,156 KB
testcase_37 AC 139 ms
245,224 KB
testcase_38 AC 141 ms
253,228 KB
testcase_39 AC 153 ms
245,400 KB
testcase_40 AC 248 ms
306,704 KB
testcase_41 AC 266 ms
304,456 KB
testcase_42 AC 283 ms
316,664 KB
testcase_43 AC 263 ms
314,564 KB
testcase_44 AC 176 ms
252,668 KB
testcase_45 AC 267 ms
318,820 KB
testcase_46 AC 259 ms
316,844 KB
testcase_47 AC 239 ms
314,760 KB
testcase_48 AC 241 ms
241,188 KB
testcase_49 AC 163 ms
98,600 KB
testcase_50 AC 199 ms
253,080 KB
testcase_51 WA -
testcase_52 AC 146 ms
255,320 KB
testcase_53 AC 149 ms
256,492 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;
                }
                if (dp[i + 1][j] == 0) {
                    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