結果

問題 No.1265 Balloon Survival
ユーザー bonKotsubonKotsu
提出日時 2020-12-11 13:19:16
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,318 bytes
コンパイル時間 1,732 ms
コンパイル使用メモリ 177,016 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-20 01:27:26
合計ジャッジ時間 6,326 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 2 ms
4,348 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 2 ms
4,348 KB
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
testcase_33 RE -
testcase_34 AC 2 ms
4,348 KB
testcase_35 RE -
権限があれば一括ダウンロードができます

ソースコード

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