Submission #1179117

#TimeUsernameProblemLanguageResultExecution timeMemory
1179117razivoPortal (BOI24_portal)C++20
1 / 100
648 ms1114112 KiB
#include <iostream>
#include <vector>
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;
}
pt mod(pt a,pt b, pt c) {
    if(a.first<0) {a.first*=-1; a.second*=-1;}
    if(b.second<0) {b.first*=-1; b.second*=-1;}
    long long multb = d(b,c)/(b.first*b.first+b.second*b.second);
    long long multa = d(a,c)/(a.first*a.first+a.second*a.second);
    return {c.first-b.first*multb-a.first*multa,c.second-b.second*multb-a.second*multa};
}
pair<pt,pt> reduce(pt a, pt b, pt c) {
    if(a==b) return {b,c};
    c = mod(a,b,c);
    pt p = {0,0};
    if(c == p) return {a,b};
    return reduce(b,c,a);
}
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};
    }
    pair<pt,pt> res = {t[0],t[1]};
    for (int i = 0; i < n-3; ++i) {
        res = reduce(res.first,res.second,t[i+2]);
    }
    pt p = {0,0};
    if(res.first==res.second || res.first==p || res.second==p) {
        cout<<-1<<endl;
        return 0;
    }else {
        cout<<abs(res.first.first*res.second.second-res.first.second*res.second.first)<<endl;
        return 0;
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...