結果

問題 No.1265 Balloon Survival
ユーザー tkmst201tkmst201
提出日時 2020-12-01 19:55:15
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,253 ms / 2,000 ms
コード長 1,308 bytes
コンパイル時間 2,716 ms
コンパイル使用メモリ 211,364 KB
実行使用メモリ 13,004 KB
最終ジャッジ日時 2023-10-11 03:41:59
合計ジャッジ時間 18,111 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,352 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,352 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,352 KB
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 1 ms
4,352 KB
testcase_07 AC 1 ms
4,348 KB
testcase_08 AC 2 ms
4,352 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 1 ms
4,352 KB
testcase_12 AC 2 ms
4,352 KB
testcase_13 AC 2 ms
4,352 KB
testcase_14 AC 59 ms
4,372 KB
testcase_15 AC 39 ms
4,352 KB
testcase_16 AC 11 ms
4,348 KB
testcase_17 AC 488 ms
11,680 KB
testcase_18 AC 18 ms
4,352 KB
testcase_19 AC 13 ms
4,352 KB
testcase_20 AC 57 ms
4,352 KB
testcase_21 AC 171 ms
5,204 KB
testcase_22 AC 85 ms
5,324 KB
testcase_23 AC 98 ms
5,264 KB
testcase_24 AC 1,233 ms
11,488 KB
testcase_25 AC 1,230 ms
12,020 KB
testcase_26 AC 1,232 ms
11,616 KB
testcase_27 AC 1,229 ms
12,188 KB
testcase_28 AC 1,233 ms
13,004 KB
testcase_29 AC 1,230 ms
12,048 KB
testcase_30 AC 1,237 ms
12,712 KB
testcase_31 AC 1,228 ms
12,436 KB
testcase_32 AC 1,228 ms
11,604 KB
testcase_33 AC 1,253 ms
11,404 KB
testcase_34 AC 2 ms
4,356 KB
testcase_35 AC 2 ms
4,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
template<typename A, typename B> inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; }
template<typename A, typename B> inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = false;
//---------------------------------//

int main() {
	int N;
	cin >> N;
	vector<int> X(N), Y(N);
	REP(i, N) scanf("%d %d", &X[i], &Y[i]);
	
	using tup = tuple<ll, int, int>;
	priority_queue<tup, vector<tup>, greater<tup>> pq;
	REP(i, N) FOR(j, i + 1, N) {
		const ll dx = X[j] - X[i], dy = Y[j] - Y[i];
		pq.emplace(dx * dx + dy * dy, i, j);
	}
	int ans = 0;
	vector<bool> alive(N, true);
	ll prevd = -1;
	vector<int> v;
	while (!pq.empty()) {
		auto [dist, x, y] = pq.top(); pq.pop();
		if (prevd != dist) {
			for (int i : v) alive[i] = false;
			prevd = dist;
		}
		if (!alive[x] || !alive[y]) continue;
		if (x == 0) {
			++ans;
			alive[y] = false;
		}
		else {
			v.emplace_back(x);
			v.emplace_back(y);
		}
	}
	cout << ans << endl;
}
0