結果

問題 No.4 おもりと天秤
ユーザー hanyu
提出日時 2020-12-26 00:54:29
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 6 ms / 5,000 ms
コード長 604 bytes
コンパイル時間 2,707 ms
コンパイル使用メモリ 198,676 KB
最終ジャッジ日時 2025-01-17 07:26:43
ジャッジサーバーID
(参考情報)
judge2 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main() {
  int n;
  cin >> n;
  
  vector<int> w(n);
  int sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> w.at(i);
    sum += w.at(i);
  }
  
  if (sum % 2 == 1) {
    cout << "impossible\n";
    return 0;
  }
  
  vector<vector<bool>> dp(n + 1, vector<bool>(10001, false));
  dp[0][0] = true;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 10001; j++) {
      if (!dp[i][j]) continue;
      dp[i + 1][j + w.at(i)] = true;
      dp[i + 1][j] = true;
    }
  }
  
  if (dp[n][sum / 2]) cout << "possible\n";
  else cout << "impossible\n";
}
0