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"
using namespace std;
using ll = long long;
ll count_rectangles(vector<vector<int>> a) {
ll ans = 0, cnt = 0;
int n = a.size();
int m = a[0].size();
if (n <= 2 or m <= 2) {
return 0;
}
int mx[n][m][m], mx2[m][n][n];
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
mx[i][j][j] = a[i][j];
for (int k = j+1; k < m; ++k) {
mx[i][j][k] = max(mx[i][j][k-1], a[i][k]);
}
}
}
for (int i = 0; i < m; ++i) {
for (int j = 0; j < n; ++j) {
mx2[i][j][j] = a[j][i];
for (int k = j+1; k < n; ++k) {
mx2[i][j][k] = max(mx2[i][j][k-1], a[k][i]);
}
}
}
// vector<array<int, 4>> vec;
for (int i = 1; i < n-1; ++i) {
for (int j = 1; j < m-1; ++j) {
pair<int, int> top_right{i, j};
for (int k = i; k < n-1; ++k) {
for (int l = j; l < m-1; ++l) {
pair<int, int> bottom_left{k, l};
bool cont = false;
for (int row = top_right.first; row <= bottom_left.first; ++row) {
int maxi = mx[row][top_right.second][bottom_left.second];
if (maxi >= min(a[row][top_right.second-1], a[row][bottom_left.second+1])) {
cont = true;
break;
}
}
if (cont) continue;
cnt++;
for (int col = top_right.second; col <= bottom_left.second; ++col) {
int maxi = mx2[col][top_right.first][bottom_left.first];
/* if (i == 1 and j == 4 and k == 1 and l == 5) {
cout << "maxi : " << maxi << '\n';
cout << "upar : " << a[top_right.first-1][col] << '\n';
cout << "neeche : " << a[bottom_left.first+1][col] << '\n';
}
*/ if (maxi >= min(a[top_right.first-1][col], a[bottom_left.first+1][col])) {
// if (i == 1 and j == 4 and k == 1 and l == 5) {cout << "cont hua\n";}
cont = true;
break;
}
}
if (cont) continue;
ans++;
// vec.push_back({i, j, k, l});
}
}
}
}
// for (auto x : vec) {
// for (auto y : x) cout << y << " " ;
// cout << '\n';
// }
// cout << "cnt : " << cnt << '\n';
return ans;
}
/*
int main() {
int n, m;
cin >> n >> m;
vector<vector<int>> v(n, vector<int>(m));
for (auto &x : v) for (auto &y : x) cin >> y;
cout << count_rectangles(v);
}
*/
# | 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... |