結果

問題 No.4 おもりと天秤
ユーザー kurenaif
提出日時 2017-04-07 12:50:16
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 468 bytes
コンパイル時間 515 ms
コンパイル使用メモリ 61,792 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-06-26 10:13:52
合計ジャッジ時間 1,373 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>

using namespace std;

int main(void){
	int N; cin >> N;
	vector<int> W(N);
	int sum = 0;
	for(int &a:W){
		cin >> a;
		sum += a;
	}
	vector<bool> check(sum+1);
	if(sum%2 == 1){
		cout << "impossible" << endl;
		return 0;
	}

	check[0] = true;

	for(auto &a:W){
		for(int i=check.size()-1;i>=0;--i)	if(i-a >= 0 && check[i-a]) check[i] = true;
	}
	if(check[sum/2]) cout << "possible" << endl;
	else cout << "impossible" << endl;
}
0