結果

問題 No.4 おもりと天秤
ユーザー yukiteru
提出日時 2017-10-20 21:55:50
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 4 ms / 5,000 ms
コード長 953 bytes
コンパイル時間 859 ms
コンパイル使用メモリ 78,232 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-06-26 10:24:09
合計ジャッジ時間 1,370 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<string>
#include<string.h>
#include<algorithm>
#include<stdio.h>
#include<cmath>
#include<vector>
#include<utility>
#include<stack>
#include<queue>
#include<list>
#include<bitset>

#define FOR(i, a, b) for(int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000

using namespace std;


int main(void) {
	int n;
	int w[101];
	bool dp[101][10001];
	int total=0;

	cin >> n;
	FOR(i, 0, 100) {
		FOR(t, 0, 10000) {
			dp[i][t] = false;
		}
	}
	FOR(i, 0, n-1) {
		cin >> w[i];
		total += w[i];
	}
	if (total % 2 == 1) {
		cout << "impossible" << endl;
	}
	else {
		total /= 2;
		dp[0][0] = true;
		FOR(i, 0, n-1) {
			FOR(t, 0, 10000) {
				
				if (dp[i][t] == true) {
					dp[i + 1][t] = true;
					dp[i + 1][t + w[i]] = true;
				}
			}
		}
		if (dp[n][total] == true) {
			cout << "possible" << endl;
		}
		else {
			cout << "impossible" << endl;
		}
	}
	return 0;
}
0