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<bits/stdc++.h>
#include "rect.h"
#define F first
#define S second
#define PB push_back
#define sz(s) (int(s.size()))
#define bit(n, k) (((n)>>(k))&1)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int maxn = 2510;
int aftx[maxn][maxn], befx[maxn][maxn], afty[maxn][maxn], befy[maxn][maxn];
ll count_rectangles(vector< vector<int> > a){
int n = sz(a);
int m = sz(a[0]);
/*
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++){
befx[i][j] = j-1;
while(befx[i][j] >= 0 && a[i][befx[i][j]] <= a[i][j])
befx[i][j] = befx[i][ befx[i][j] ];
}
for(int j = m-1; j >= 0; j--){
aftx[i][j] = j+1;
while(aftx[i][j] < m && a[i][aftx[i][j]] <= a[i][j])
aftx[i][j] = aftx[i][ aftx[i][j] ];
}
}
for(int j = 0; j < m; j++){
for(int i = 0; i < n; i++){
befy[i][j] = i-1;
while(befy[i][j] >= 0 && a[befy[i][j]][j] <= a[i][j])
befy[i][j] = befy[ befy[i][j] ][j];
}
for(int i = n-1; i >= 0; i--){
afty[i][j] = i+1;
while(afty[i][j] < n && a[afty[i][j]][j] <= a[i][j])
afty[i][j] = afty[ afty[i][j] ][j];
}
}
*/
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++){
befx[i][j] = j-1;
while(befx[i][j] >= 0 && a[i][befx[i][j]] <= a[i][j])
befx[i][j]--;
}
for(int j = m-1; j >= 0; j--){
aftx[i][j] = j+1;
while(aftx[i][j] < m && a[i][aftx[i][j]] <= a[i][j])
aftx[i][j]++;
}
}
for(int j = 0; j < m; j++){
for(int i = 0; i < n; i++){
befy[i][j] = i-1;
while(befy[i][j] >= 0 && a[befy[i][j]][j] <= a[i][j])
befy[i][j]--;
}
for(int i = n-1; i >= 0; i--){
afty[i][j] = i+1;
while(afty[i][j] < n && a[afty[i][j]][j] <= a[i][j])
afty[i][j]++;
}
}
ll ans = 0;
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++){
if(befx[i][j] == -1 || befy[i][j] == -1 || aftx[i][j] == m || afty[i][j] == n)
continue;
bool ok = 1;
for(int x = befy[i][j] + 1; x < afty[i][j]; x++){
for(int y = befx[i][j] + 1; y < aftx[i][j]; y++){
if((pii){x, y} < (pii){i, j})
ok&= a[x][y] < a[i][j];
ok&= befx[x][y] >= befx[i][j];
ok&= befy[x][y] >= befy[i][j];
ok&= aftx[x][y] <= aftx[i][j];
ok&= afty[x][y] <= afty[i][j];
}
}
ans+= ok;
}
}
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... |