結果

問題 No.4 おもりと天秤
ユーザー IL_mstaIL_msta
提出日時 2015-06-03 17:51:39
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,060 bytes
コンパイル時間 520 ms
コンパイル使用メモリ 72,524 KB
実行使用メモリ 8,768 KB
最終ジャッジ日時 2023-09-20 19:00:14
合計ジャッジ時間 7,461 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <iomanip>

#include <algorithm>
#include <math.h>

#include <string>
#include <list>
/////////
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define P(p) cout<<(p)<<endl;
/////////
typedef long long LL;
typedef long double LD;
/////////
using namespace::std;
/////////
int N;
int W[100];
bool solve(int n,int wlim){
	bool ans;
	if( n >= N){
		return false;
	}

	if(wlim == W[n]){
		//成功
		return true;
	}
	else if(wlim < W[n]){
		//失敗
		return false;
	}

	{
		ans = solve(n+1,wlim -W[n]);
		if(ans == true){
			return ans;
		}
		ans = solve(n+1,wlim );
		if(ans == true){
			return ans;
		}
	}
	return false;
}


int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed;//
    //cout << setprecision(6);//
	
	
	cin>>N;//[2,100]
	
	int sum=0;
	rep(i,N){
		cin>>W[i];//[1,100]
		sum += W[i];
	}
	if(sum%2 != 0){
		P("impossible");
		return 0;
	}

	sort(W,W+N);

	bool ans = solve(0,sum/2);

	if(ans == true){
		P("possible");
	}else{
		P("impossible");
	}
	return 0;
}
0