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 <algorithm>
- #include <map>
- #include <cmath>
- //#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>> cords(n);
- for(int i = 0; i < n; i++) {
- cin >> cords[i].first >> cords[i].second;
- }
- sort(cords.begin(), cords.end());
- set<pair<int, int>> st;
- st.insert(make_pair(cords[0].first, cords[0].second));
- ll shortest_distance = 1e9, result = 1e9;
- for(int i = 1; i < n; i++) {
- set<pair<int, int>>::iterator it1 = st.lower_bound(make_pair(cords[i].first - shortest_distance, cords[i].second - shortest_distance));
- set<pair<int, int>>::iterator it2 = st.upper_bound(make_pair(cords[i].first + shortest_distance, cords[i].second + shortest_distance));
- if(it1 == st.end()) {
- continue;
- }
- for(set<pair<int, int>>::iterator it = it1; it != it2; it++) {
- ll dist = (cords[i].first - it->first) * (cords[i].first - it->first) + (cords[i].second - it->second) * (cords[i].second - it->second);
- result = min(result, dist);
- shortest_distance = min(shortest_distance, dist);
- }
- st.insert(make_pair(cords[i].first, cords[i].second));
- }
- cout << sqrt(result) << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement