結果
| 問題 | No.4 おもりと天秤 | 
| コンテスト | |
| ユーザー |  lioo | 
| 提出日時 | 2021-03-30 17:21:36 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 2 ms / 5,000 ms | 
| コード長 | 597 bytes | 
| コンパイル時間 | 511 ms | 
| コンパイル使用メモリ | 64,128 KB | 
| 実行使用メモリ | 5,248 KB | 
| 最終ジャッジ日時 | 2024-11-30 16:20:16 | 
| 合計ジャッジ時間 | 1,515 ms | 
| ジャッジサーバーID (参考情報) | judge5 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 23 | 
ソースコード
#include <iostream>
using namespace std;
bool memo[5001]={};
int main(){
    int N,sum=0;
    cin>>N;
    memo[0]= true;
    int weight[100];
    
    for(int i=0;i<N;i++){
        cin>>weight[i];
        sum+=weight[i];
    }
 
    if(sum%2==1){
        cout<<"impossible"<<endl;
        return 0;
    }
    int half = sum/2;
    for(int i = 0; i<N;i++){
        for(int j=half;j>=0;j--){
            if(j-weight[i]<0)break;
            if(memo[j-weight[i]])
            memo[j]=true;
        }
    }
    if(memo[half])
    cout<<"possible"<<endl;
    else
    cout<<"impossible"<<endl;
}
            
            
            
        