結果

問題 No.4 おもりと天秤
ユーザー stack9996
提出日時 2015-08-26 15:31:01
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 5 ms / 5,000 ms
コード長 584 bytes
コンパイル時間 517 ms
コンパイル使用メモリ 56,516 KB
実行使用メモリ 5,888 KB
最終ジャッジ日時 2024-06-26 09:17:16
合計ジャッジ時間 1,352 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <numeric>

#define rep(i, a) FOR(i, 0, a)
#define FOR(i, a, b) for(int i = a; i < b; ++i)

int n;
int w[101];
int dp[105][10005];

int main(){
	std::cin >> n;
	rep(i, n)std::cin >> w[i];
	dp[0][0] = 1;
	rep(i, n)rep(j, 10001){
		if (dp[i][j] != 0){
			dp[i + 1][j] = 1;
			if (j + w[i] < 10001)dp[i + 1][j + w[i]] = 1;
		}
	}
	if (std::accumulate(w, w + n, 0) % 2 != 0)std::cout << "impossible" << std::endl;
	else if (dp[n][std::accumulate(w, w + n, 0) / 2])std::cout << "possible" << std::endl;
	else std::cout << "impossible" << std::endl;
	return 0;
}
0