結果
| 問題 | No.4 おもりと天秤 | 
| コンテスト | |
| ユーザー |  Fu_L | 
| 提出日時 | 2020-06-17 22:14:31 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 3 ms / 5,000 ms | 
| コード長 | 659 bytes | 
| コンパイル時間 | 1,615 ms | 
| コンパイル使用メモリ | 166,500 KB | 
| 実行使用メモリ | 6,944 KB | 
| 最終ジャッジ日時 | 2024-07-03 12:29:18 | 
| 合計ジャッジ時間 | 2,362 ms | 
| ジャッジサーバーID (参考情報) | judge3 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 23 | 
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
ll n;
ll a[105];
bool dp[105][5005];
ll sum;
int main(void){
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
        sum+=a[i];
    }
    if(sum%2==1){
        cout<<"impossible"<<endl;
        return 0;
    }
    dp[0][0]=true;
    dp[0][a[0]]=true;
    for(int i=1;i<n;i++){
        for(int j=0;j<=5000;j++){
            if(j-a[i]>=0&&dp[i-1][j-a[i]]==true) dp[i][j]=true;
            if(dp[i-1][j]==true) dp[i][j]=true;
        }
    }
    if(dp[n-1][sum/2]==true){
        cout<<"possible"<<endl;
    }else{
        cout<<"impossible"<<endl;
    }
    
}
            
            
            
        