# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
428567 | Hazem | Rectangles (IOI19_rect) | C++14 | 0 ms | 0 KiB |
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
using namespace std;
const int N = 751;
int n,m;
int col[N][N][N],row[N][N][N];
long long count_rectangles(std::vector<std::vector<int> > a) {
n = a.size();
m = a[0].size();
for(int i=0;i<n;i++)
for(int j=0;j<m;j++){
int mx = 0;
for(int k=j+1;k<m;k++){
if(k-j>1&&mx<a[i][j]&&mx<a[i][k])
row[j][k][i]++;
mx = max(mx,a[i][k]);
}
}
for(int i=0;i<m;i++)
for(int j=0;j<n;j++){
int mx = 0;
for(int k=j+1;k<n;k++){
if(k-j>1&&mx<a[j][i]&&mx<a[k][i])
col[j][k][i]++;
if(i)
col[j][k][i] += col[j][k][i-1];
mx = max(mx,a[k][i]);
}
}
LL ans = 0;
for(int i=0;i<n;i++)
for(int j=0;j<m;j++)
for(int k=j+1;k<m;k++){
int q = 1;
for(int k1 = i+1;k1<n;k1++){
if(k1-i>1&&k-j>1)
ans += q&(col[i][k1][k-1]-col[i][k1][j]==(k-j-1));
q &= row[j][k][k1];
}
}
return ans;
}