結果
| 問題 |
No.1017 Reiwa Sequence
|
| ユーザー |
kyort0n
|
| 提出日時 | 2020-04-04 05:02:08 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 1,360 ms / 2,000 ms |
| コード長 | 1,650 bytes |
| コンパイル時間 | 1,816 ms |
| コンパイル使用メモリ | 183,176 KB |
| 実行使用メモリ | 107,392 KB |
| 最終ジャッジ日時 | 2024-07-19 16:49:17 |
| 合計ジャッジ時間 | 49,969 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 50 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
if(a < b) {
a = b;
return true;
}
return false;
}
template<class T>
inline bool chmin(T &a, T b) {
if(a > b) {
a = b;
return true;
}
return false;
}
const long double EPS = 1e-10;
const long long INF = 1e18;
const long double PI = acos(-1.0L);
//const ll mod = 1000000007;
map<ll, vector<ll>> mp;
int main() {
//cout.precision(10);
cin.tie(0);
ios::sync_with_stdio(false);
ll N;
cin >> N;
vector<ll> A(N), ans(N);
vector<l_l> v(N);
for(int i = 0; i < N; i++) {
cin >> A[i];
v[i] = {A[i], i};
}
sort(v.begin(), v.end());
for(int i = 0; i < (1LL << min(N, 30LL)); i++) {
ll sum = 0;
for(int j = 0; j <= min(N, 30LL); j++) {
if(i & (1 << j)) sum += v[j].first;
}
if(mp.count(sum)) {
for(int j = 0; j <= min(N, 30LL); j++) {
if(i & (1 << j)) ans[v[j].second] += v[j].first;
}
for(auto tmp : mp[sum]) {
ans[tmp] -= A[tmp];
}
cout << "Yes" << endl;
for(int i = 0; i < N; i++) {
if(i != 0) cout << " ";
cout << ans[i];
}
cout << endl;
return 0;
} else {
for(int j = 0; j <= min(N, 30LL); j++) {
if(i & (1 << j)) mp[sum].push_back(v[j].second);
}
}
}
cout << "No" << endl;
return 0;
}
kyort0n