This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// In the name of Allah
#include <bits/stdc++.h>
#include "rect.h"
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef complex<ld> cld;
#define all(x) (x).begin(),(x).end()
#define len(x) ((ll) (x).size())
#define F first
#define S second
#define pb push_back
#define sep ' '
#define endl '\n'
#define Mp make_pair
#define kill(x) cout << x << '\n', exit(0)
#define set_dec(x) cout << fixed << setprecision(x);
#define file_io(x,y) freopen(x, "r", stdin); freopen(y, "w", stdout);
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int maxn = 2500 + 4;
int n, m;
int L1[maxn][maxn], R1[maxn][maxn];
int L2[maxn][maxn], R2[maxn][maxn];
bool ok(int l1, int r1, int l2, int r2) {
for (int j = l2; j <= r2; j++) {
int i1 = l1 - 1, i2 = r1 + 1;
if (L1[i2][j] != i1 && R1[i1][j] != i2) return 0;
}
for (int i = l1; i <= r1; i++) {
int j1 = l2 - 1, j2 = r2 + 1;
if (L2[i][j2] != j1 && R2[i][j1] != j2) return 0;
}
return 1;
}
ll count_rectangles(vector<vector<int>> A) {
n = len(A); m = len(A[0]);
for (int j = 0; j < m; j++) {
for (int i = 0; i < n; i++) {
for (L1[i][j] = i - 1; L1[i][j] != -1 && A[i][j] > A[L1[i][j]][j]; L1[i][j] = L1[L1[i][j]][j]);
}
for (int i = n - 1; i >= 0; i--) {
for (R1[i][j] = i + 1; R1[i][j] != n && A[i][j] > A[R1[i][j]][j]; R1[i][j] = R1[R1[i][j]][j]);
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
for (L2[i][j] = j - 1; L2[i][j] != -1 && A[i][j] > A[i][L2[i][j]]; L2[i][j] = L2[i][L2[i][j]]);
}
for (int j = m - 1; j >= 0; j--) {
for (R2[i][j] = j + 1; R2[i][j] != m && A[i][j] > A[i][R2[i][j]]; R2[i][j] = R2[i][R2[i][j]]);
}
}
ll ans = 0;
for (int l1 = 1; l1 < n - 1; l1++) {
for (int r1 = l1; r1 < n - 1; r1++) {
for (int l2 = 1; l2 < m - 1; l2++) {
for (int r2 = l2; r2 < m - 1; r2++) {
if (ok(l1, r1, l2, r2)) 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... |