結果
| 問題 |
No.1017 Reiwa Sequence
|
| ユーザー |
ferin
|
| 提出日時 | 2020-04-03 23:15:52 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,358 bytes |
| コンパイル時間 | 2,105 ms |
| コンパイル使用メモリ | 196,804 KB |
| 最終ジャッジ日時 | 2025-01-09 13:42:06 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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> 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;
}
ferin