結果
| 問題 |
No.1017 Reiwa Sequence
|
| ユーザー |
|
| 提出日時 | 2020-04-10 14:11:02 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 40 ms / 2,000 ms |
| コード長 | 1,924 bytes |
| コンパイル時間 | 1,490 ms |
| コンパイル使用メモリ | 171,980 KB |
| 実行使用メモリ | 10,484 KB |
| 最終ジャッジ日時 | 2024-07-03 08:43:31 |
| 合計ジャッジ時間 | 30,556 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 50 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}
int nextInt() { int x; scanf("%d", &x); return x;}
ll nextLong() { ll x; scanf("%lld", &x); return x;}
const int MAX_A = 150000;
const int MAX_V = 1500000;
int dp[MAX_V];
int main2() {
CLR(dp, -1);
int N = nextInt();
vector<int> a(N);
REP(i, N) a[i] = nextInt();
bool yes = false;
vector<int> s, t;
dp[0] = 0;
REP(i, N) {
for (int v = MAX_V - MAX_A; v >= 0; v--) {
if (dp[v] >= 0 && v + a[i] < MAX_V) {
if (dp[ v + a[i] ] != -1) {
yes = true;
{
int S = v + a[i];
while (S > 0) {
int p = dp[S];
s.push_back(p);
S -= a[p];
}
}
{
t.push_back(i);
int S = v;
while (S > 0) {
int p = dp[S];
t.push_back(p);
S -= a[p];
}
}
goto END;
} else {
dp[ v + a[i] ] = i;
}
}
}
}
END:
if (yes) {
cout << "Yes" << endl;
vector<int> ans(N);
for (int x : s) ans[x]--;
for (int x : t) ans[x]++;
bool first = true;
REP(i, N) {
if (first) { first = false; } else printf(" ");
printf("%d", ans[i] * a[i]);
}
printf("\n");
} else {
cout << "No" << endl;
}
return 0;
}
int main() {
#ifdef LOCAL
for (;!cin.eof();cin>>ws)
#endif
main2();
return 0;
}