結果

問題 No.4 おもりと天秤
ユーザー TAISA_
提出日時 2018-05-30 22:35:34
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 714 bytes
コンパイル時間 1,189 ms
コンパイル使用メモリ 159,180 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-06-30 08:25:16
合計ジャッジ時間 1,976 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define all(vec) vec.begin(),vec.end()
typedef long long int ll;
typedef pair<ll,ll> P;
const ll MOD=1000000007;
const ll INF=1000000010;
const ll LINF=4000000000000000010LL;
const int MAX=310;
const double EPS=1e-9;
int dx[4]={0,1,0,1};
int dy[4]={0,0,1,1};
bool dp[110][10010];
int main(){
	int n;cin>>n;
	int w[110];
	int sum=0;
	for(int i=0;i<n;i++){
		cin>>w[i];
		sum+=w[i];
	}
	if(sum%2){
		cout<<"impossible"<<endl;
		return 0;
	}
	dp[0][0]=true;
	for(int i=0;i<n;i++){
		for(int j=0;j<=sum/2;j++){
			dp[i+1][j]|=dp[i][j];
			dp[i+1][j+w[i]]|=dp[i][j];
		}
	}
	if(dp[n][sum/2]){
		cout<<"possible"<<endl;
	}else{
		cout<<"impossible"<<endl;
	}
    return 0;
}
0