This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include "rect.h"
using namespace std;
#define ve vector
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9 + 10;
ll count_rectangles(ve<ve<int>> A) {
int n, m;
ve<ve<ve<int>>> R, C;
n = (int)A.size();
m = (int)A[0].size();
R = ve<ve<ve<int>>>(m, ve<ve<int>>(m, ve<int>(n, -1)));
C = ve<ve<ve<int>>>(n, ve<ve<int>>(n, ve<int>(m, -1)));
for (int i = 1; i < m - 1; i++) {
ve<int> Max(n, 0);
for (int j = i; j >= 1; j--) {
int cnt = 0;
for (int k = 1; k < n - 1; k++) {
Max[k] = max(Max[k], A[k][j]);
if (Max[k] < A[k][i + 1] && Max[k] < A[k][j - 1]) {
R[i][j][k] = cnt;
}
else cnt++;
}
}
}
for (int i = 1; i < n - 1; i++) {
ve<int> Max(m, 0);
for (int j = i; j >= 1; j--) {
int cnt = 0;
for (int k = 1; k < m - 1; k++) {
Max[k] = max(Max[k], A[j][k]);
if (Max[k] < A[i + 1][k] && Max[k] < A[j - 1][k]) {
C[i][j][k] = cnt;
}
else cnt++;
}
}
}
ll ans = 0;
for (int i = 1; i < n - 1; i++) {
for (int j = 1; j <= i; j++) {
for (int k = 1; k < m - 1; k++) {
for (int l = 1; l <= k; l++) {
int a = C[i][j][k];
int b = C[i][j][l];
int c = R[k][l][i];
int d = R[k][l][j];
if (a != -1 && b != -1 && c != -1 && d != -1) {
if (a == b && c == d) 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... |