結果

問題 No.4 おもりと天秤
ユーザー w10y26w10y26
提出日時 2017-05-08 09:57:16
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 952 bytes
コンパイル時間 648 ms
コンパイル使用メモリ 77,004 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-08 17:26:07
合計ジャッジ時間 1,661 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#define ll long long
#define ffor(i,a,b) for (int i=(a);i<(b);i++)
#define rfor(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define rep(i,n) for (int i=0;i<(n);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<map>
#define SIZE 100001
#define MOD 1000000007
#define INF 100000000
using namespace std;
bool dp[SIZE];

//全ての重りの合計の半分の値となる組み合わせがあるか?
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);

	int n,sum=0;
	vector<int> v(100);

	cin >> n;
	rep(i,n) cin >> v[i];

	rep(i,n) sum +=v[i];

	if(sum%2 == 1){
		cout << "impossible" << endl;
		return 0;
	}

	int mid = sum/2;
	dp[0] = true;
	rep(i,n){
		for(int j = mid; j>=v[i];j--){
			dp[j]|=dp[j-v[i]];//bit和代入
		}
	}

	if(dp[mid])cout<<"possible"<<endl;
	else cout<<"impossible"<<endl;
	return 0;
}
0