結果

問題 No.4 おもりと天秤
ユーザー rsk0315
提出日時 2019-09-22 23:49:09
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 437 bytes
コンパイル時間 678 ms
コンパイル使用メモリ 68,808 KB
最終ジャッジ日時 2025-01-07 19:00:34
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 23
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:10:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   10 |   scanf("%zu", &n);
      |   ~~~~~^~~~~~~~~~~
main.cpp:13:26: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   13 |   for (auto& ai: a) scanf("%d", &ai);
      |                     ~~~~~^~~~~~~~~~~

ソースコード

diff #

#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