結果
| 問題 |
No.2812 Plus Minus Blackboard
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-07-19 22:05:16 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 37 ms / 2,000 ms |
| コード長 | 841 bytes |
| コンパイル時間 | 1,730 ms |
| コンパイル使用メモリ | 202,168 KB |
| 実行使用メモリ | 6,272 KB |
| 最終ジャッジ日時 | 2025-06-20 02:14:28 |
| 合計ジャッジ時間 | 3,331 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 35 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
void solve() {
ll n;
cin >> n;
vector<ll> pos, neg;
rep(i, n) {
ll a;
cin >> a;
if (a > 0)
pos.push_back(a);
if (a < 0)
neg.push_back(-a);
}
sort(pos.rbegin(), pos.rend());
sort(neg.rbegin(), neg.rend());
while (!pos.empty() && !neg.empty()) {
ll p = pos.back();
pos.pop_back();
ll n = neg.back();
neg.pop_back();
if (p > n) {
pos.push_back(p - n);
} else if (p < n) {
neg.push_back(n - p);
}
}
bool ok = pos.size() + neg.size() <= 1;
cout << (ok ? "Yes" : "No") << '\n';
}
int main() {
std::cin.tie(nullptr);
std::ios_base::sync_with_stdio(false);
int T = 1;
for (int t = 0; t < T; t++) {
solve();
}
return 0;
}