結果

問題 No.4 おもりと天秤
ユーザー 🍡yurahuna🍡yurahuna
提出日時 2016-02-27 16:41:00
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 4 ms / 5,000 ms
コード長 1,230 bytes
コンパイル時間 624 ms
コンパイル使用メモリ 74,024 KB
実行使用メモリ 4,544 KB
最終ジャッジ日時 2023-09-08 16:36:05
合計ジャッジ時間 1,767 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <complex>
#include <queue>
#include <map>
#include <string>
using namespace std;

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define FORR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define pb push_back
#define ALL(a) (a).begin(),(a).end()

#define PI 3.1415926535

typedef long long ll;
typedef pair<int, int> P;
//typedef complex<double> C;

const int MAX_N = 100;
const int MAX_S = 10000;

int N;
int w[MAX_N];
int sum_w = 0;

// dp[i][j] = i番目までの和がjとなるような重りの選び方があるか
bool dp[MAX_N + 1][MAX_S + 1];

void input() {
	cin >> N;
	REP(i, N) {
		cin >> w[i];
		sum_w += w[i];
	}
}

void solve() {
	// 和が偶数でなければ2分割できない
	if (sum_w % 2 != 0) {
		cout << "impossible" << endl;
		return;
	}

	REP(i, N + 1) REP(j, MAX_S + 1) dp[i][j] = false;
	dp[0][0] = true;
	REP(i, N) {
		REP(j, MAX_S + 1) {
			if (dp[i][j]) {
				dp[i + 1][j + w[i]] = dp[i + 1][j] = true;
 			}
		}
	}

	if (dp[N][sum_w / 2]) {
		cout << "possible" << endl;
	} else {
		cout << "impossible" << endl;
	}
}

int main() {
	input();
	solve();
}
0