結果

問題 No.4 おもりと天秤
ユーザー ama_nukoama_nuko
提出日時 2018-06-14 01:54:36
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 5 ms / 5,000 ms
コード長 920 bytes
コンパイル時間 825 ms
コンパイル使用メモリ 95,724 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-13 04:03:47
合計ジャッジ時間 2,112 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <utility>
#include <iomanip>

#define int long long int
#define rep(i, n) for(int i = 0; i < (n); ++i)

using namespace std;

typedef pair<int, int> P;

const int INF = 1e15;
const int MOD = 1e9+7;

signed main(){
    int n;
    cin >> n;
    vector<int> w(n);
    rep(i, n) cin >> w[i];

    vector<bool> dp(10001, false);
    dp[0] = true;
    rep(i, n){
        for(int j = 10000; j >= 1; j--){
            if(j < w[i]){
                continue;
            }
            dp[j] = dp[j] || dp[j-w[i]];
        }
    }
    int sum = 0;
    rep(i, n) sum += w[i];
    if(sum % 2 == 1){
        cout << "impossible" << endl;
        return 0;
    }
    sum /= 2;
    if(dp[sum]){
        cout << "possible" << endl;
    }else{
        cout << "impossible" << endl;
    }

    return 0;
}
0