This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int, int>
#define P complex<int>
int N;
int cross(P a, P b){
return (a * conj(b)).imag();
}
vector<int> vec(P p){
return {p.real(), p.imag()};
}
void cancel(P& a, P& b, int dim){
if(vec(b)[dim] == 0){
return;
}
if(vec(a)[dim] == 0){
swap(a, b);
return;
}
int nb_in = vec(b)[dim]/vec(a)[dim];
b -= nb_in *a;
swap(a, b);
cancel(a, b, dim);
}
void compress(vector<P>& v){
vector<P> res;
for(int dim = 0; dim<2; dim++){
int cur_c = dim;
for(int i = dim; i<v.size(); i++){
if(vec(v[i])[dim] != 0){
cur_c = i;
}
}
if(vec(v[cur_c])[dim]==0){
continue;
}
swap(v[dim], v[cur_c]);
for(int i = dim+1; i<v.size(); i++){
cancel(v[dim], v[i], dim);
}
res.push_back(v[dim]);
}
v = res;
}
signed main(){
cin>>N;
vector<P> portals(N);
for(int i = 0; i<N; i++){
pii pos;
cin>>pos.first>>pos.second;
portals[i] = {pos.first, pos.second};
}
P origin = portals.back();
for(P& portal: portals){
portal -= origin;
}
portals.pop_back();
vector<P> base = portals;
if(N<3){
cout<<-1<<endl;
return 0;
}
compress(base);
if(base.size()<2){
cout<<-1<<endl;
return 0;
}
cout<<abs(cross(base[0], base[1]))<<endl;
}
Compilation message (stderr)
Main.cpp: In function 'void compress(std::vector<std::complex<long long int> >&)':
Main.cpp:36:27: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::complex<long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
36 | for(int i = dim; i<v.size(); i++){
| ~^~~~~~~~~
Main.cpp:46:29: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::complex<long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
46 | for(int i = dim+1; i<v.size(); i++){
| ~^~~~~~~~~
# | 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... |