結果

問題 No.4 おもりと天秤
ユーザー mannshi222mannshi222
提出日時 2022-04-01 20:08:18
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 943 bytes
コンパイル時間 845 ms
コンパイル使用メモリ 83,480 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-30 11:19:35
合計ジャッジ時間 1,760 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <stack>
#include <algorithm>

using namespace std;

bool chk( vector<int> w, int i, int half );

int main()
{
	int N;
	cin >> N;

	vector<int> W(N);
	for(int i = 0 ; i < N; i++ ){
		cin  >> W[i];
	}
	sort( W.begin(), W.end() );

	int half = 0;
	for( auto x: W ) {
		half += x;
	}

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


	if( chk( W, 0, half ) ) {
		cout << "possible" << endl;
	}
	else {
		cout << "impossible" << endl;
	}

	return 0;
}
bool chk( vector<int> w, int i, int half )
{
	if( i >= w.size() ) {
		return false;
	}
	if( w[i] == half ) {
		return true;
	}
	if( w[i] < half ) {
		bool tmp = chk( w, i+1, half - w[i] );
		if( tmp ) {
			return true;
		}
		if( i <= 0 ) {
			return false;
		}
		//return chk( w, i-1, half+w[i] );
		//return chk( w, i+2, half );
		return false;
		
	}
	if( w[i] > half ) {
		return false;
	}

	return false;
}
0