結果

問題 No.4 おもりと天秤
コンテスト
ユーザー yukkuriesu
提出日時 2017-12-10 11:45:41
言語 C++11
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=gnu++11 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 965 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 959 ms
コンパイル使用メモリ 175,524 KB
実行使用メモリ 6,144 KB
最終ジャッジ日時 2026-03-13 02:47:59
合計ジャッジ時間 1,699 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#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;
}
0