結果

問題 No.4 おもりと天秤
ユーザー nak3nak3
提出日時 2017-03-11 17:59:20
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 609 bytes
コンパイル時間 1,055 ms
コンパイル使用メモリ 143,860 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-06 18:09:45
合計ジャッジ時間 2,020 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define INF 2000000000
#define MOD 1000000007
typedef long long ll;
typedef pair<int, int> P;


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

	int a[n];
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	ll sum = accumulate(a, a+n, 0);
	if (sum%2!=0) {
		cout << "impossible" << "\n";
		return 0;
	}

	ll h = sum/2;

	for (int all = 0; all < (1<<n); all++) {
		ll subsum = 0;
		for (int i = 0; i < n; i++) {
			if (all & (1<<i)) {
				subsum += a[i];
			}
		}
		if (subsum==h) {
			cout << "possible" << "\n";
			return 0;
		}
	}
	cout << "impossible" << "\n";
	return 0;

}
0