#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
#define pb push_back
#define pii pair<int, int>
#define pll pair<ll, ll>
#define st first
#define nd second
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define debug false
const int MAXW = 50 * 1000;
vector<int> a[MAXW];
vector<pii> przesuniecia = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
int ok (int x1, int y1, int x2, int y2) {
pii pos = {x1, y1};
for (int i = x1; i <= x2; i ++) {
for (int j = y1; j <= y2; j ++) {
if (a[i][j] > a[pos.st][pos.nd]) {
pos = {i, j};
}
}
}
int ile = 1;
while (true) {
pii maks = {-1, -1};
for (auto x : przesuniecia) {
int nx = pos.st + x.st;
int ny = pos.nd + x.nd;
if (nx >= x1 && nx <= x2 && ny >= y1 && ny <= y2) {
if (a[nx][ny] > a[pos.st][pos.nd]) {
continue;
}
if (maks.st == -1) {
maks = {nx, ny};
} else if (a[nx][ny] > a[maks.st][maks.nd]) {
maks = {nx, ny};
}
}
}
if (maks.st == -1) {
break;
}
ile ++;
pos = maks;
}
return (ile == (x2 - x1 + 1) * (y2 - y1 + 1));
}
int main () {
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int n, m, x;
cin >> n >> m;
for (int i = 0; i < n; i ++) {
for (int j = 0; j < m; j ++) {
cin >> x;
a[i].pb(x);
}
}
int wyn = 0;
for (int i = 0; i < n; i ++) {
for (int j = 0; j < m; j ++) {
for (int k = i; k < n; k ++) {
for (int l = j; l < m; l ++) {
wyn += ok(i, j, k, l);
}
}
}
}
cout << wyn << "\n";
return 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... |