結果

問題 No.4 おもりと天秤
ユーザー rinyuushokurinyuushoku
提出日時 2020-08-17 15:37:28
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 9 ms / 5,000 ms
コード長 2,371 bytes
コンパイル時間 1,457 ms
コンパイル使用メモリ 168,184 KB
実行使用メモリ 11,392 KB
最終ジャッジ日時 2024-04-19 18:53:44
合計ジャッジ時間 2,269 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define repreverse(i, start, end) for (long long i = start; i >= end; --i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define len(x) ((long long)(x).size())
#define lcm(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vllvll = vector<vll>;
using vc = vector<char>;
using pll = pair<ll, ll>;
template<class T>void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
template<class T>void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
template<class T, class U>bool haskey(T mp, U key) { return mp.find(key) != mp.end(); }
template<class T, class U>bool isin(T el, U container) { return find(all(container), el) != container.end(); }
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
template<class T>bool even(T n) { return ! (n & 1); }
template<class T>bool odd(T n) { return n & 1; }
template<class T>ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T>ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
ll intpow(ll a,ll n){ll p=1;while(n){if(n&1)p*=a;a*=a;n>>=1;}return p;} 
const long double pi = M_PI;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;



int main()
{
        ll N;
        cin >> N;
        vll W(N+1);
        rep(i, 1, N+1) cin >> W[i];


        vllvll dp(N+1, vll(10101, 0));

        dp[0][0] = 1;

        rep(i, 1, N+1) {
                rep(j, 0, 10101) {
                        if (dp[i-1][j] == 1) dp[i][j] = dp[i-1][j];
                        if (j-W[i] >= 0 and dp[i-1][j-W[i]] == 1) {
                                dp[i][j] = dp[i-1][j-W[i]];
                        }
                }
        }

        // print2d(dp, -1, 100);

        ll sm = 0;
        rep(i, 1, N+1) sm += W[i];

        if (odd(sm)) {
                cout << "impossible" << endl;
                return 0;
        }

        if (dp[N][sm/2] == 1) {
                cout << "possible" << endl;
        } else {
                cout << "impossible" << endl;
        }
}
0