結果

問題 No.4 おもりと天秤
ユーザー myukiimyukii
提出日時 2016-09-13 14:09:12
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 677 bytes
コンパイル時間 700 ms
コンパイル使用メモリ 71,352 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-28 13:02:41
合計ジャッジ時間 2,186 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>

int main(int argc, char **argv) {
	int n = -1;
	int w = -1;
	int amount_w = 0;
	int half_w = 0;
	std::vector<int> ws;

	std::cin >> n;
	for (int i = 0; i < n; i++) {
		std::cin >> w;
		amount_w += w;
		ws.push_back(w);
	}

	half_w = amount_w / 2;
	if (amount_w % 2 != 0) {
		std::cout << "impossible\n";
		return 0;
	}

	bool checks[amount_w + 1] = { false };

	checks[0] = true;

	for (int i = 0; i < n; i++) {
		for (int j = 0; j <= amount_w; j++) {
			if (!checks[j]) {
				break;
			}
			checks[j + ws.at(i)] = true;
		}
	}

	if (checks[half_w]) {
		std::cout << "possible\n";
	} else {
		std::cout << "impossible\n";
	}
	return 0;
}
0