結果

問題 No.4 おもりと天秤
ユーザー T.StreamT.Stream
提出日時 2020-04-14 11:34:28
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 4 ms / 5,000 ms
コード長 522 bytes
コンパイル時間 2,283 ms
コンパイル使用メモリ 200,496 KB
実行使用メモリ 6,952 KB
最終ジャッジ日時 2024-04-09 05:16:04
合計ジャッジ時間 3,179 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main() {
	long n,i,j,cur,res;
	cin >> n;
	vector<long> w(n);
	res=0;
	for(i=0; i<n; i++){
		cin >> w[i];
		res+=w[i];
	}
	if(res%2==1){
		cout << "impossible" << endl; return 0;
	}
	vector<bool> p1(res+1,false),p2(res+1,false);
	p1[0]=true; p2[0]=true;
	cur=0;
	for(i=0; i<n; i++){
		for(j=0; j<=cur; j++){
			p2[j+w[i]]=p1[j+w[i]] | p1[j];
		}
		cur+=w[i];
		p1=p2;
	}
	if(p1[res/2]){
		cout << "possible" << endl;
	}else{
		cout << "impossible" << endl;
	}
	return 0;
}
0