結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 13 ms
19,732 KB
testcase_01 AC 9 ms
13,588 KB
testcase_02 AC 7 ms
9,484 KB
testcase_03 AC 21 ms
32,096 KB
testcase_04 AC 6 ms
9,716 KB
testcase_05 AC 16 ms
42,288 KB
testcase_06 AC 11 ms
30,004 KB
testcase_07 AC 6 ms
9,564 KB
testcase_08 AC 7 ms
9,500 KB
testcase_09 AC 69 ms
224,604 KB
testcase_10 AC 141 ms
364,468 KB
testcase_11 AC 59 ms
195,868 KB
testcase_12 AC 180 ms
395,988 KB
testcase_13 AC 152 ms
395,992 KB
testcase_14 AC 61 ms
202,036 KB
testcase_15 AC 68 ms
224,540 KB
testcase_16 AC 62 ms
206,112 KB
testcase_17 AC 86 ms
263,492 KB
testcase_18 AC 60 ms
202,000 KB
testcase_19 AC 126 ms
361,760 KB
testcase_20 AC 131 ms
347,416 KB
testcase_21 AC 131 ms
363,800 KB
testcase_22 AC 129 ms
361,760 KB
testcase_23 AC 122 ms
351,520 KB
testcase_24 AC 115 ms
345,376 KB
testcase_25 AC 118 ms
333,120 KB
testcase_26 AC 119 ms
361,828 KB
testcase_27 AC 120 ms
355,616 KB
testcase_28 AC 122 ms
366,012 KB
testcase_29 AC 130 ms
365,892 KB
testcase_30 AC 129 ms
351,544 KB
testcase_31 AC 125 ms
359,732 KB
testcase_32 AC 126 ms
359,756 KB
testcase_33 AC 123 ms
357,756 KB
testcase_34 AC 115 ms
365,876 KB
testcase_35 AC 103 ms
323,004 KB
testcase_36 AC 126 ms
365,876 KB
testcase_37 AC 114 ms
361,904 KB
testcase_38 AC 112 ms
365,892 KB
testcase_39 AC 123 ms
361,980 KB
testcase_40 AC 154 ms
405,176 KB
testcase_41 AC 155 ms
387,496 KB
testcase_42 AC 155 ms
385,328 KB
testcase_43 AC 151 ms
401,044 KB
testcase_44 AC 87 ms
199,264 KB
testcase_45 AC 157 ms
405,180 KB
testcase_46 AC 157 ms
405,948 KB
testcase_47 AC 143 ms
371,172 KB
testcase_48 AC 168 ms
390,612 KB
testcase_49 AC 69 ms
73,064 KB
testcase_50 AC 97 ms
212,372 KB
testcase_51 AC 5 ms
9,716 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[22][600010][2];
bool dp[22][600010][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);

    const ll base = 300000;
    dp[0][base][0] = true;
    REP(i, min(n, 21LL)) REP(j, 600001) REP(k, 2) {
        if(!dp[i][j][k]) continue;
        if(j+a[i] <= 600000) {
            dp[i+1][j+a[i]][1] = true;
            pre[i+1][j+a[i]][1] = PII(a[i], k);
            if(!ok && j+a[i] == base) {
                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;
                    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) {
            dp[i+1][j-a[i]][1] = true;
            pre[i+1][j-a[i]][1] = PII(-a[i], k);
            if(!ok && j-a[i] == base) {
                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;
                    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