Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <queue>
- #include <iostream>
- #include <vector>
- #include <cstring>
- #include <iostream>
- #include <set>
- #include <cstring>
- #include <stack>
- //#include <bits/stdc++.h>
- using namespace std;
- typedef long long ll;
- const int maxn = 3e5 + 10;
- const ll INF = 3e16 + 10;
- int main() {
- ios_base::sync_with_stdio(false);
- int n;
- cin >> n;
- vector<pair<int, int>> points(n);
- for(int i = 0; i < n; i++) {
- cin >> points[i].first >> points[i].second;
- }
- sort(points.begin(), points.end());
- set<pair<int, int>> st;
- st.insert(make_pair(points[0].first, points[0].second));
- ll shortest_distance = 1e9, result = 1e18;
- for(int i = 1; i < n; i++) {
- set<pair<int, int>>::iterator it1 = st.lower_bound(make_pair(points[i].first - shortest_distance, points[i].second - shortest_distance));
- set<pair<int, int>>::iterator it2 = st.upper_bound(make_pair(points[i].first, points[i].second + shortest_distance));
- if(it1 == st.end()) {
- continue;
- }
- for(set<pair<int, int>>::iterator it = it1; it != it2; it++) {
- ll dist = (points[i].first - it->first) * (points[i].first - it->first) + (points[i].second - it->second) * (points[i].second - it->second);
- result = min(result, dist);
- }
- st.insert(make_pair (points[i].first, points[i].second));
- }
- cout << sqrt(result) << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement