結果

問題 No.4 おもりと天秤
ユーザー zenito9970zenito9970
提出日時 2017-03-27 10:47:29
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 5 ms / 5,000 ms
コード長 1,122 bytes
コンパイル時間 1,868 ms
コンパイル使用メモリ 170,516 KB
実行使用メモリ 7,360 KB
最終ジャッジ日時 2023-09-08 17:22:31
合計ジャッジ時間 3,105 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) FOR(i,0,n)
#define repr(i,n) for(int i=(n)-1;0<=i;--i)
#define each(e,v) for(auto&& e:(v))
#define all(v) begin(v),end(v)
#define DUMP(x) cerr<<#x<<": "<<(x)<<endl
#define DEBUG(x) cerr<<#x<<": "<<(x)<<" (L"<<__LINE__<<")"<<endl
using namespace std;
using vint = vector<int>;
using vdouble = vector<double>;
using vstring = vector<string>;
using ll = long long;
template <class T> void chmin(T& a, const T& b) { a = min(a, b); }
template <class T> void chmax(T& a, const T& b) { a = max(a, b); }

int main() {
    int N; cin >> N;
    vint w(N);
    rep(i, N) cin >> w[i];
    sort(all(w));
    const int W = accumulate(all(w), 0);
    if(W % 2 != 0) { cout << "impossible" << endl; return 0; }
    int dp[N+1][W+1];
    fill(dp[0], dp[N+1], 0);
    repr(i, N) {
        rep(mw, W+1) {
            if(mw < w[i]) dp[i][mw] = dp[i+1][mw];
            else dp[i][mw] = max(dp[i+1][mw], dp[i+1][mw - w[i]] + w[i]);
        }
    }
    if(dp[0][W/2] == W/2) cout << "possible" << endl;
    else cout << "impossible" << endl;
    return 0;
}
0