結果

問題 No.4 おもりと天秤
ユーザー DadarithmDadarithm
提出日時 2015-09-14 23:09:50
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 592 bytes
コンパイル時間 516 ms
コンパイル使用メモリ 64,168 KB
実行使用メモリ 8,760 KB
最終ジャッジ日時 2023-09-26 11:57:20
合計ジャッジ時間 7,136 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int N; vector<int> arr; bool ans;

bool solve(int n, int left)
{
	if (n == arr.size())
		return !left;
	else
	{
		if (solve(n + 1, left) || solve(n + 1, left - arr[n]))
			return true;
		return false;
	}
}

int main()
{
	ans = false;
	cin >> N;
	for (int i = 0; i < N; ++i)
	{
		int j;
		cin >> j;
		arr.push_back(j);
	}

	int sum = 0, nsum = 0;
	for (int i = 0; i < arr.size(); ++i)
		sum += arr[i];
	if (!(sum % 2))
		ans = solve(0, sum / 2);

	cout << (ans ? "possible" : "impossible") << endl;

	return 0;
}
0