結果

問題 No.4 おもりと天秤
ユーザー 👑 CleyL
提出日時 2020-01-18 02:25:27
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 4 ms / 5,000 ms
コード長 794 bytes
コンパイル時間 548 ms
コンパイル使用メモリ 65,484 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-06-26 05:52:02
合計ジャッジ時間 1,447 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
using namespace std;
bool dp[100][10010];
int main(){
    int n;cin>>n;
    int sm = 0;
    int a[n];
    for(int i = 0; n > i; i++){
        cin>>a[i];
        sm += a[i];
    }
    if(sm%2){
        cout << "impossible" << endl;
        return 0;
    }
    dp[0][0] = true;
    dp[0][a[0]] = true;
    for(int i = 1; n > i; i++){
        for(int j = 0; 10000 >= j; j++){
            if(dp[i-1][j]){
                //cout << i << " " << j << endl;
                dp[i][j] = true;
            }
            if(a[i]<=j && dp[i-1][j-a[i]]){
                //cout << i << " " << j << endl;
                dp[i][j] = true;
            }
        }
    }
    if(dp[n-1][sm/2]){
        cout << "possible" << endl;
    }else{
        cout << "impossible" << endl;
    }
    
}
0