結果

問題 No.2812 Plus Minus Blackboard
ユーザー kotatsugamekotatsugame
提出日時 2024-07-19 21:36:15
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 38 ms / 2,000 ms
コード長 644 bytes
コンパイル時間 661 ms
コンパイル使用メモリ 76,840 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-07-21 20:26:30
合計ジャッジ時間 1,986 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 38 ms
6,944 KB
testcase_04 AC 23 ms
6,940 KB
testcase_05 AC 35 ms
6,940 KB
testcase_06 AC 8 ms
6,944 KB
testcase_07 AC 6 ms
6,944 KB
testcase_08 AC 5 ms
6,940 KB
testcase_09 AC 30 ms
6,940 KB
testcase_10 AC 5 ms
6,940 KB
testcase_11 AC 19 ms
6,944 KB
testcase_12 AC 16 ms
6,940 KB
testcase_13 AC 37 ms
6,944 KB
testcase_14 AC 10 ms
6,940 KB
testcase_15 AC 5 ms
6,940 KB
testcase_16 AC 34 ms
6,940 KB
testcase_17 AC 11 ms
6,944 KB
testcase_18 AC 8 ms
6,944 KB
testcase_19 AC 27 ms
6,940 KB
testcase_20 AC 5 ms
6,944 KB
testcase_21 AC 37 ms
6,940 KB
testcase_22 AC 32 ms
6,944 KB
testcase_23 AC 2 ms
6,944 KB
testcase_24 AC 2 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>
#include<cassert>
using namespace std;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int N;cin>>N;
	vector<int>pos,neg;
	for(int i=0;i<N;i++)
	{
		int a;cin>>a;
		if(a>0)pos.push_back(a);
		else if(a<0)neg.push_back(-a);
	}
	sort(pos.begin(),pos.end());
	reverse(pos.begin(),pos.end());
	sort(neg.begin(),neg.end());
	reverse(neg.begin(),neg.end());
	while(!pos.empty()&&!neg.empty())
	{
		int t=pos.back()-neg.back();
		pos.pop_back();
		neg.pop_back();
		if(t>0)pos.push_back(t);
		else if(t<0)neg.push_back(-t);
	}
	cout<<(pos.size()+neg.size()>1?"No":"Yes")<<endl;
}
0