#include <iostream>
#include <vector>.
#include <cmath>
#include <complex>
using namespace std;
typedef pair<long long, long long> pt;
long long d(pt a, pt b) {
return a.first*b.first+a.second*b.second;
}
long long det(pt a,pt b) {
return a.first*b.second-a.second*b.first;
}
long long di(long long a, long long b) {
double a1 = a;
double b1 = b;
return floor(a1/b1);
}
int k = 0;
pt mod(pt a,pt b, pt c) {
long long multb = di(d(b,c),(b.first*b.first+b.second*b.second));
long long multa = di(d(a,c),(a.first*a.first+a.second*a.second));
pt mc = {c.first-b.first*multb-a.first*multa,c.second-b.second*multb-a.second*multa};
return mc;
}
pt d1red(pt a,pt b) {
pt p = {0,0};
long long mult = di(d(a,b),(a.first*a.first+a.second*a.second));
b = {b.first-a.first*mult,b.second-a.second*mult};
if(b==a) return a;
if(b==p) return a;
return d1red(b,a);
}
pt normalize(pt a) {
if(a.first<0) return {-a.first,-a.second};
if(a.first==0 && a.second<0) return {-a.first,-a.second};
return a;
}
pair<pt,pt> reduce(pt a, pt b, pt c) {
pt p = {0,0};
if(a==b) return {a,b};
if(a==c) return {a,b};
if(c==b) return {a,b};
if(a==p ||b==p||c==p) exit(1);
if(det(a,b)==0) {
return {
d1red(a,b),c};
}
if(det(a,c)==0) {
return {
d1red(a,c),b};
}if(det(b,c)==0) {
return {
d1red(c,b),a};
}
pt c2 = mod(a,b,c);
if(c==c2)
if(c == p) return {a,b};
return reduce(c,a,b);
}
int main() {
int n; cin>>n;
if(n<3) {
cout<<-1<<endl;
return 0;
}
pt prev;
cin>>prev.first>>prev.second;
vector<pt> t(n-1);
for (int i = 0; i < n-1; ++i) {
int x,y; cin>>x>>y;
t[i] = {prev.first-x,prev.second-y};
prev = {x,y};
}
pair<pt,pt> res = {t[0],t[1]};
for (int i = 0; i < n-3; ++i) {
k=0;
res = reduce(res.first,res.second,t[i+2]);
}
pt p = {0,0};
if(res.first==res.second || res.first==p || res.second==p|| det(res.first,res.second)==0) {
cout<<-1<<endl;
return 0;
}else {
cout<<abs(res.first.first*res.second.second-res.first.second*res.second.first)<<endl;
return 0;
}
}
Compilation message (stderr)
Main.cpp:2:18: warning: extra tokens at end of #include directive
2 | #include <vector>.
| ^
# | 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... |