結果

問題 No.1265 Balloon Survival
ユーザー bonKotsubonKotsu
提出日時 2020-12-11 14:13:04
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,317 bytes
コンパイル時間 1,665 ms
コンパイル使用メモリ 176,720 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-09-19 21:17:29
合計ジャッジ時間 5,571 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3 WA * 1
other AC * 5 WA * 6 RE * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define P pair<int, int>

int main() {
  int N;
  cin >> N;

  vector<ll> x(N), y(N);
  rep(i, N) cin >> x[i] >> y[i];

  priority_queue<pair<ll, P>, vector<pair<ll, P>>, greater<pair<ll, P>>> que;

  rep(i, N) {
    for (int j = i+1; j < N; j++) {
      ll d = (x[i]-x[j]) * (x[i]-x[j]) + (y[i-y[j]]) * (y[i]-y[j]);
      que.push({d, {i,j}});
    } 
  }

  vector<bool> excluded(N, false); // i 番目の風船を除いたか
  int ans = 0;

  while(que.size()) {

    pair<ll, P> p = que.top(); // 次に破裂する組み合わせ

    int b1 = p.second.first, b2 = p.second.second;

    // もう風船が既になければ無視してよい(b1 == 0 も含む)
    if (excluded[b1] || excluded[b2]) {
      que.pop();
      continue;
    }

    // 風船1(0)でなければ勝手に取り除かれるので,最初に取り除かなくて良い
    if (b1 != 0 && b2 != 0) {
      que.pop();
      excluded[b1] = true, excluded[b2] = true;
      continue;
    }

    // 風船1 風船が消えていなかったら事前に取り除く必要あり
    if (b1 == 0 && !excluded[b2]) {
      ans++;
      que.pop();
      excluded[b2] = true;
      continue;
    }
  }

  cout << ans << endl;



}
0