結果
問題 | No.1017 Reiwa Sequence |
ユーザー |
|
提出日時 | 2020-04-04 00:38:10 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 339 ms / 2,000 ms |
コード長 | 1,132 bytes |
コンパイル時間 | 1,528 ms |
コンパイル使用メモリ | 175,436 KB |
実行使用メモリ | 44,160 KB |
最終ジャッジ日時 | 2024-07-03 06:40:55 |
合計ジャッジ時間 | 34,584 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 50 |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int N; cin >> N; int n = min(N, 22); vector<int> a(n); for (int i = 0; i < n; ++i) { cin >> a[i]; } vector<int> dp(1 << n, 0); for (int i = 0; i < n; ++i) { for (int j = 0; j < (1 << i); ++j) { dp[j | (1 << i)] = dp[j] + a[i]; } } map<int, int> memo; int cand1 = -1, cand2 = -1; for (int i = 0; i < (1 << n); ++i) { if (memo.find(dp[i]) != memo.end()) { cand1 = memo[dp[i]]; cand2 = i; break; } memo[dp[i]] = i; } if (cand1 == -1) { cout << "No\n"; return 0; } int is = cand1 & cand2; cand1 ^= is; cand2 ^= is; cout << "Yes\n"; for (int i = 0; i < N; ++i) { if (i >= n) cout << 0; else { if (cand1 >> i & 1) cout << a[i]; else if (cand2 >> i & 1) cout << -a[i]; else cout << 0; } cout << " \n"[i + 1 == N]; } return 0; }