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;
#define ll long long
long long count_rectangles(vector<vector<int> > a) {
int n = a.size();
int m = a[0].size();
ll ans = 0;
for(int width = 0; width < n - 2; width++){
for(int height = 0; height < m -2; height++){
for(int starti = 1; starti < n -1 - width; starti++){
for(int startj = 1; startj < m - 1 - height; startj++){
bool good = true;
//cout <<starti<<", "<<startj<<": "<<starti + width <<", "<<startj + width<<endl;
for(int i =starti; i<=starti + width ;i++){
for(int j =startj ;j <=startj + height; j++){
int cnt = 0;
if(a[starti-1][j] > a[i][j])
cnt++;
if(a[starti + width + 1][j] > a[i][j])
cnt++;
if(a[i][startj -1] > a[i][j])
cnt++;
if(a[i][startj + height+1] > a[i][j])
cnt++;
if(cnt != 4)
{
//cout << ":BAD:"<<starti<<", "<<startj<<": "<<width<<", "<<height<<endl;
good = false;
break;
}
}
if(!good)
break;
}
if(good){
//cout << starti<<", "<<startj<<": "<<width<<", "<<height<<endl;
}
ans += good;
}
}
}
}
return ans;
}
/*subtask 5: debug*/
/*
long long count_rectangles(vector<vector<int> > a) {
int n = a.size();
int m = a[0].size();
ll ans = 0;
for(int i =1; i<n-1 ;i++){
int leftind = 0;
for(int j =1 ;j <m-1; j++){
int cnt = 0;
cout << a[i][j]<<", "<<leftind<< ": "<<a[i][leftind]<<endl;
bool pos = true;
if(a[i-1][j] > a[i][j])
cnt++;
else
pos = false;
if(a[i+1][j] > a[i][j])
cnt++;
else
pos = false;
if(a[i][leftind] > a[i][j])
cnt++;
else
pos = false;
if(a[i][j+1] > a[i][j])
cnt++;
if(!pos){
leftind = j;
}
cout << pos<<" & "<<cnt<<endl;
if(cnt == 4){
for(int ii = leftind+1; ii < j; ii++){
if(a[i][ii] >= a[i][j+1]){
leftind = ii;
}
}
ll curans = 0;
for(int ii = leftind +1; ii<=j; ii++){
if(a[i][ii] < a[i][ii - 1]){
curans++;
cout << ii<<":";
}
}
cout << "!"<<leftind<<endl;
ans+= curans;
}
}
}
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... |