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 <vector>
#include <algorithm>
using namespace std;
long long count_rectangles(std::vector<std::vector<int> > A) {
const int inf = 1012345678;
int H = A.size(), W = A[0].size();
vector<vector<vector<bool> > > flag_row(H, vector<vector<bool> >(W + 1, vector<bool>(W + 1)));
vector<vector<vector<bool> > > flag_col(W, vector<vector<bool> >(H + 1, vector<bool>(H + 1)));
for(int i = 0; i < H; ++i) {
for(int j = 1; j < W; ++j) {
int mx = -inf;
for(int k = j + 1; k < W; ++k) {
mx = max(mx, A[i][k - 1]);
flag_row[i][j][k] = (A[i][j - 1] > mx && A[i][k] > mx);
}
}
}
for(int i = 0; i < W; ++i) {
for(int j = 1; j < H; ++j) {
int mx = -inf;
for(int k = j + 1; k < H; ++k) {
mx = max(mx, A[k - 1][i]);
flag_col[i][j][k] = (A[j - 1][i] > mx && A[k][i] > mx);
}
}
}
vector<vector<vector<int> > > sum_row(H + 1, vector<vector<int> >(W + 1, vector<int>(W + 1)));
vector<vector<vector<int> > > sum_col(W + 1, vector<vector<int> >(H + 1, vector<int>(H + 1)));
for(int i = 0; i < H; ++i) {
for(int j = 1; j < W; ++j) {
for(int k = j + 1; k < W; ++k) {
sum_row[i + 1][j][k] = sum_row[i][j][k] + flag_row[i][j][k];
}
}
}
for(int i = 0; i < W; ++i) {
for(int j = 1; j < H; ++j) {
for(int k = j + 1; k < H; ++k) {
sum_col[i + 1][j][k] = sum_col[i][j][k] + flag_col[i][j][k];
}
}
}
long long ans = 0;
for(int xa = 1; xa < H; ++xa) {
for(int ya = 1; ya < W; ++ya) {
for(int xb = xa + 1; xb < H; ++xb) {
for(int yb = ya + 1; yb < W; ++yb) {
int sr = sum_row[xb][ya][yb] - sum_row[xa][ya][yb];
int sc = sum_col[yb][xa][xb] - sum_col[ya][xa][xb];
if(sr == xb - xa && sc == yb - ya) {
++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... |