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>
using namespace std;
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define ff first
#define ss second
#define pb push_back
#define SZ(x) ((int)(x).size())
#define all(x) x.begin(), x.end()
#define debug(x) cout << #x << ": " << x << " "
#define nl cout << "\n"
#define rep(i, a, b) for(int i = (a); i < (b); i++)
#define per(i, a, b) for(int i = (a); i >= (b); i--)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
long long count_rectangles(vector<vector<int>> a){
int N = SZ(a), M = SZ(a[0]);
auto check = [&](int i1, int j1, int i2, int j2){
rep(i, i1, i2 + 1){
int mn = min(a[i][j1 - 1], a[i][j2 + 1]);
int mx = -1;
rep(j, j1, j2 + 1){
mx = max(mx, a[i][j]);
}
if(!(mx < mn)) return false;
}
rep(j, j1, j2 + 1){
int mn = min(a[i1 - 1][j], a[i2 + 1][j]);
int mx = -1;
rep(i, i1, i2 + 1){
mx = max(mx, a[i][j]);
}
if(!(mx < mn)) return false;
}
return true;
};
ll ans = 0;
rep(i1, 1, N - 1){
rep(i2, i1, N - 1){
rep(j1, 1, N - 1){
rep(j2, j1, N - 1){
if(check(i1, j1, i2, j2)) ans++;
}
}
}
}
return ans;
}
Compilation message (stderr)
rect.cpp: In function 'long long int count_rectangles(std::vector<std::vector<int> >)':
rect.cpp:18:20: warning: unused variable 'M' [-Wunused-variable]
18 | int N = SZ(a), M = SZ(a[0]);
| ^
# | 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... |