結果

問題 No.4 おもりと天秤
コンテスト
ユーザー rsk0315
提出日時 2019-09-22 23:49:09
言語 C++17
(gcc 15.3.0 + boost 1.92.0 + ACL)
コンパイル:
g++-15 -O2 -fplugin=/usr/lib/yukicoder/noavx512-gcc15.so -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 1 ms / 5,000 ms
+ 849µs
コード長 437 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 425 ms
コンパイル使用メモリ 84,348 KB
実行使用メモリ 9,916 KB
最終ジャッジ日時 2026-10-24 03:59:11
合計ジャッジ時間 2,103 ms
ジャッジサーバーID
(参考情報)
judge4_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <cstdio>
#include <cstdint>
#include <vector>
#include <algorithm>
#include <bitset>
#include <numeric>

int main() {
  size_t n;
  scanf("%zu", &n);

  std::vector<int> a(n);
  for (auto& ai: a) scanf("%d", &ai);
  int s = std::accumulate(a.begin(), a.end(), 0);
  if (s & 1) return puts("impossible"), 0;

  std::bitset<10001> dp;
  dp.set(0);
  for (auto ai: a) dp |= (dp << ai);

  puts(dp[s/2]? "possible": "impossible");
}
0