結果

問題 No.1017 Reiwa Sequence
ユーザー ferinferin
提出日時 2020-04-03 23:19:52
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,540 bytes
コンパイル時間 2,116 ms
コンパイル使用メモリ 209,432 KB
実行使用メモリ 365,904 KB
最終ジャッジ日時 2023-09-16 04:52:47
合計ジャッジ時間 17,066 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 12 ms
19,740 KB
testcase_01 AC 8 ms
13,716 KB
testcase_02 AC 6 ms
9,496 KB
testcase_03 AC 21 ms
32,104 KB
testcase_04 AC 6 ms
9,492 KB
testcase_05 AC 16 ms
42,376 KB
testcase_06 AC 11 ms
28,056 KB
testcase_07 AC 6 ms
9,480 KB
testcase_08 AC 6 ms
9,692 KB
testcase_09 AC 56 ms
167,252 KB
testcase_10 AC 111 ms
279,924 KB
testcase_11 AC 56 ms
191,772 KB
testcase_12 AC 137 ms
345,400 KB
testcase_13 AC 133 ms
331,116 KB
testcase_14 AC 46 ms
142,624 KB
testcase_15 AC 57 ms
175,508 KB
testcase_16 AC 52 ms
173,360 KB
testcase_17 AC 81 ms
245,024 KB
testcase_18 AC 53 ms
171,288 KB
testcase_19 AC 127 ms
341,312 KB
testcase_20 AC 124 ms
328,984 KB
testcase_21 AC 126 ms
355,616 KB
testcase_22 AC 122 ms
345,456 KB
testcase_23 AC 127 ms
359,360 KB
testcase_24 AC 126 ms
359,112 KB
testcase_25 AC 121 ms
357,708 KB
testcase_26 AC 130 ms
365,296 KB
testcase_27 AC 121 ms
318,764 KB
testcase_28 AC 127 ms
337,312 KB
testcase_29 AC 141 ms
331,160 KB
testcase_30 AC 119 ms
347,460 KB
testcase_31 AC 119 ms
329,024 KB
testcase_32 AC 116 ms
343,396 KB
testcase_33 AC 117 ms
343,376 KB
testcase_34 AC 111 ms
365,904 KB
testcase_35 AC 113 ms
365,256 KB
testcase_36 AC 112 ms
365,248 KB
testcase_37 AC 120 ms
357,776 KB
testcase_38 AC 121 ms
357,656 KB
testcase_39 AC 120 ms
357,668 KB
testcase_40 AC 71 ms
73,612 KB
testcase_41 AC 71 ms
73,700 KB
testcase_42 AC 71 ms
73,464 KB
testcase_43 AC 71 ms
73,576 KB
testcase_44 AC 66 ms
73,616 KB
testcase_45 AC 71 ms
73,568 KB
testcase_46 AC 71 ms
73,524 KB
testcase_47 AC 70 ms
73,580 KB
testcase_48 AC 83 ms
75,388 KB
testcase_49 AC 74 ms
75,380 KB
testcase_50 AC 101 ms
214,712 KB
testcase_51 AC 4 ms
9,516 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> p(n);
    REP(i, n) cin >> p[i];
    vector<PII> a(n);
    REP(i, n) a[i].first = p[i], a[i].second = i;
    sort(ALL(a));

    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].first <= 600000) {
            dp[i+1][j+a[i].first][1] = true;
            pre[i+1][j+a[i].first][1] = PII(a[i].first, k);
            if(!ok && j+a[i].first == base) {
                ok = true;
                ll ni = i+1, nj = j+a[i].first, nk = 1;
                while(ni > 0) {
                    dump(ni, nj, nk, pre[ni][nj][nk]);
                    ans[a[ni-1].second] = 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].first >= 0) {
            dp[i+1][j-a[i].first][1] = true;
            pre[i+1][j-a[i].first][1] = PII(-a[i].first, k);
            if(!ok && j-a[i].first == base) {
                ok = true;
                ll ni = i+1, nj = j-a[i].first, nk = 1;
                while(ni > 0) {
                    dump(ni, nj, nk, pre[ni][nj][nk]);
                    ans[a[ni-1].second] = 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