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 <bits/stdc++.h>
#include "rect.h"
using namespace std;
typedef long long int lli;
typedef pair<int,int> pii;
const int MAXN = 3000;
const int INF = 1000000010;
int n, m;
int v[MAXN][MAXN];
int sv[MAXN][MAXN];
int qtdDown[MAXN][MAXN][2];
int qtdRight[MAXN][MAXN][2];
int sum(int x1, int y1, int x2, int y2)
{
int ans = sv[x2][y2] + sv[x1 - 1][y1 - 1];
ans -= sv[x2][y1 - 1] + sv[x1 - 1][y2];
return ans;
}
long long count_rectangles(vector< vector<int> > a) //Grids pequenos
{
n = a.size();
m = a[0].size();
for(int i = 0 ; i < n ; i++)
for(int j = 0 ; j < m ; j++)
v[i + 1][j + 1] = a[i][j];
for(int i = 1 ; i <= n ; i++)
for(int j = 1 ; j <= m ; j++)
sv[i][j] = sv[i - 1][j] + sv[i][j - 1] - sv[i - 1][j - 1] + v[i][j];
for(int i = n ; i > 0 ; i--)
{
for(int j = m ; j > 0 ; j--)
{
int val = v[i][j];
qtdDown[i][j][val] = qtdDown[i + 1][j][val] + 1;
qtdRight[i][j][val] = qtdRight[i][j + 1][val] + 1;
}
}
lli ans = 0;
for(int i = 2 ; i < n ; i++)
{
for(int j = 2 ; j < m ; j++)
{
if( v[i][j] == 1 ) continue;
int x2 = i + qtdDown[i][j][0] - 1;
int y2 = j + qtdRight[i][j][0] - 1;
if( sum( i , j , x2 , y2 ) != 0 ) continue;
if( qtdDown[i][j - 1][1] < qtdDown[i][j][0] ) continue;
if( qtdRight[i - 1][j][1] < qtdRight[i][j][0] ) continue;
if( qtdDown[i][y2 + 1][1] < qtdDown[i][j][0] ) continue;
if( qtdRight[x2 + 1][j][1] < qtdRight[i][j][0] ) continue;
ans++;
}
}
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... |