Submission #815229

#TimeUsernameProblemLanguageResultExecution timeMemory
815229blackyukiFountain Parks (IOI21_parks)C++17
55 / 100
417 ms41240 KiB
#include "parks.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll,ll> P; typedef tuple<ll,ll,ll> PP; typedef vector<ll> vi; typedef vector<vi> vvi; typedef vector<P> vp; typedef vector<vp> vvp; typedef vector<bool> vb; #define rep(i,n) for(ll i=0;i<(ll)(n);i++) #define REP(i,k,n) for(ll i=(ll)(k);i<(ll)(n);i++) #define all(a) a.begin(),a.end() #define fi first #define se second #define pb emplace_back #define lb(v,k) (lower_bound(all(v),k)-v.begin()) template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;} template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;} template<class T> void out(T a){cout<<a<<'\n';} template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';} const ll inf=1001001001001001001; struct UF{ ll n; vi par,sz; UF(ll n_):n(n_),par(n,-1),sz(n,1){} void merge(ll a,ll b){ a=root(a);b=root(b); if(a==b)return; if(sz[a]>sz[b])swap(a,b); par[a]=b; sz[b]+=sz[a]; } ll root(ll i){ if(par[i]==-1)return i; par[i]=root(par[i]); return par[i]; } bool same(ll a,ll b){ return root(a)==root(b); } ll getsz(ll i){ return sz[root(i)]; } }; int construct_roads(std::vector<int> x, std::vector<int> y) { ll n=x.size(); UF uf(n); vector<PP> v(n); rep(i,n)v[i]=PP(x[i],y[i],i); sort(all(v)); vi dx={2,0},dy={0,2}; set<P> S; vector<int> U, V, A, B; rep(i,n)rep(j,2){ P a(x[i],y[i]),b(x[i]+dx[j],y[i]+dy[j]); ll l=lb(v,PP(b.fi,b.se,-1)); if(l==n)continue; l=get<2>(v[l]); if(P(x[l],y[l])!=b)continue; P c((a.fi+b.fi)/2,(a.se+b.se)/2); if(a.fi==b.fi){ if((a.fi+a.se)%4==0)c.fi--; else c.fi++; } else{ if((a.fi+a.se)%4==0)c.se++; else c.se--; } uf.merge(i,l); if(S.insert(c).se){ U.pb(i); V.pb(l); A.pb(c.fi); B.pb(c.se); } } if(uf.getsz(0)<n)return 0; build(U,V,A,B); 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...