結果

問題 No.1017 Reiwa Sequence
ユーザー ferinferin
提出日時 2020-04-03 23:09:37
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,046 bytes
コンパイル時間 2,344 ms
コンパイル使用メモリ 202,220 KB
実行使用メモリ 201,548 KB
最終ジャッジ日時 2023-09-16 04:25:46
合計ジャッジ時間 16,353 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 8 ms
15,576 KB
testcase_01 AC 6 ms
11,544 KB
testcase_02 AC 4 ms
7,460 KB
testcase_03 AC 13 ms
25,848 KB
testcase_04 AC 5 ms
9,568 KB
testcase_05 AC 11 ms
34,080 KB
testcase_06 AC 10 ms
32,088 KB
testcase_07 AC 4 ms
7,496 KB
testcase_08 AC 4 ms
7,544 KB
testcase_09 AC 49 ms
118,056 KB
testcase_10 AC 108 ms
185,116 KB
testcase_11 AC 41 ms
107,124 KB
testcase_12 AC 117 ms
197,476 KB
testcase_13 AC 117 ms
191,244 KB
testcase_14 AC 33 ms
108,444 KB
testcase_15 AC 35 ms
117,136 KB
testcase_16 AC 33 ms
104,736 KB
testcase_17 AC 42 ms
134,884 KB
testcase_18 AC 33 ms
106,332 KB
testcase_19 AC 60 ms
170,212 KB
testcase_20 AC 61 ms
173,460 KB
testcase_21 AC 60 ms
179,280 KB
testcase_22 AC 62 ms
180,280 KB
testcase_23 AC 60 ms
168,792 KB
testcase_24 AC 55 ms
177,652 KB
testcase_25 AC 57 ms
171,328 KB
testcase_26 AC 58 ms
185,796 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 60 ms
177,508 KB
testcase_31 AC 61 ms
185,704 KB
testcase_32 AC 62 ms
187,784 KB
testcase_33 AC 62 ms
189,740 KB
testcase_34 AC 56 ms
189,788 KB
testcase_35 AC 46 ms
142,604 KB
testcase_36 AC 58 ms
189,800 KB
testcase_37 AC 57 ms
189,916 KB
testcase_38 AC 54 ms
187,680 KB
testcase_39 AC 61 ms
185,792 KB
testcase_40 AC 78 ms
201,548 KB
testcase_41 AC 77 ms
191,360 KB
testcase_42 AC 76 ms
187,224 KB
testcase_43 AC 78 ms
195,256 KB
testcase_44 AC 50 ms
98,768 KB
testcase_45 AC 79 ms
201,540 KB
testcase_46 AC 78 ms
199,396 KB
testcase_47 AC 73 ms
181,248 KB
testcase_48 AC 93 ms
200,360 KB
testcase_49 AC 50 ms
56,792 KB
testcase_50 AC 60 ms
105,852 KB
testcase_51 AC 4 ms
9,468 KB
testcase_52 WA -
testcase_53 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<ll, ll>;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
template<typename T> void chmin(T &a, const T &b) { a = min(a, b); }
template<typename T> void chmax(T &a, const T &b) { a = max(a, b); }
struct FastIO {FastIO() { cin.tie(0); ios::sync_with_stdio(0); }}fastiofastio;
#ifdef DEBUG_ 
#include "../program_contest_library/memo/dump.hpp"
#else
#define dump(...)
#endif
const ll INF = 1LL<<60;

PII pre[21][300001][2];
bool dp[21][300001][2];
int main(void) {
    ll n;
    cin >> n;
    vector<ll> a(n);
    REP(i, n) cin >> a[i];

    bool ok = false;
    vector<ll> ans(n);

    dp[0][150000][0] = true;
    REP(i, min(n, 20LL)) REP(j, 300001) REP(k, 2) {
        if(!dp[i][j][k]) continue;
        // dump(i);
        if(j+a[i] <= 300000) {
            // dump(j+a[i], 1);
            dp[i+1][j+a[i]][1] = true;
            pre[i+1][j+a[i]][1] = PII(a[i], k);
            if(!ok && j+a[i] == 150000) {
                ok = true;
                ll ni = i+1, nj = j+a[i], nk = 1;
                while(ni > 0) {
                    dump(ni, nj, nk, pre[ni][nj][nk]);
                    ans[ni-1] = pre[ni][nj][nk].first;
                    // if(pre[ni][nj][nk].first > 0) {
                    //     ans[ni-1] = a[ni-1];
                    // } else if(pre[ni][nj][nk].first < 0) {
                    //     ans[ni-1] = -a[ni-1];
                    // } else {
                    //     ans[ni-1] = 0;
                    // }
                    ll nni = ni-1;
                    ll nnj = nj - pre[ni][nj][nk].first;
                    ll nnk = pre[ni][nj][nk].second;
                    ni = nni, nj = nnj, nk = nnk;
                }
            }
        }

        if(j-a[i] >= 0) {
            // dump(j-a[i], 1);
            dp[i+1][j-a[i]][1] = true;
            pre[i+1][j-a[i]][1] = PII(-a[i], k);
            if(!ok && j-a[i] == 150000) {
                ok = true;
                ll ni = i+1, nj = j-a[i], nk = 1;
                while(ni > 0) {
                    dump(ni, nj, nk, pre[ni][nj][nk]);
                    ans[ni-1] = pre[ni][nj][nk].first;
                    // if(pre[ni][nj][nk].first > 0) {
                    //     ans[ni-1] = a[ni-1];
                    // } else if(pre[ni][nj][nk].first < 0) {
                    //     ans[ni-1] = -a[ni-1];
                    // } else {
                    //     ans[ni-1] = 0;
                    // }
                    ll nni = ni-1;
                    ll nnj = nj - pre[ni][nj][nk].first;
                    ll nnk = pre[ni][nj][nk].second;
                    ni = nni, nj = nnj, nk = nnk;
                }
            }
        }

        // dump(j, k);
        dp[i+1][j][k] = true;
        pre[i+1][j][k] = PII(0, k);
    }

    if(ok) {
        cout << "Yes\n";
        REP(i, n) cout << ans[i] << (i==n-1 ? '\n' : ' ');
    } else {
        cout << "No\n";
    }

    return 0;
}
0