結果

問題 No.1017 Reiwa Sequence
ユーザー Mayimg
提出日時 2020-04-06 00:41:47
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
RE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,039 bytes
コンパイル時間 1,948 ms
コンパイル使用メモリ 195,236 KB
最終ジャッジ日時 2025-01-09 14:29:32
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3 RE * 1
other AC * 36 RE * 14
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
vector<int> sum[3300003];
signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  int n;
  cin >> n;
  int m = min(22, n);
  vector<int> a(m);
  for (int i = 0; i < m; i++) cin >> a[i];
  for (int mask = 0; mask < (1 << m); mask++) {
    int s = 0;
    for (int i = 0; i < m; i++) if (mask & (1 << i)) s += a[i];
    sum[s].push_back(mask);
  }
  vector<int> ans(m);
  bool found = false;
  for (int t = 0; t <= 3300003; t++) {
    if ((int) sum[t].size() > 1) {
      for (int i = 0; i < m; i++) if (sum[t][0] & (1 << i)) ans[i] = 1;
      for (int i = 0; i < m; i++) if (sum[t][1] & (1 << i)) {
        if (ans[i] == 1) ans[i] = 0;
        else ans[i] = -1;
      }
      found = true;
      break;
    }
  }
  if (!found) {
    cout << "No\n";
    return 0;
  }
  cout << "Yes\n";
  for (int i = 0; i < m; i++) {
    if (i > 0) cout << " ";
    cout << ans[i] * a[i];
  }
  for (int i = m; i < n; i++) {
    cout << " " << 0;
  }
  cout << endl;
  return 0;
}
0