結果

問題 No.4 おもりと天秤
ユーザー nksknksk
提出日時 2017-04-22 10:25:50
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 869 bytes
コンパイル時間 664 ms
コンパイル使用メモリ 73,316 KB
実行使用メモリ 7,816 KB
最終ジャッジ日時 2023-09-28 21:14:00
合計ジャッジ時間 7,418 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 3 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 3 ms
4,380 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<cstdio>
#include <iostream>
#include<algorithm>
#include<string>
#include<queue>
#include<vector>
#include<functional>
#include<cmath>
#include<map>
#include<stack>
#include<set>
using namespace std;
typedef long long ll;
//typedef pair<int, int> P;

int w[101],P[101];
int N,sum,res1,res2,flag=0;

void solve() {
	for (int i = 0; i < N; i++) {
		if (P[i]) {
			res1 += w[i];
		}
		else {
			res2 += w[i];
		}
	}

	if (res1 == res2) {
		flag = 1;
	}
}

 void Set(int x) {
	if (x >= N) {
		res1 = res2 = 0;
		solve();
		return;
	}
	for (int i = 0; i < 2; i++) {
		P[x] = i;
		Set(x + 1);
	}
}

int main()
{
    cin >> N;
	
	for (int i = 0; i < N; i++) {
		cin >> w[i];
		sum += w[i];
	}

	if (sum % 2 != 0) {
		cout << "impossible" << endl;
		return 0;
	}
	Set(0);
	if (flag) {
		cout << "possible" << endl;
	}
	else
		cout << "impossible" << endl;
	return	0;
}
0