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"
# define ll long long
using namespace std;
const int N = 707;
// bool dp[N][N][N]; // dp[i][j][i1] = 0/1; 1-> can create a rect starting from i,j ending at i1, j
long long count_rectangles(vector<vector<int> > a) {
int n = a.size(), m = a[0].size(), ans = 0;
for ( int i = 1; i < n - 1; i++ ) {
for ( int j = 1; j < m - 1; j++ ) {
for ( int i1 = i; i1 < n - 1; i1++ ) {
for ( int j1 = j; j1 < m - 1; j1++ ) {
int ok = 1, k = 0;
for ( int x = i; x <= i1; x++ ) {
for ( int y = j; y <= j1; y++ ) {
k = 1;
int A = a[i - 1][y], B = a[i1 + 1][y];
int C = a[x][j - 1], D = a[x][j1 + 1];
int z = a[x][y];
if ( z > A || z > B || z > C || z > D ) {
ok = 0;
break;
}
}
if ( !ok ) {
k = 0;
break;
}
}
ans += k;
}
}
}
}
return ans;
}
/*
int32_t main() {
int n, m;
cin >> n >> m;
vector < vector < int > > a;
for ( int i = 0; i < n; i++ ) {
vector < int > vc;
for ( int j = 0; j < m; j++ ) {
int x;
cin >> x;
vc.push_back( x );
}
a.push_back( vc );
}
cout << count_rectangles(a);
}
/*
6 5
4 8 7 5 6
7 4 10 3 5
9 7 20 14 2
9 14 7 3 6
5 7 5 2 7
4 5 13 5 6
*/
Compilation message (stderr)
rect.cpp:56:1: warning: "/*" within comment [-Wcomment]
/*
# | 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... |