結果

問題 No.1265 Balloon Survival
ユーザー bonKotsubonKotsu
提出日時 2020-12-11 14:18:43
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 131 ms / 2,000 ms
コード長 1,318 bytes
コンパイル時間 1,904 ms
コンパイル使用メモリ 177,264 KB
実行使用メモリ 12,156 KB
最終ジャッジ日時 2023-10-20 01:28:20
合計ジャッジ時間 4,449 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
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 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 12 ms
4,392 KB
testcase_15 AC 10 ms
4,392 KB
testcase_16 AC 5 ms
4,348 KB
testcase_17 AC 63 ms
12,152 KB
testcase_18 AC 6 ms
4,348 KB
testcase_19 AC 5 ms
4,348 KB
testcase_20 AC 13 ms
4,392 KB
testcase_21 AC 27 ms
5,440 KB
testcase_22 AC 18 ms
5,440 KB
testcase_23 AC 18 ms
5,440 KB
testcase_24 AC 122 ms
12,156 KB
testcase_25 AC 124 ms
12,156 KB
testcase_26 AC 125 ms
12,156 KB
testcase_27 AC 127 ms
12,156 KB
testcase_28 AC 129 ms
12,156 KB
testcase_29 AC 126 ms
12,156 KB
testcase_30 AC 127 ms
12,156 KB
testcase_31 AC 122 ms
12,156 KB
testcase_32 AC 129 ms
12,156 KB
testcase_33 AC 131 ms
12,156 KB
testcase_34 AC 2 ms
4,348 KB
testcase_35 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

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