結果

問題 No.4 おもりと天秤
ユーザー sotanakajimacl1sotanakajimacl1
提出日時 2017-09-16 14:25:03
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 481 bytes
コンパイル時間 549 ms
コンパイル使用メモリ 57,320 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-25 14:34:47
合計ジャッジ時間 1,528 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<iostream>
#include<algorithm>
#define INF (1<<30)
using namespace std;

//yuki 4 おもりと天秤

int n,w[101],ms,dp[10001];

int main(){
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>w[i];
		ms+=w[i];
	}
	if(ms%2==1){
		cout<<"impossible"<<endl;
	}
	else{
		ms/=2;
		dp[0]=1;
		for(int i=1;i<=n;i++){
			dp[w[i]]=1;
			for(int j=1;j<=10000;j++){
				if(dp[j]==1) dp[j+w[i]]=1;
			}
		}
		if(dp[ms]==1) cout<<"possible"<<endl;
		else cout<<"impossible"<<endl;
	}
	return 0;
}
0