Submission #435487

#TimeUsernameProblemLanguageResultExecution timeMemory
435487errorgornFountain Parks (IOI21_parks)C++17
100 / 100
805 ms32088 KiB
#include "parks.h" #include <bits/stdc++.h> using namespace std; #define ll long long #define ii pair<ll,ll> #define fi first #define se second #define puf push_front #define pof pop_front #define pub push_back #define pob pop_back #define lb lower_bound #define ub upper_bound #define rep(x,s,e) for (auto x=s-(s>e);x!=e-(s>e);s<e?x++:x--) #define all(x) (x).begin(),(x).end() #define sz(x) (int) (x).size() struct UFDS{ int p[200005]; UFDS(){ rep(x,0,200005) p[x]=x; } int parent(int i){ if (p[i]==i) return i; else return p[i]=parent(p[i]); } void unions(int i,int j){ i=parent(i),j=parent(j); p[i]=j; } } ufds; int n; ii arr[200005]; //return values vector<int> id1,id2; vector<int> bx,by; map<ii,int> id; int construct_roads(std::vector<int> X, std::vector<int> Y) { n=sz(X); rep(x,0,n) arr[x]=ii(X[x],Y[x]); rep(x,0,n) id[arr[x]]=x; rep(x,0,n){ int i,j; tie(i,j)=arr[x]; if (id.count(ii(i,j+2))){ //vertical int temp=id[ii(i,j+2)]; ufds.unions(x,temp); //cout<<"ver: "<<x<<" "<<temp<<endl; if ((i+j)%4==0){ //left id1.pub(x); id2.pub(temp); bx.pub(i-1); by.pub(j+1); } else{ //right if possible if (!id.count(ii(i+2,j)) || !id.count(ii(i+2,j+2))){ id1.pub(x); id2.pub(temp); bx.pub(i+1); by.pub(j+1); } } } if (id.count(ii(i+2,j))){ //horizontal int temp=id[ii(i+2,j)]; ufds.unions(x,temp); //cout<<"hor: "<<x<<" "<<temp<<endl; if (j%4==0){ if (i%4==0){ //up id1.pub(x); id2.pub(temp); bx.pub(i+1); by.pub(j+1); } else{ //down id1.pub(x); id2.pub(temp); bx.pub(i+1); by.pub(j-1); } } else{ if (i%4==0){ //down if possible if (!id.count(ii(i,j-2)) || !id.count(ii(i+2,j-2))){ id1.pub(x); id2.pub(temp); bx.pub(i+1); by.pub(j-1); } } else{ //up if possible if (!id.count(ii(i,j+2)) || !id.count(ii(i+2,j+2))){ id1.pub(x); id2.pub(temp); bx.pub(i+1); by.pub(j+1); } } } } } rep(x,0,n) if (ufds.parent(0)!=ufds.parent(x)) return 0; build(id1,id2,bx,by); return 1; }
#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...