結果
| 問題 | No.4 おもりと天秤 | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2024-06-28 13:01:16 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 2 ms / 5,000 ms | 
| コード長 | 1,756 bytes | 
| コンパイル時間 | 1,699 ms | 
| コンパイル使用メモリ | 169,016 KB | 
| 実行使用メモリ | 6,944 KB | 
| 最終ジャッジ日時 | 2024-06-28 13:01:18 | 
| 合計ジャッジ時間 | 2,457 ms | 
| ジャッジサーバーID (参考情報) | judge3 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 23 | 
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(x) x.begin(),x.end()
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define rep_r(i,a,b) for(int i=a;i>=b;i--)
#define each(a,x) for (auto& x : a)
using pi = pair<int,int>;
using pl = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;
#define sz(x) int(x.size())
#define so(x) sort(all(x))
#define so_r(x) sort(all(x),greater<int>())
#define lb lower_bound
#define ub upper_bound
const char nl = '\n';
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int bit_cnt(int x){
    return __builtin_popcount(x);
}
ll bex(ll a, ll b, ll mod = 1e9 + 7){ll res = 1LL; while(b){ if (b&1) res = res * a % mod; a = a * a % mod; b >>= 1;} return res;}
template<class t,class u> bool chmax(t&a,u b){if(a<b){a=b;return true;}else return false;}
template<class t,class u> bool chmin(t&a,u b){if(b<a){a=b;return true;}else return false;}
const int MOD = 998244353;
const int N = 5e5 + 5;
const ll INF = 1e16;
int a[N];
void solve(){
    int n; cin >> n;
    rep(i,1,n) cin >> a[i];
    // https://yukicoder.me/problems/no/4
    // brief: find a way to divide array into two subsequences with equal sum 
    // constraint: n <= 100, a[i] <= 100
    // condition:
    // dp[sum / 2] = true
    // sum % 2 == 0
    int sum = accumulate(a+1,a+1+n,0);
    if (sum%2==1) {
        cout << "impossible";
    } else {
        int target = sum / 2;
        vl dp(target+1, false);
        dp[0] = true;
        rep(i,1,n){
            rep_r(j,target,a[i]) dp[j] |= dp[j-a[i]];
        }
        cout << (dp[target] ? "possible" : "impossible");
    }
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t = 1; 
    // cin >> t;
    while (t--){
        solve();
    }
}
            
            
            
        