比赛 |
2022级DP专题练习赛1 |
评测结果 |
AAAAAAAAAA |
题目名称 |
棋盘制作 |
最终得分 |
100 |
用户昵称 |
op_组撒头屯 |
运行时间 |
1.180 s |
代码语言 |
C++ |
内存使用 |
46.95 MiB |
提交时间 |
2023-02-10 20:25:14 |
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define ld long double
#define pii pair<int,int>
#define vi vector<int>
#define si set<int>
#define unsi unordered_set<int>
#define qi queue<int>
#define sti stack<int>
#define pqi priority_queue<int>
#define mii map<int,int>
#define unmii unordered_map<int,int>
#define fi first
#define se second
#define pb push_back
#define clr(f,n) memset(f,0,sizeof(int)*(n))
#define cpy(f,g,n) memcpy(f,g,sizeof(int)*(n))
const int N=2000+5;
int n,m;
int a[N][N],f[N][N];
int l[N][N],r[N][N];
int main(){
freopen ("makechess.in","r",stdin);
freopen ("makechess.out","w",stdout);
scanf("%d%d",&n,&m);
for (int i=1;i<=n;i++){
for (int j=1;j<=m;j++){
scanf("%d",&a[i][j]);
l[i][j]=r[i][j]=j;
}
}
for (int i=1;i<=m;i++)f[n][i]=1;
for (int i=n-1;i>=1;i--){
for (int j=1;j<=m;j++){
if (a[i][j]==a[i+1][j])f[i][j]=1;
else f[i][j]=f[i+1][j]+1;
}
}
int ans1=0,ans2=0;
for (int i=1;i<=n;i++){
for (int j=1;j<=m;j++)while(f[i][l[i][j]-1]>=f[i][j]&&a[i][l[i][j]-1]!=a[i][l[i][j]])l[i][j]=l[i][l[i][j]-1];
for (int j=m;j>=1;j--)while(f[i][r[i][j]+1]>=f[i][j]&&a[i][r[i][j]+1]!=a[i][r[i][j]])r[i][j]=r[i][r[i][j]+1];
for (int j=1;j<=m;j++){
ans1=max(ans1,(r[i][j]-l[i][j]+1)*f[i][j]);
int b=min(r[i][j]-l[i][j]+1,f[i][j]);
ans2=max(ans2,b*b);
}
}
printf("%d\n%d\n",ans2,ans1);
return 0;
}