結果

問題 No.1265 Balloon Survival
コンテスト
ユーザー polylogK
提出日時 2020-10-23 22:09:08
言語 C++17
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 48 ms / 2,000 ms
コード長 1,119 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,196 ms
コンパイル使用メモリ 221,620 KB
実行使用メモリ 12,008 KB
最終ジャッジ日時 2026-06-14 17:13:19
合計ジャッジ時間 3,389 ms
ジャッジサーバーID
(参考情報)
judge3_1 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 32
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = std::int_fast64_t;
using std::cout;
using std::cerr;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

i64 calc(i64 a, i64 b, i64 c, i64 d) {
	return (a - c) * (a - c) + (b - d) * (b - d);
}

int main() {
	int n; scanf("%d", &n);
	std::vector<int> x(n), y(n);
	for(int i = 0; i < n; i++) scanf("%d%d", &x[i], &y[i]);

	std::vector<std::tuple<i64, int, int>> vec;
	for(int i = 0; i < n; i++) {
		for(int j = i + 1; j < n; j++) {
			vec.push_back({calc(x[i], y[i], x[j], y[j]), i, j});
		}
	}
	sort(begin(vec), end(vec));

	std::vector<int> bombed(n);
	std::vector<int> deleted(n);
	for(auto [_, i, j]: vec) {
		if(bombed[i] or bombed[j] or deleted[i] or deleted[j]) continue;
		if(i == 0) deleted[j] = true;
		else bombed[i] = bombed[j] = true;
	}

	printf("%d\n", std::accumulate(begin(deleted), end(deleted), 0));
	return 0;
}
0