結果
| 問題 |
No.1017 Reiwa Sequence
|
| ユーザー |
ocat
|
| 提出日時 | 2020-04-04 17:20:30 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,108 bytes |
| コンパイル時間 | 1,744 ms |
| コンパイル使用メモリ | 178,348 KB |
| 実行使用メモリ | 68,420 KB |
| 最終ジャッジ日時 | 2024-07-03 07:31:58 |
| 合計ジャッジ時間 | 12,474 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 8 TLE * 1 -- * 41 |
ソースコード
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll = long long;
int main() {
int N;
cin >> N;
vector<int> A(N);
for (int i=0; i<N; ++i) cin >> A[i];
int M = min(N, 22);
vector<int> dp(1<<M, 0);
for (int i=1; i<=M; ++i) {
int l = 1 << (i-1);
int r = 1 << i;
for (int j=l; j<r; ++j) {
dp[j] = dp[j - l] + A[i-1];
}
}
int S = -1, T;
map<int,int> mp;
for (int i=1; i<(1<<M); ++i) {
if (mp.count(dp[i])) {
S = mp[dp[i]];
T = i;
}
mp[dp[i]] = i;
}
if (S < 0) {
cout << "No" << endl;
} else {
vector<int> ans = A;
for (int i=0; i<M; ++i) {
bool sb = (S >> i) & 1;
bool tb = (T >> i) & 1;
if ( ! (sb ^ tb)) ans[i] = 0;
else if (sb) ans[i] *= -1;
else if (tb) ans[i] *= 1;
}
cout << "Yes" << endl;
for (int i=0; i<N; ++i) {
cout << ans[i] << (i == N-1 ? "\n" : " ");
}
}
return 0;
}
ocat