# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1203493 | BigBadBully | Portal (BOI24_portal) | C++20 | 0 ms | 0 KiB |
#include <bits/stdc++.h>
#define int long long
#define pii pair<int,int>
#define ff first
#define ss second
using namespace std;
int mcd(int a,int b)
{
if (a>b)swap(a,b);
if (a==0)return b;
a = abs(a),b = abs(b);
return __gcd(a,b);
}
signed main()
{
int n;
cin >> n;
vector<pii> v(n);
for (int i = 0; i < n ;i++)
cin >> v[i].ff >> v[i].ss;
for (int i = n-1; i >= 0; i--)
v[i].ff-=v[0].ff,v[i].ss-=v[0].ss;
int x = 0, y = 0;
for (int i = 0; i < n; i++)
{
y = mcd(v[i].ss,y);
for (int j = i+1; j < n; j++)
{
int add = 0;
if (v[i].ss == 0 && v[j].ss == 0)
add = mcd(v[i].ff,v[j].ff);
else
{
int lc = v[i].ss*v[j].ss/mcd(v[i].ss,v[j].ss);
int c1 = lc/(v[j].ss != 0 ? v[j].ss : 1);
int c2 = lc/(v[i].ss != 0 ? v[i].ss : 1);
add = c2*v[i].ff - c1*v[j].ff;
}
x = mcd(x,add);
}
}
if (x*y == 0)
cout << -1;
else
cout << x*y;
return 0;
}