Submission #736705

#TimeUsernameProblemLanguageResultExecution timeMemory
736705bobthebuilderRectangles (IOI19_rect)C++17
10 / 100
6 ms596 KiB
#include "rect.h" #include<bits/stdc++.h> using namespace std; #define sz(x) (int)x.size() #define REP(i,n) for(int i=0;i<n;i++) #define REP1(i,n) for(int i=1;i<=n;i++) #define pb push_back #define lowb(x) (x&(-x)) #define ALL(x) x.begin(),x.end() #define pii pair<int,int> #define f first #define s second #define SORT_UNIQUE(x) sort(ALL(x)),x.erase(unique(ALL(x)),x.end()) const int maxn=3e3+5; #define ll long long pii rng[maxn]; int par[maxn]; bool ded[maxn]; int find(int u){ if(par[u]==u) return u; return par[u]=find(par[u]); } void merge(int a,int b){ a=find(a),b=find(b); if(a==b) return; rng[b]={min(rng[a].f,rng[b].f),max(rng[a].s,rng[b].s)}; par[a]=b; } long long count_rectangles(std::vector<std::vector<int> > a) { int n=sz(a),m=sz(a[0]); map<pii,vector<int>> mp; REP1(i,n-2){ vector<pii> v; REP(j,m) rng[j]={j,j},par[j]=j; REP(j,m){ if(a[i-1][j]<=a[i][j] or a[i+1][j]<=a[i][j]){ ded[j]=1; } v.pb({a[i][j],j}); } sort(ALL(v)); vector<pii> vv; for(int j=0;j<sz(v);){ int p=j; vector<int> ps; while(j<sz(v) and v[p].f==v[j].f){ int z=v[j].s; if(z and a[i][z-1]<=a[i][z]) merge(z-1,z); if(z+1<m and a[i][z+1]<=a[i][z]) merge(z,z+1); ps.pb(z); ++j; } for(int x:ps){ auto z=rng[find(x)]; if(z.f and z.s!=m-1) { bool ok=1; for(int j=z.f;j<=z.s;j++){ if(ded[j]){ ok=0; break; } assert(a[i][j]<a[i][z.f-1] and a[i][j]<a[i][z.s+1]); } if(ok) vv.pb(z); } } } SORT_UNIQUE(vv); for(auto x:vv){ mp[x].pb(i); } return sz(vv); } 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...
#Verdict Execution timeMemoryGrader output
Fetching results...