結果

問題 No.4 おもりと天秤
ユーザー Rumain831
提出日時 2025-05-03 01:38:42
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 514 bytes
コンパイル時間 1,123 ms
コンパイル使用メモリ 75,112 KB
実行使用メモリ 6,272 KB
最終ジャッジ日時 2025-05-03 01:38:44
合計ジャッジ時間 2,142 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
using namespace std;

int main(void){
  int n; cin >> n;
  vector<int> w(n);
  int sum=0;
  for(int i=0; i<n; i++) cin >> w[i], sum+=w[i]; 
  if(sum%2){
    cout << "impossible" << endl; return 0;
  }
  vector<bool> dp(sum+1, false);
  dp[0]=true;
  for(int i=0; i<n; i++){
    vector<bool> old(sum+1, false);
    swap(old, dp);
    for(int j=0; j<=sum; j++){
      if(old[j]) dp[j]=dp[j+w[i]]=true;
    }
  }
  cout << (dp[sum/2]?"possible":"impossible") << endl;
  return 0;
}
0