結果
| 問題 |
No.1265 Balloon Survival
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-12-11 14:18:43 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 104 ms / 2,000 ms |
| コード長 | 1,318 bytes |
| コンパイル時間 | 1,652 ms |
| コンパイル使用メモリ | 176,188 KB |
| 実行使用メモリ | 11,740 KB |
| 最終ジャッジ日時 | 2024-09-19 21:17:33 |
| 合計ジャッジ時間 | 3,816 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 32 |
ソースコード
#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;
}