제출 #771357

#제출 시각아이디문제언어결과실행 시간메모리
771357TimDeeRectangles (IOI19_rect)C++17
37 / 100
4614 ms140232 KiB
#include "rect.h" #include <bits/stdc++.h> using namespace std; #define forn(i,n) for(int i=0; i<n; ++i) #define pi pair<int,int> #define f first #define s second #define ll long long #define pb push_back #define all(x) x.begin(),x.end() const int N=700; struct dsu { vector<int> p,sz,l,r; dsu(int n) { forn(i,n) p.pb(i), sz.pb(1); l=r=p; } int get(int u) { return p[u]==u?u:get(p[u]); } void uni(int u, int v) { u=get(u),v=get(v); if (u==v) return; if (sz[u]<sz[v]) swap(u,v); p[v]=u; sz[u]+=sz[v]; l[u]=min(l[u],l[v]); r[u]=max(r[u],r[v]); } }; vector<dsu> dsu1(N,dsu(N)), dsu2(N,dsu(N)); int ok[N][N]; int a[N][N]; bitset<N> dp1[N][N], dp2[N][N]; int ite=0; int check(int l, int u, int r, int d) { int ok=1; for (int i=l; i<=r; ++i) { ok&=dp1[i][u][d]; } for (int i=u; i<=d; ++i) { ok&=dp2[i][l][r]; } return ok; } ll count_rectangles(vector<vector<int>> b) { int n=b.size(), m=b[0].size(); if (min(n,m)<3) return 0; if (n==3) { ll ans=0; for (int i=0; i<m; ++i) { int mx=0; for (int j=i+1; j<m-1; ++j) { if (b[0][j]<=b[1][j] || b[1][j]>=b[2][j]) break; mx=max(mx,b[1][j]); ans += b[1][i]>mx && mx<b[1][j+1]; } } return ans; } if (max(n,m)>N) exit(0); forn(i,n) forn(j,m) a[i][j]=b[i][j]; forn(i,n) { for (int l=0; l<m; ++l) { int mx=0; for (int r=l+1; r+1<m; ++r) { mx=max(mx,a[i][r]); dp1[i][l+1][r]=a[i][l]>mx && mx<a[i][r+1]; } } } forn(i,m) { for (int l=0; l<n; ++l) { int mx=0; for (int r=l+1; r+1<n; ++r) { mx=max(mx,a[r][i]); dp2[i][l+1][r]=a[l][i]>mx && mx<a[r+1][i]; } } } vector<pi> v; forn(i,n) forn(j,m) v.pb({a[i][j],i*m+j}); sort(all(v)); ll ans=0; int N=v.size(); map<ll,ll> was; for(int i=0; i<N; ) { vector<int> z; int x=v[i].f; while (i<N && v[i].f==x) { z.pb(v[i].s); ++i; } for(auto&it:z) { int x=it/m, y=it%m; if (x) if (ok[x-1][y]) dsu1[y].uni(x-1,x); if (x<n-1) if (ok[x+1][y]) dsu1[y].uni(x+1,x); if (y) if (ok[x][y-1]) dsu2[x].uni(y-1,y); if (y<m-1) if (ok[x][y+1]) dsu2[x].uni(y+1,y); ok[x][y]=1; } for(auto&it:z) { int x=it/m, y=it%m; int u=dsu1[y].get(x); int a=dsu1[y].l[u], c=dsu1[y].r[u]; int v=dsu2[x].get(y); int b=dsu2[x].l[v], d=dsu2[x].r[v]; if (a==0 || b==0 || c==n-1 || d==m-1) continue; if (was[1ll*a*m+b+1ll*n*m*(1ll*c*m+d)]) continue; was[1ll*a*m+b+1ll*n*m*(1ll*c*m+d)]=1; if (ite<=3e8) { int q = check(a,b,c,d); ans+=q; ite+=c-a+d-b+2; } else exit(0); } } return ans; }
#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...