結果
問題 |
No.1017 Reiwa Sequence
|
ユーザー |
![]() |
提出日時 | 2020-04-03 23:19:52 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,540 bytes |
コンパイル時間 | 2,334 ms |
コンパイル使用メモリ | 202,160 KB |
最終ジャッジ日時 | 2025-01-09 13:46:01 |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 48 WA * 2 |
ソースコード
#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; }