結果
| 問題 | No.4 おもりと天秤 | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2020-08-28 23:57:41 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 4 ms / 5,000 ms | 
| コード長 | 522 bytes | 
| コンパイル時間 | 1,658 ms | 
| コンパイル使用メモリ | 166,516 KB | 
| 実行使用メモリ | 6,820 KB | 
| 最終ジャッジ日時 | 2024-11-14 03:13:41 | 
| 合計ジャッジ時間 | 2,636 ms | 
| ジャッジサーバーID (参考情報) | judge2 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 23 | 
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < n; ++i)
using ll = long long;
const int SIZE=10000;
bool dp[SIZE+1];
int main() {
   int N;cin>>N;
   int sum=0;
   dp[0]=true;
   rep(i,N){
      int wi;cin>>wi;
      sum+=wi;
      for (int i = SIZE; i >= 0; i--)
      {
         if(i+wi>SIZE)continue;
         if(dp[i])dp[i+wi]=true;
      }
   }
   if(sum%2==1)cout<<"impossible"<<endl;
   else {
      if(dp[sum/2])cout<<"possible"<<endl;
      else cout<<"impossible"<<endl;
   }
}
            
            
            
        