#include "rect.h"
#include <bits/stdc++.h>
using namespace std;
#define sig signed
#define int long long
#define arr array
#define vec vector
#define pii pair<int, int>
#define fir first
#define sec second
const int N = 80 + 5, M = 80 + 5;
int n, m;
arr<arr<int, M>, N> a;
arr<arr<arr<int, M>, M>, N> up, dwn, vld, fr;
void prcmp() {
for (int i = n; i >= 1; i--) {
for (int l = 1; l <= m; l++) {
for (int r = l; r <= m; r++) {
up[i][l][r] = 0, dwn[i][l][r] = n + 1, vld[i][l][r] = false, fr[i][l][r] = n + 1;
for (int j = i - 1; j >= 1; j--) {
bool hlt = false;
for (int k = l; k <= r; k++)
if (a[j][k] >= a[i][k]) hlt = true;
if (hlt) { up[i][l][r] = j; break; }
}
for (int j = i + 1; j <= n; j++) {
bool hlt = false;
for (int k = l; k <= r; k++)
if (a[j][k] >= a[i][k]) hlt = true;
if (hlt) { dwn[i][l][r] = j; break; }
}
int mx = -1;
for (int j = l; j <= r; j++) mx = max(mx, a[i][j]);
if (l != 1 && r != m) vld[i][l][r] = (mx < min(a[i][l - 1], a[i][r + 1]));
for (int j = i + 1; j <= n; j++)
if (!vld[j][l][r]) { fr[i][l][r] = j; break; }
// cout << i << " " << l << " " << r << ": " << dwn[i][l][r] << " " << fr[i][l][r] << '\n';
}
}
}
}
int cmp() {
int ans = 0;
for (int i = 1; i <= n; i++) {
for (int l = 1; l <= m; l++) {
for (int r = l; r <= m; r++) {
int j = min({dwn[i][l][r], fr[i][l][r], n});
if (j < i + 2) continue;
// cout << i << " " << l << " " << r << ": " << i + 2 << " to " << j << '\n';
for (int k = i + 2; k <= j; k++)
ans += (up[k][l][r] <= i);
}
}
}
return ans;
}
int count_rectangles(vec<vec<sig>> _a) {
n = _a.size(), m = _a[0].size();
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++)
a[i][j] = _a[i - 1][j - 1];
prcmp();
return cmp();
}
# | 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... |