結果

問題 No.4 おもりと天秤
ユーザー tempura-samatempura-sama
提出日時 2016-04-18 10:32:04
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 605 bytes
コンパイル時間 377 ms
コンパイル使用メモリ 56,336 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-15 03:27:14
合計ジャッジ時間 2,354 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <cstring>
using namespace std;

#define N 100
#define W 100

int n;
int w[N];
int wm[W*N+1];
int hw;

int dp()
{
	for ( int i = 0; i < n; i++ ) {
		if ( w[i] == hw ) {
			return 1;
		}
		for ( int j = hw - 1; j >= 1; j-- ) {
			if ( wm[j] == 1 ) {
				wm[j + w[i]] = 1;
			}
		}
		wm[w[i]] = 1;
		if ( w[hw] == 1 ) {
			return 1;
		}
	}
	return 0;
}

int main()
{
	cin >> n;
	for ( int i = 0; i < n; i++ ) {
		cin >> w[i];
		hw += w[i];
	}
	if ( hw % 2 == 0 && (hw /= 2, dp() == 1) ) {
		cout << "possible" << endl;
	}
	else {
		cout << "impossible" << endl;
	}

	return 0;
}
0