이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define int long long
#define all(x) x.begin(),x.end()
#define pii pair<int,int>
#define rz resize
#define pb emplace_back
#define LCBorz ios_base::sync_with_stdio(false);cin.tie(0);
#define endl '\n'
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
const int INF=9e18;
const int mod=1e9+7;
const int N=200005;
const int K=20;
const int C=2000005;
int gcd(int a,int b){
return abs(__gcd(a,b));
}
int32_t main(){
LCBorz;
int n;cin>>n;
if(n<=2){
cout<<-1<<endl;
return 0;
}
vector<pair<int,int>> v(n),v1(n);
for(int i=0;i<n;i++){
int a,b;cin>>a>>b;
v[i]={a,b};
}
sort(all(v));
for(int i=1;i<n;i++){
v[i].x-=v[0].x;
v[i].y-=v[0].y;
}
int ans=INF;
if(v[1].y==0&&v[2].y==0){
cout<<-1<<endl;
return 0;
}
if(v[1].y==0){
cout<<abs(v[1].x*v[2].y)<<endl;
return 0;
}
if(v[2].y==0){
cout<<abs(v[2].x*v[1].y)<<endl;
return 0;
}
//cout<<v[1].x<<' '<<v[1].y<<' '<<v[2].x<<' '<<v[2].y<<endl;
int r1=v[2].y/gcd(v[1].y,v[2].y);
for(int i=r1;i<=r1;i++){
int t=v[1].y*i;
int t1=t/v[2].y;
int x1=abs(v[1].x*i-v[2].x*t1);
if(x1!=0&&x1<ans){
ans=x1;
break;
}
}
cout<<(ans==INF?-1:ans*gcd(v[1].y,v[2].y))<<endl;
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... |