結果

問題 No.4 おもりと天秤
ユーザー tsukiotsukio
提出日時 2016-03-10 22:56:38
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 864 bytes
コンパイル時間 998 ms
コンパイル使用メモリ 58,416 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-24 22:42:00
合計ジャッジ時間 7,709 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <string>
#include <numeric>
using namespace std;

bool isDevideInHalf(int* weights, int n, int index, int total_weight) {
	if (total_weight == 0) return true;
	if (index >= n) return false;

	if (weights[index] <= total_weight) {
		if (isDevideInHalf(weights, n, index + 1, total_weight - weights[index]))
			return true;
		return isDevideInHalf(weights, n, index + 1, total_weight);
	}

	return isDevideInHalf(weights, n, index + 1, total_weight);
}

int main() {
	int n;
	cin >> n;

	int weights[100];
	for (int i = 0; i < n; i++) {
		cin >> weights[i];
	}

	bool is_possible = false;
	int sum_weight = accumulate(weights, weights + n, 0);
	if (sum_weight % 2 == 0) {
		is_possible = isDevideInHalf(weights, n, 0, sum_weight / 2);
	}
	
	string answer = is_possible ? "possible" : "impossible";
	cout << answer << endl;

	return 0;
}
0