結果

問題 No.4 おもりと天秤
ユーザー agonybusscla191
提出日時 2018-02-16 18:29:11
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 4 ms / 5,000 ms
コード長 947 bytes
コンパイル時間 1,366 ms
コンパイル使用メモリ 160,996 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-06-26 10:28:40
合計ジャッジ時間 2,184 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>

using namespace std;

bool dp[110][10010];

int main(){
        int N;
        cin>>N;
        vector <int> w(N);
        int sum=0;
        for(int i=0;i<N;i++){
                cin>>w[i];
                sum+=w[i];
        }
        for(int i=0;i<110;i++){
                for(int j=0;j<10010;j++){
                        dp[i][j]=false;
                }
        }
        if(sum%2!=0){
                cout<<"impossible"<<endl;
                return 0;
        }
        dp[0][0]=true;
        for(int i=0;i<N;i++){
                for(int j=0;j<=10000;j++){
                        if(dp[i][j]){
                                dp[i+1][j+w[i]]=true;
                                dp[i+1][j]=true;
                        }
                }
        }
        if(dp[N][sum/2]){
                cout<<"possible"<<endl;
        }
        else{
                cout<<"impossible"<<endl;
        }
        return 0;
}
0