結果

問題 No.4 おもりと天秤
ユーザー sotanakajimacl1
提出日時 2017-09-16 14:25:03
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 481 bytes
コンパイル時間 652 ms
コンパイル使用メモリ 56,800 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-11-08 01:31:15
合計ジャッジ時間 1,633 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 17 WA * 6
権限があれば一括ダウンロードができます

ソースコード

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