#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1100;
int n;
int a[MAXN][MAXN];
bool h[MAXN][MAXN], l[MAXN][MAXN];
int suml,sumh;
int fx[8] = {-1, -1, -1, 0, 0, 1, 1, 1};
int fy[8] = {-1, 0, 1, -1, 1, -1, 0, 1};
void dfsh(int x, int y) {
h[x][y] = true;
for (int i = 0; i < 8; i++) {
int tx = x + fx[i];
int ty = y + fy[i];
if (tx >= 1 && tx <= n && ty >= 1 && ty <= n && !h[tx][ty] && a[tx][ty] <= a[x][y]) {
dfsh(tx, ty);
}
}
}
void dfsl(int x, int y) {
l[x][y] = true;
for (int i = 0; i < 8; i++) {
int tx = x + fx[i];
int ty = y + fy[i];
if (tx >= 1 && tx <= n && ty >= 1 && ty <= n && !l[tx][ty] && a[tx][ty] >= a[x][y]) {
dfsl(tx, ty);
}
}
}
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
cin >> a[i][j];
}
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
bool p = true, v = true;
for (int k = 0; k < 8; k++) {
int tx = i + fx[k];
int ty = j + fy[k];
if (tx >= 1 && tx <= n && ty >= 1 && ty <= n) {
if (a[tx][ty] > a[i][j]) p = false;
if (a[tx][ty] < a[i][j]) v = false;
}
}
if (p && !h[i][j]) {
dfsh(i, j);
sumh++;
}
if (v && !l[i][j]) {
dfsl(i, j);
suml++;
}
}
}
cout << sumh << " " << suml;
return 0;
}
看不出来哪错了...