結果
問題 | No.2812 Plus Minus Blackboard |
ユーザー |
|
提出日時 | 2024-07-30 10:46:15 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 98 ms / 2,000 ms |
コード長 | 962 bytes |
コンパイル時間 | 1,840 ms |
コンパイル使用メモリ | 171,396 KB |
実行使用メモリ | 11,904 KB |
最終ジャッジ日時 | 2024-07-30 10:46:20 |
合計ジャッジ時間 | 4,890 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 22 |
ソースコード
#include <bits/stdc++.h>using namespace std;typedef long long ll;typedef pair<int,int> P;#define REP(i,n) for(int i=0;i<int(n);i++)int main(){cin.tie(nullptr); ios_base::sync_with_stdio(false);ll i,j,k;ll N;cin >> N;multiset<ll> s,t;bool f=false;for(i=1;i<=N;i++){ll x;cin >> x;if(x==0 && !f){s.insert(x);f=true;}else if(x>0) s.insert(x);else t.insert(-x);}ll n=s.size(),m=t.size();if(m+n==1){cout <<"Yes" << endl;return 0;}if(n==0 || m==0){cout <<"No" << endl;return 0;}while(1){ll a=*s.begin(),b=*t.begin();ll c=a-b;s.erase(s.begin());t.erase(t.begin());if(c>=0) s.insert(c);else t.insert(-c);n=s.size(),m=t.size();if(n==0 || m==0) break;}if(n==1 || m==1) cout <<"Yes" << endl;else cout <<"No" << endl;return 0;}