結果

問題 No.2812 Plus Minus Blackboard
ユーザー risujiroh
提出日時 2024-07-19 21:40:59
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 716 bytes
コンパイル時間 3,453 ms
コンパイル使用メモリ 279,340 KB
実行使用メモリ 7,720 KB
最終ジャッジ日時 2025-04-08 23:41:58
合計ジャッジ時間 4,982 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 21 WA * 2
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using Int = int64_t;

void Solve() {
  Int n;
  std::cin >> n;
  std::priority_queue qn(std::greater{}, std::vector<Int>{});
  std::priority_queue qp(std::greater{}, std::vector<Int>{});
  while (n--) {
    Int a;
    std::cin >> a;
    if (a < 0) {
      qn.push(-a);
    } else if (0 < a) {
      qp.push(a);
    }
  }
  while (qn.size() && qp.size()) {
    Int x = qn.top();
    qn.pop();
    Int y = qp.top();
    qp.pop();
    Int z = y - x;
    if (z < 0) {
      qn.push(-z);
    } else if (0 < z) {
      qp.push(z);
    }
  }
  std::cout << (qn.size() + qp.size() == 1 ? "Yes\n" : "No\n");
}

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);

  Solve();
}
0