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;
const int MAXN = 210;
int n, m;
int v[MAXN][MAXN];
bool isAnswer(int x1, int y1, int x2, int y2)
{
for(int i = x1 ; i <= x2 ; i++)
{
for(int j = y1 ; j <= y2 ; j++)
{
if( v[i][j] >= v[i][y1 - 1] || v[i][j] >= v[i][y2 + 1] ) return false;
if( v[i][j] >= v[x1 - 1][j] || v[i][j] >= v[x2 + 1][j] ) return false;
}
}
return true;
}
long long count_rectangles(vector< vector<int> > a)
{
n = a.size();
m = a[0].size();
for(int i = 0 ; i < n ; i++)
for(int j = 0 ; j < m ; j++)
v[i][j] = a[i][j];
lli ans = 0;
for(int i = 0 ; i < n ; i++)
{
for(int j = 0 ; j < m ; j++)
{
int L, R;
int up, down;
L = R = up = down = -1;
for(int k = 0 ; k < j ; k++)
if( v[i][k] >= v[i][j] ) L = k;
for(int k = m - 1 ; k > j ; k--)
if( v[i][k] > v[i][j] ) R = k;
for(int k = 0 ; k < i ; k++)
if( v[k][j] >= v[i][j] ) up = k;
for(int k = n - 1 ; k > i ; k--)
if( v[k][j] > v[i][j] ) down = k;
if( L == -1 || R == -1 || up == -1 || down == -1 ) continue;
if( isAnswer( up + 1 , L + 1 , down - 1 , R - 1 ) ) 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... |