## 1057: [ZJOI2007]棋盘制作

Time Limit: 20 Sec  Memory Limit: 162 MB
Submit: 2027  Solved: 1019
[Submit][Status][Discuss]

3 3
1 0 1
0 1 0
1 0 0

## Sample Output

4
6

#include <iostream>
#include <vector>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <stack>
#include <bitset>
using namespace std;
#define pb(x) push_back(x)
#define ll long long
#define mk(x, y) make_pair(x, y)
#define lson l, m, rt<<1
#define mem(a) memset(a, 0, sizeof(a))
#define rson m+1, r, rt<<1|1
#define mem1(a) memset(a, -1, sizeof(a))
#define mem2(a) memset(a, 0x3f, sizeof(a))
#define rep(i, n, a) for(int i = a; i<n; i++)
#define fi first
#define se second
typedef pair<int, int> pll;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int mod = 1e9+7;
const int inf = 1061109567;
const int dir[][2] = { {-1, 0}, {1, 0}, {0, -1}, {0, 1} };
int dp[2005][2005], l[2005][2005], r[2005][2005], a[2005][2005];
int main()
{
int n, m;
cin>>n>>m;
for(int i = 1; i<=n; i++) {
for(int j = 1; j<=m; j++) {
scanf("%d", &a[i][j]);
if(i == 1) {
dp[i][j] = 1;
} else if(a[i][j] != a[i-1][j]) {
dp[i][j] = dp[i-1][j]+1;
} else {
dp[i][j] = 1;
}
}
}
for(int i = 1; i<=n; i++) {
for(int j = 1; j<=m; j++) {
l[i][j] = j;
while(l[i][j]>1 && dp[i][j]<=dp[i][l[i][j]-1] && a[i][l[i][j]] != a[i][l[i][j]-1])
l[i][j] = l[i][l[i][j]-1];
}
for(int j = m; j>=1; j--) {
r[i][j] = j;
while(r[i][j]<m && dp[i][j]<=dp[i][r[i][j]+1] && a[i][r[i][j]] != a[i][r[i][j]+1])
r[i][j] = r[i][r[i][j]+1];
}
}
int ans1 = 0, ans2 = 0;
for(int i = 1; i<=n; i++) {
for(int j = 1; j<=m; j++) {
int len = r[i][j]-l[i][j]+1;
ans1 = max(ans1, len*dp[i][j]);
len = min(len, dp[i][j]);
ans2 = max(ans2, len*len);
}
}
cout<<ans2<<endl<<ans1<<endl;
return 0;
}

posted on 2016-02-29 16:48  yohaha  阅读(183)  评论(0编辑  收藏

• 随笔 - 305
• 文章 - 0
• 评论 - 6
• 引用 - 0