Submission #1045238

#TimeUsernameProblemLanguageResultExecution timeMemory
1045238Darren0724Portal (BOI24_portal)C++17
1 / 100
40 ms3604 KiB
#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=4e18; const int mod=1e9+7; const int N=200005; const int K=20; int32_t main(){ LCBorz; int n;cin>>n; int flag=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}; v1[i]={b,a}; } sort(all(v)); sort(all(v1)); int g1=-1,g2=-1; int rec1=0,rec2=0; for(int i=1;i<n;i++){ if(v[i].x==v[i-1].x){ int t=abs(v[i].y-v[i-1].y); g2=(g2==-1?t:__gcd(g2,t)); flag=1; rec1=1; } else{ int t=abs(v[i].x-v[i-1].x); if(rec1)g1=(g1==-1?t:__gcd(g1,t)); rec1=0; } if(v1[i].x==v1[i-1].x){ int t=abs(v1[i].y-v1[i-1].y); g1=(g1==-1?t:__gcd(g1,t)); flag=1; rec2=1; } else{ int t=abs(v1[i].x-v1[i-1].x); if(rec2)g2=(g2==-1?t:__gcd(g2,t)); rec2=0; } } //cout<<g1<<' '<<g2<<endl; if(!flag){ cout<<-1<<endl; } else{ cout<<g1*g2<<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...