比赛 不准粘代码,必须自己写(HS除外) 评测结果 AAAAAAAAAA
题目名称 棋盘制作 最终得分 100
用户昵称 云卷云书 运行时间 1.764 s
代码语言 C++ 内存使用 74.88 MiB
提交时间 2019-09-25 19:55:47
显示代码纯文本
  1. #include<iostream>
  2. #include<cstdio>
  3. using namespace std;
  4. int x,y,ans1=0,ans2=0,n,m,t,chess[2003][2003],h[2003][2003],l[2003][2003],r[2003][2003];
  5. int main(){
  6. freopen("makechess.in","r",stdin);
  7. freopen("makechess.out","w",stdout);
  8. cin>>n>>m;
  9. for(int i=1;i<=n;i++)
  10. for(int j=1;j<=m;j++){
  11. scanf("%d",&chess[i][j]);
  12. }
  13. for(int i=1;i<=n;i++)
  14. for(int j=1;j<=m;j++){
  15. l[i][j]=r[i][j]=j;
  16. h[i][j]=1;
  17. }
  18. for(int i=1;i<=n;i++){
  19. for(int j=2;j<=m;j++){
  20. if(chess[i][j]!=chess[i][j-1])
  21. l[i][j]=l[i][j-1];
  22. }
  23. }
  24. for(int i=1;i<=n;i++){
  25. for(int j=m-1;j>=1;j--){
  26. if(chess[i][j]!=chess[i][j+1])
  27. r[i][j]=r[i][j+1];
  28. }
  29. }
  30. for(int i=1;i<=n;i++){
  31. for(int j=1;j<=m;j++)
  32. {
  33. if(i>1&&chess[i][j]!=chess[i-1][j])
  34. {
  35. l[i][j]=max(l[i][j],l[i-1][j]);
  36. r[i][j]=min(r[i][j],r[i-1][j]);
  37. h[i][j]=h[i-1][j]+1;
  38. }
  39. int x=r[i][j]-l[i][j]+1;
  40. int y=min(x,h[i][j]);
  41. ans1=max(ans1,x*h[i][j]);
  42. ans2=max(ans2,y*y);
  43. }
  44. }
  45. cout<<ans2<<endl<<ans1;
  46. return 0;
  47. }