#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define vs vector<string>
#define vc vector<char>
#define vb vector<bool>
#define vp vector<pair<ll, ll>>
#define vpp vector<pair<ll, pair<ll, ll>>>
#define pp pair<ll, ll>
#define qi queue<ll>
#define qp queue<pp>
#define pqi priority_queue<ll>
#define pqp priority_queue<pp>
#define mi map<ll, ll>
#define mpi map<pp, ll>
#define mip map<ll, pp>
#define mp map<pp, pp>
#define mb map<ll, bool>
#define si set<ll>
#define sp set<pp>
#define sc set<char>
#define mod 1000000007
#define inf INT_MAX
#define all(x) (x).begin(), (x).end()
ll cross(pp a, pp b) {
return abs(a.first * b.second - a.second * b.first);
}
ll GCD(ll a, ll b) {
if(b == 0) return a;
return GCD(b, a % b);
}
pp vec_gcd(pp a, pp b) {
return {GCD(a.first, b.first), GCD(a.second, b.second)};
}
pair<pp, pp> pal_gcd(pp a, pp b, pp c) {
if(cross(a, b) == 0) {
a = vec_gcd(a, b);
b = c;
return {a, b};
}
if(cross(a, c) == 0) {
a = vec_gcd(a, c);
return {a, b};
}
if(cross(b, c) == 0) {
b = vec_gcd(b, c);
return {a, b};
}
ll dem = a.first * b.second - a.second * b.first;
ll k = (c.first * b.second - c.second * b.first) / dem;
ll l = (a.first * c.second - a.second * c.first ) / dem;
pp remainder;
remainder.first = c.first - k * a.first - l * b.first;
remainder.second = c.second - k * a.second - l * b.second;
return pal_gcd(a, remainder, b);
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
ll n;
cin >> n;
vp ar(n);
for(int i = 0; i < n; i++) {
cin >> ar[i].first >> ar[i].second;
}
if(n <= 2) {
cout << "-1\n";
return 0;
}
vp v;
for(int i = 1; i < n; i++) {
ll x = ar[0].first - ar[i].first;
ll y = ar[0].second - ar[i].second;
v.push_back({x, y});
}
pp base;
for(int i = 1; i < v.size(); i++) {
if(v[i] == v[0]) {
if(i + 1 == v.size()) {
cout << "-1\n";
return 0;
}
continue;
}
ll x = v[0].first - v[i].first;
ll y = v[0].second - v[i].second;
base = {x, y};
break;
}
pp a = v[0];
pp b;
ll ans = 0;
for(int i = 1; i < v.size(); i++) {
swap(v[i], v[1]);
b = v[1];
ll cur = cross(a, b);
ans = cur;
if(ans != 0) {
break;
}
}
if(ans == 0) {
cout << "-1\n";
return 0;
}
for(int i = 2; i < v.size(); i++) {
auto p = pal_gcd(a, b, v[i]);
a = p.first;
b = p.second;
}
ans = cross(a, b);
cout << ans << '\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... |