結果
| 問題 | No.4 おもりと天秤 | 
| コンテスト | |
| ユーザー |  yukkuriesu | 
| 提出日時 | 2017-12-10 11:45:41 | 
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 2 ms / 5,000 ms | 
| コード長 | 965 bytes | 
| コンパイル時間 | 1,309 ms | 
| コンパイル使用メモリ | 158,644 KB | 
| 実行使用メモリ | 5,376 KB | 
| 最終ジャッジ日時 | 2024-06-26 10:25:19 | 
| 合計ジャッジ時間 | 2,132 ms | 
| ジャッジサーバーID (参考情報) | judge4 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 23 | 
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define FORS(i,a,b) for(int i=a+1;i<=b;i++)
#define REP(i,N) FOR(i,0,N)
#define REPS(i,N) FORS(i,0,N)
#define debug(x) cout<<#x<<"="<<x<<endl
#define debugarr(arr,N,M){REP(i,N){REP(j,M){if(arr[i][j]==INF)printf(" INF");\
	else printf("%d",arr[i][j]);} cout<<endl;}}
#define pb push_back
#define pob pop_back
typedef long long ll;
const int INF=100000000;
//--------------------------------------//
int N;
int W[100];
int a=0;
bool dp[101][5001];
int main(){
	cin>>N;
	REP(i,N){
		cin>>W[i];
		a+=W[i];
	}
	if(a%2==1){
		cout<<"impossible"<<endl;
		goto end;	//人生で一回ぐらいは使ってみたかった。許して。
	}
	a/=2;
	REP(i,N) dp[i][0]=true;
	REP(i,N){
		REP(j,a){
			if(j+1-W[i]>=0) dp[i+1][j+1]=(dp[i][j+1]|dp[i][j+1-W[i]]);
			else  dp[i+1][j+1]=dp[i][j+1];
		}
	}
	if(dp[N][a]) cout<<"possible"<<endl;
	else cout<<"impossible"<<endl;
end:
	return 0;
}
            
            
            
        