#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define MASK(i) (1ULL << (i))
#define GETBIT(mask, i) (((mask) >> (i)) & 1)
#define ALL(v) (v).begin(), (v).end()
ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}
ll gcd(ll a, ll b){return __gcd(abs(a), abs(b));}
ll lcm(ll a, ll b){return abs(a) / gcd(a, b) * abs(b);}
ll LASTBIT(ll mask){return (mask) & (-mask);}
int pop_cnt(ull mask){return __builtin_popcountll(mask);}
int ctz(ull mask){return __builtin_ctzll(mask);}
int logOf(ull mask){return 63 - __builtin_clzll(mask);}
mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
ll rngesus(ll l, ll r){return l + (ull) rng() % (r - l + 1);}
template <class T1, class T2>
bool maximize(T1 &a, T2 b){
if (a < b) {a = b; return true;}
return false;
}
template <class T1, class T2>
bool minimize(T1 &a, T2 b){
if (a > b) {a = b; return true;}
return false;
}
template <class T>
void printArr(T container, string separator = " ", string finish = "\n", ostream &out = cout){
for(auto item: container) out << item << separator;
out << finish;
}
template <class T>
void remove_dup(vector<T> &a){
sort(ALL(a));
a.resize(unique(ALL(a)) - a.begin());
}
#define lll __int128
vector<pair<lll,lll>> gg;
// lll abs(lll a){
// return (a < 0) ? (-a) : a;
// }
lll gcd(lll a, lll b){
a = abs(a), b = abs(b);
while(a > 0 && b > 0){
tie(a, b) = make_pair(b % a, a);
}
return a + b;
}
void make_positive(pair<lll, lll> &a){
if (a.first < 0){
a = make_pair(-a.first, -a.second);
}
else if (a.first == 0 && a.second < 0){
a = make_pair(-a.first, -a.second);
}
}
void vector_gcd(pair<lll, lll> &a, pair<lll, lll> &b){
while(a.first != 0){
make_positive(a);
make_positive(b);
lll d = b.first / a.first;
b.first -= a.first * d;
b.second -= a.second * d;
swap(a, b);
}
make_positive(a);
make_positive(b);
}
void update(pair<lll, lll> v){
for(pair<lll, lll> &i: gg){
if (i.first * v.second == i.second * v.first){
lll x1 = abs(i.first) + abs(i.second);
lll x2 = abs(v.first) + abs(v.second);
lll g = gcd(x1, x2);
i.first /= (x1 / g);
i.second /= (x1 / g);
return;
}
}
if (gg.size() < 2) {
gg.push_back(v);
if (gg.size() == 2){
vector_gcd(gg[0], gg[1]);
}
return;
}
vector_gcd(gg[0], v);
vector_gcd(gg[1], v);
lll g = gcd(abs(gg[0].second), abs(gg[1].second));
gg.clear();
gg.push_back(make_pair(0, g));
gg.push_back(v);
}
ll solve(){
int n; cin >> n;
vector<pair<ll, ll>> a(n);
for(int i = 0; i < n; ++i) cin >> a[i].first >> a[i].second;
sort(ALL(a));
vector<pair<ll,ll>> b;
for(int i = 1; i < n; ++i){
b.push_back(make_pair(a[i].first - a[0].first, a[i].second - a[0].second));
}
for(pair<ll, ll> i: b){
pair<lll, lll> tmp = make_pair((lll)i.first, (lll)i.second);
update(tmp);
}
if (gg.size() < 2){
return -1;
}
else{
ll y = gg[0].second;
ll x = 0;
for(pair<ll, ll> i: b) x = gcd(x, abs(i.first));
return x * y;
}
}
int main(void){
ios::sync_with_stdio(0);cin.tie(0); cout.tie(0);
clock_t start = clock();
cout << solve() << "\n";
cerr << "Time elapsed: " << clock() - start << "ms!\n";
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |