結果

問題 No.4 おもりと天秤
ユーザー RubikunRubikun
提出日時 2019-07-31 02:01:42
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 940 bytes
コンパイル時間 1,536 ms
コンパイル使用メモリ 167,248 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-18 15:50:44
合計ジャッジ時間 2,501 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 3 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 3 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 3 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 3 ms
4,380 KB
testcase_19 AC 3 ms
4,376 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 3 ms
4,376 KB
testcase_22 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=100001,INF=1<<30;

int main(){

    int N;cin>>N;
    vector<int> A(N);
    int sum=0;
    for(int i=0;i<N;i++){
        cin>>A[i];
        sum+=A[i];
    }
    
    if(sum%2==1) cout<<"impossible"<<endl;
    else{
        bool dp[N+1][sum+1];
        for(int i=0;i<N+1;i++){
            for(int j=0;j<sum+1;j++){
                dp[i][j]=0;
            }
        }
        dp[0][0]=1;
        
        for(int i=0;i<N;i++){
            for(int j=sum;j>=0;j--){
                bool ok=0;
                if(j-A[i]>=0&&dp[i][j-A[i]]) ok=1;
                if(dp[i][j]) ok=1;
                if(ok) dp[i+1][j]=1;
                else dp[i+1][j]=0;
            }
        }
        
        if(dp[N][sum/2]) cout<<"possible"<<endl;
        else cout<<"impossible"<<endl;
    }
    
}

0