이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "rect.h"
#include<iostream>
#include<vector>
using namespace std;
using ll = long long;
const int N = 202;
int gr[N][N][N];
int gc[N][N][N];
ll count_rectangles(vector<vector<int>>a) {
int n = a.size(), m = a[0].size();
ll ans = 0;
for (int r = 1 ; r < n - 1 ; ++ r) {
for (int c1 = 1 ; c1 < m - 1 ; ++ c1) {
int mx = 0;
for (int c2 = c1 ; c2 < m - 1 ; ++ c2) {
mx = max(mx, a[r][c2]);
if (mx < a[r][c1 - 1] && mx < a[r][c2 + 1]) {
gr[r][c1][c2] = 1;
}
}
}
}
for (int c = 1 ; c < m - 1 ; ++ c) {
for (int r1 = 1 ; r1 < n - 1 ; ++ r1) {
int mx = 0;
for (int r2 = r1 ; r2 < n - 1 ; ++ r2) {
mx = max(mx, a[r2][c]);
if (mx < a[r1 - 1][c] && mx < a[r2 + 1][c]) {
gc[c][r1][r2] = 1;
}
}
}
}
for (int r = 1 ; r < n - 1 ; ++ r) {
for (int c1 = 1 ; c1 < m - 1 ; ++ c1) {
for (int c2 = c1 ; c2 < m - 1 ; ++ c2) {
gr[r][c1][c2] += gr[r-1][c1][c2];
}
}
}
for (int c = 1 ; c < m - 1 ; ++ c) {
for (int r1 = 1 ; r1 < n - 1 ; ++ r1) {
for (int r2 = r1 ; r2 < n - 1 ; ++ r2) {
gc[c][r1][r2] += gc[c-1][r1][r2];
}
}
}
for (int r1 = 1 ; r1 < n - 1 ; ++ r1) {
for (int r2 = r1 ; r2 < n - 1 ; ++ r2) {
for (int c1 = 1 ; c1 < m - 1 ; ++ c1) {
for (int c2 = c1 ; c2 < m - 1; ++ c2) {
int sr = gr[r2][c1][c2] - gr[r1-1][c1][c2];
int sc = gc[c2][r1][r2] - gc[c1-1][r1][r2];
if (sr == r2 - r1 + 1 && sc == c2 - c1 + 1) {
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... |