結果

問題 No.4 おもりと天秤
ユーザー polylogKpolylogK
提出日時 2017-09-15 16:33:32
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 681 bytes
コンパイル時間 878 ms
コンパイル使用メモリ 90,088 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-08 17:34:06
合計ジャッジ時間 1,651 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <vector>
#include <string>
#include <string.h>
#include <iomanip>
#include <limits>
using namespace std;

const int MAX_N=10000;
int n;
bool dp[10001]; //dp[i]:=重さがiになるような組み合わせが存在するか。

int main(){
	cin >> n;
	
	fill(dp,dp+sizeof(dp)/sizeof(dp[0]),false);
	dp[0]=true;
	int w,s=0;
	for(int i=0;i<n;i++){
		cin >> w;
		s+=w;
		for(int j=10001;j>=w;j--) if(dp[j-w]) dp[j]=true;
	}
	
	if(s%2==0){
		if(dp[s/2]){
			cout << "possible" << endl;
			return 0;
		}
	}
	
	cout << "impossible" << endl;
	return 0;
}
0