結果

問題 No.4 おもりと天秤
ユーザー 09SEPGR09SEPGR
提出日時 2017-10-22 01:13:45
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 4 ms / 5,000 ms
コード長 1,091 bytes
コンパイル時間 654 ms
コンパイル使用メモリ 71,584 KB
実行使用メモリ 4,432 KB
最終ジャッジ日時 2023-09-08 17:35:39
合計ジャッジ時間 1,633 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 4 ms
4,432 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 4 ms
4,392 KB
testcase_08 AC 3 ms
4,380 KB
testcase_09 AC 4 ms
4,380 KB
testcase_10 AC 4 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 4 ms
4,380 KB
testcase_19 AC 4 ms
4,408 KB
testcase_20 AC 3 ms
4,380 KB
testcase_21 AC 4 ms
4,388 KB
testcase_22 AC 4 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

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