結果

問題 No.4 おもりと天秤
ユーザー 09SEPGR
提出日時 2017-10-22 01:13:45
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 4 ms / 5,000 ms
コード長 1,091 bytes
コンパイル時間 927 ms
コンパイル使用メモリ 72,068 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-06-26 10:24:14
合計ジャッジ時間 1,396 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

/*
 * main.cpp
 *
 *  Created on: 2017/10/06
 *      Author: sep
 */

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>

using namespace std;

inline int main003();
inline int main045();
inline int main004();
inline int main4();


int main() {

	main004();

	return 0;
}

inline int main004() {

	int num;
	int *weight;
	int i, j;
	int sum = 0;
	bool **dyp;

	cin >> num;

	weight = new int[num];
	dyp = new bool*[num + 1];

	for (i = 0; i < num; i++) {
		cin >> weight[i];
		dyp[i] = new bool[num * 100 + 1];
		sum += weight[i];
	}

	dyp[num] = new bool[num * 100 + 1];

	fill(dyp[0], dyp[num], false);

	if (sum % 2 == 1) {
		cout << "impossible";
		return 0;
	}

	dyp[0][0] = true;

	for (i = 0; i < num; i++)
		for (j = 0; j <= num * 100; j++) {
			if (dyp[i][j] == true) {
				dyp[i + 1][j + weight[i]] = true;
				dyp[i + 1][j] = true;
			}
		}

	if (dyp[num][sum / 2] == true) {
		cout << "possible";
	} else {
		cout << "impossible";
	}

	return 0;
}
0