和玉蟾宫很像,条件改成不相等就行了。
悬线法题目 洛谷 P1169 p4147 p2701 p1387
#include<cstdio>
#include<algorithm>
#define REP(i, a, b) for(int i = (a); i < (b); i++)
#define _for(i, a, b) for(int i = (a); i <= (b); i++)
using namespace std;const int MAXN = 2123;
int up[MAXN][MAXN], l[MAXN][MAXN];
int r[MAXN][MAXN], a[MAXN][MAXN], n, m;int main()
{scanf("%d%d", &n, &m);_for(i, 1, n)_for(j, 1, m){scanf("%d", &a[i][j]);l[i][j] = r[i][j] = j;up[i][j] = 1;} _for(i, 1, n){_for(j, 2, m)if(a[i][j] != a[i][j-1])l[i][j] = l[i][j-1];for(int j = m - 1; j >= 1; j--)if(a[i][j] != a[i][j+1])r[i][j] = r[i][j+1];}int ans1 = 0, ans2 = 0;_for(i, 1, n)_for(j, 1, m){if(i > 1 && a[i][j] != a[i-1][j]){up[i][j] = up[i-1][j] + 1;l[i][j] = max(l[i][j], l[i-1][j]);r[i][j] = min(r[i][j], r[i-1][j]);}int w = r[i][j] - l[i][j] + 1, h = up[i][j];ans1 = max(ans1, min(w, h) * min(w, h));ans2 = max(ans2, w * h);}printf("%d\n%d\n", ans1, ans2);return 0;
}