This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "rect.h"
#include <bits/stdc++.h>
#define ll long long
#define fast cin.tie(0);cout.tie(0);
#define order ios::sync_with_stdio(0);ios_base::sync_with_stdio(0);
#define pb push_back
using namespace std;
int n,m,a[2509][2509],mxx[1009][1009],my[2509],acx[1009][1009],acy[1009][1009];
int rec(int x,int y,int x2,int y2)
{
if(acx[x2][y2]&&acy[x2][y2])return 1;
return 0;
}
ll check(int x,int y)
{
ll ret=0;
for(int i=x;i<n-1;i++)
{
mxx[i][y-1]=0;
for(int j=y;j<m-1;j++)
{
mxx[i][j]=max(mxx[i][j-1],a[i][j]);
if(i==x)my[j]=a[i][j];
else my[j]=max(my[j],a[i][j]);
int mx=mxx[i][j];
if(mx<a[i][j+1]&&mx<a[i][y-1])
{
if(i!=x)acx[i][j]=acx[i-1][j];
else acx[i][j]=1;
}
else acx[i][j]=0;
mx=my[j];
if(mx<a[x-1][j]&&mx<a[i+1][j])
{
if(j==y)acy[i][j]=1;
else acy[i][j]=acy[i][j-1];
}
else acy[i][j]=0;
if(rec(x,y,i,j))ret++;
}
}
return ret;
}
ll ans;
long long count_rectangles(std::vector<std::vector<int> > aa)
{
n=aa.size();m=aa[0].size();
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)a[i][j]=aa[i][j];
}
for(int i=1;i<n-1;i++)
{
for(int j=1;j<m-1;j++)
{
ans+=check(i,j);
}
}
return ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |