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 "rect.h"
#include <bits/stdc++.h>
using namespace std;
long long count_rectangles(vector<vector<int> > mat) {
const int r = mat.size();
const int c = mat[0].size();
if (r <= 2) {
return 0;
}
if (c <= 2) {
return 0;
}
// Subtask #1 && Subtask #2
long long res = 0;
for (int i = 1; i < c - 1; i++) {
for (int j = i; j < c - 1; j++) {
vector<bool> valid_linha(r);
for (int x = 1; x < r - 1; x++) {
int mx = 0;
for (int z = i; z <= j; z++) {
mx = max(mx, mat[x][z]);
}
valid_linha[x] = (mx < mat[x][i - 1] && mx < mat[x][j + 1]);
}
vector<bool> valid_up(r);
vector<bool> valid_down(r);
for (int x = 1; x < r - 1; x++) {
bool up = true, down = true;
for (int z = i; z <= j; z++) {
up &= (mat[x][z] < mat[x - 1][z]);
down &= (mat[x][z] < mat[x + 1][z]);
}
valid_up[x] = up;
valid_down[x] = down;
}
for (int x = 1; x < r - 1; x++) {
if (!valid_up[x]) continue;
if (!valid_linha[x]) continue;
for (int z = x; z < r - 1; z++) {
if (!valid_linha[z]) break;
if (!valid_down[z]) continue;
++res;
}
}
}
}
return res;
}
# | 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... |