結果

問題 No.4 おもりと天秤
ユーザー yuruhiya
提出日時 2019-05-01 10:03:00
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 1,652 bytes
コンパイル時間 1,920 ms
コンパイル使用メモリ 176,340 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-12-31 12:13:08
合計ジャッジ時間 2,854 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, m, n) for(int i=(m); i<(n); ++i)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define dump(x) cerr << #x << " = " << (x) << endl;
using LL=long long;
using VI=vector<int>;
using VL=vector<long long>;
using VS=vector<string>;
using VVI=vector<vector<int>>;
using PII=pair<int, int>;
const int inf = (int)1e9;
const LL mod = (long long)1e9 + 7;
const double pi = acos(-1.0);

template<class T>void Sort(T & a) { sort(a.begin(), a.end()); }
template<class T>void ReSort(T& a) { sort(a.rbegin(), a.rend()); }
template<class T>void Reverse(T& a) { reverse(a.begin(), a.end()); }
template<class T>void Unique(T& a) { a.erase(unique(a.begin(), a.end()), a.end()); }
template<class T>auto Max(T a) { return *max_element(a.begin(), a.end()); }
template<class T>auto Min(T a) { return *min_element(a.begin(), a.end()); }
template<class T, class U>int Count(T a, U c) { return count(a.begin(), a.end(), c); }
template<class T, class U>U Sum(T a, U init = 0) { return accumulate(a.begin(), a.end(), init); }
template<class T>T Age(T a, T b) { return (a + b - 1) / b; }

int main() {
	int n; cin >> n;
	VI w(n); rep(i, n)cin >> w[i];
	int sum = Sum(w, 0);
	vector<vector<bool>> dp(109, vector<bool>(10009));
	dp[0][0] = true;
	if (sum % 2) {
		puts("impossible");
	}
	else {
		rep(i, n)rep(j, sum / 2 + 1) {
			if (dp[i][j])dp[i + 1][j] = true;
			if (j >= w[i])if (dp[i][j - w[i]])dp[i + 1][j] = true;
		}
		puts(dp[n][sum / 2] ? "possible" : "impossible");
	}
}
0