結果
| 問題 |
No.1017 Reiwa Sequence
|
| ユーザー |
|
| 提出日時 | 2020-04-10 14:07:53 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
(最新)
J_TLE
(最初)
|
| 実行時間 | - |
| コード長 | 1,890 bytes |
| コンパイル時間 | 1,457 ms |
| コンパイル使用メモリ | 171,088 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-07-03 08:42:54 |
| 合計ジャッジ時間 | 29,771 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 41 WA * 9 |
ソースコード
#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_V = 312345;
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 = 150000; 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;
}