結果

問題 No.4 おもりと天秤
ユーザー KoshStorm
提出日時 2017-12-17 00:18:43
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 693 bytes
コンパイル時間 1,481 ms
コンパイル使用メモリ 165,428 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-12-14 22:36:08
合計ジャッジ時間 2,168 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 18 WA * 5
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define MAX(a, b) ((a) > (b) ? (a) : (b))
using namespace std;

int main(void){
	short N;
	cin >> N;
	vector<short> W(N);

	long sum = 0;

	REP(i,N){
		cin >> W[i];
		sum += W[i];
	}

	if (sum % 2) {
		cout << "impossible\n";
		exit(0);
	}

	#ifdef DEBUG
		cout << "sum ==> " << sum << "\n";
	#endif


	vector<vector<char>>dp(N+1, vector<char>(sum/2+1, 0));
	REP(i,N) dp[i][0] = 1;

	REP(i,N){
		REP(j,sum/2+1){
			if ((j - W[j]) >= 0){
				dp[i+1][j] = MAX(dp[i][j-W[i]],dp[i][j]);
			}
		}	
	}

	if (dp[N][sum/2]) cout << "possible\n";
	else cout << "impossible\n";


	return 0;
}
0