結果

問題 No.1265 Balloon Survival
ユーザー chocopuuchocopuu
提出日時 2020-11-27 19:44:12
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,441 ms / 2,000 ms
コード長 1,580 bytes
コンパイル時間 2,107 ms
コンパイル使用メモリ 210,164 KB
実行使用メモリ 66,096 KB
最終ジャッジ日時 2023-10-01 04:20:10
合計ジャッジ時間 18,404 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 69 ms
10,928 KB
testcase_15 AC 44 ms
8,996 KB
testcase_16 AC 13 ms
5,480 KB
testcase_17 AC 589 ms
36,508 KB
testcase_18 AC 21 ms
6,496 KB
testcase_19 AC 15 ms
5,712 KB
testcase_20 AC 63 ms
10,880 KB
testcase_21 AC 216 ms
19,692 KB
testcase_22 AC 101 ms
13,368 KB
testcase_23 AC 127 ms
14,452 KB
testcase_24 AC 1,441 ms
65,952 KB
testcase_25 AC 1,406 ms
65,836 KB
testcase_26 AC 1,412 ms
65,812 KB
testcase_27 AC 1,298 ms
65,824 KB
testcase_28 AC 1,315 ms
65,904 KB
testcase_29 AC 1,393 ms
65,888 KB
testcase_30 AC 1,348 ms
65,892 KB
testcase_31 AC 1,417 ms
65,808 KB
testcase_32 AC 1,261 ms
66,096 KB
testcase_33 AC 1,279 ms
65,884 KB
testcase_34 AC 2 ms
4,376 KB
testcase_35 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
//#include "atcoder/all"
//using namespace atcoder;
#define int long long
#define REP(i, n) for (int i = 0; i < (int)n; ++i)
#define RREP(i, n) for (int i = (int)n - 1; i >= 0; --i)
#define FOR(i, s, n) for (int i = s; i < (int)n; ++i)
#define RFOR(i, s, n) for (int i = (int)n - 1; i >= s; --i)
#define ALL(a) a.begin(), a.end()
#define IN(a, x, b) (a <= x && x < b)
template<class T>istream&operator >>(istream&is,vector<T>&vec){for(T&x:vec)is>>x;return is;}
template<class T>inline void out(T t){cout << t << "\n";}
template<class T,class... Ts>inline void out(T t,Ts... ts){cout << t << " ";out(ts...);}
template<class T>inline bool CHMIN(T&a,T b){if(a > b){a = b;return true;}return false;}
template<class T>inline bool CHMAX(T&a,T b){if(a < b){a = b;return true;}return false;}
constexpr int INF = 1e18;



signed main(){
	int N;
	cin >> N;
	int ans = 0;
	set<tuple<int, int, int>>st;
	vector<int> x(N), y(N);
	REP(i, N) cin >> x[i] >> y[i];
	auto cost = [&](int i, int j) -> int {
		return (x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]);
	};
	REP(i, N) {
		REP(j, N) {
			if(i == j) continue;
			st.insert({cost(i, j), i, j});
		}
	}
	int n = N;
	vector<int> erased(N);
	while(n > 1) {
		int dist, a, b;
		while(1) {
			tie(dist, a, b) = *st.begin();
			if(erased[a] == 0 && erased[b] == 0) break;
			else st.erase(st.begin());
		}
		st.erase(st.begin());
		if(a > b) swap(a, b); // a < b
		if(a == 0) {
			erased[b] = 1;
			++ans;
			--n;
		} else {
			erased[a] = erased[b] = 1;
			--n;--n;
		}
	}
	out(ans);
}
0