結果

問題 No.4 おもりと天秤
ユーザー otamay6
提出日時 2019-10-17 16:24:33
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 5 ms / 5,000 ms
コード長 703 bytes
コンパイル時間 1,772 ms
コンパイル使用メモリ 173,784 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-06-24 17:46:38
合計ジャッジ時間 2,667 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define REP(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define All(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;

int main(){
    int N;cin>>N;
    vector<int> W(N);
    int S=0;
    REP(i, N){
        cin >> W[i];
        S+=W[i];
    }
    if(S&1){
        cout<<"impossible"<<endl;
        return 0;
    }
    vector<vector<bool>> dp(N+1,vector<bool>(S/2+1,false));
    dp[0][0]=true;
    REP(i,N) REP(j,S/2+1){
        dp[i+1][j]=dp[i+1][j]|dp[i][j];
        if(j+W[i]<=S/2) dp[i+1][j+W[i]]=dp[i+1][j+W[i]]|dp[i][j];
    }
    if(dp[N][S/2]) cout<<"possible"<<endl;
    else cout<<"impossible"<<endl;
}
0