結果

問題 No.4 おもりと天秤
ユーザー IL_mstaIL_msta
提出日時 2015-06-03 18:08:34
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 5 ms / 5,000 ms
コード長 1,293 bytes
コンパイル時間 642 ms
コンパイル使用メモリ 73,116 KB
実行使用メモリ 7,416 KB
最終ジャッジ日時 2023-09-08 16:18:03
合計ジャッジ時間 1,677 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

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

ソースコード

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];
int dp[100][10001];
bool solve(int n,int wlim){
	bool ans;
	if( n >= N){
		return false;
	}

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

	if(dp[n][wlim] != -1){
		//cout << "dp";
		if( dp[n][wlim] == 0){
			return false;
		}else{
			return true;
		}
	}

	{
		ans = solve(n+1,wlim -W[n]);
		if(ans == true){
			return ans;
		}
		ans = solve(n+1,wlim );
		if(ans == true){
			return ans;
		}
		
	}
	
	dp[n][wlim] = 0;
	
	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);
	rep(i,N){
		rep(k,10001){
			dp[i][k] = -1;
		}
	}
	bool ans = solve(0,sum/2);
	
	if(ans == true){
		P("possible");
	}else{
		P("impossible");
	}
	return 0;
}
0