結果

問題 No.4 おもりと天秤
ユーザー TwizzTwizz
提出日時 2017-05-05 21:40:42
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 627 bytes
コンパイル時間 1,492 ms
コンパイル使用メモリ 164,236 KB
実行使用メモリ 8,704 KB
最終ジャッジ日時 2023-10-12 09:50:42
合計ジャッジ時間 8,224 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 2 ms
4,348 KB
testcase_04 AC 2 ms
4,352 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"bits/stdc++.h"
//#include<bits/stdc++.h>
using namespace std;
#define print(x) cout<<x<<endl;
#define rep(i,a,b) for(int i=a;i<b;i++)
typedef long long ll;
//const int mod = 1e9 + 7;

int n;
int w[102];
int sum = 0;
int half = 0;

int solve(int i, int sum) {
	if (i == n) { return sum == half; }
	if (solve(i + 1, sum))return true;
	if (solve(i + 1, sum + w[i]))return true;
	return false;
}

int main() {
	
	cin >> n;
	rep(i, 0, n) { cin >> w[i]; half += w[i]; }
	if (half % 2 == 1) {
		print("impossible"); return 0;
	}
	half /= 2;
	if (solve(0, 0)) { print("possible"); }
	else { print("impossible"); }
	return 0;
}
0