結果

問題 No.4 おもりと天秤
ユーザー mannshi222mannshi222
提出日時 2022-04-03 00:49:53
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,102 bytes
コンパイル時間 788 ms
コンパイル使用メモリ 86,460 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-05-01 23:15:54
合計ジャッジ時間 1,494 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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

using namespace std;

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;

	// cout << "half " << half << endl;

	stack<int> s;

	int sum =0;
	int i = 0;
	while( 1 ) {
		if( i >= N ) {
			int sss;
			while( !s.empty() ) {
				i = s.top();
				s.pop();
			}
			if( i == N ) {
				cout << "impossible" << endl;
				return 0;
			}
			sum = 0;
			i++;
		} else if( half == sum + W[i] ) {
			cout << "possible" << endl;
			while( s.empty() ) {
				cout << s.top() << endl;
				s.pop();
			}
			return 0;
		}
		else if( half >  sum + W[i] ) {
			sum += W[i];
			s.push( i );
			i++;
		}
		else if( half < sum + W[i] ) {
			if( s.empty() ) {
				cout << "impossible" << endl;
				return 0;
			}
			i= s.top();
			sum -= W[i];
			i++;
			s.pop();
		} else { cout << "arienai" << endl; return 0; }

	}
	
	return 0;
}
0