比赛 20140418 评测结果 MMMMMMMMMM
题目名称 建造滑雪场 最终得分 0
用户昵称 Miku_lyt 运行时间 0.000 s
代码语言 C++ 内存使用 0.00 MiB
提交时间 2014-04-18 11:24:51
显示代码纯文本
#include<cstdio>
#include<cstring>
#include<algorithm>

using namespace std;

struct ski{
  int f[10][10];
  int lastx,lasty;
  };

  ski q[1000001];
  int n,m;
  char op;
  int l=1;
  int r=0;
  int mid;
  int g[101][101];
  int h[101][101];
  int f[101][101];

bool all(ski now){
  for (int i=1;i<=n;i++){
    for (int j=1;j<=m;j++){
      if (now.f[i][j]!=2){
        return 0;
        }
      }
    }
  return 1;
  }
  
bool check(int x,int y,ski now,int B){
  if (now.lastx==x&&now.lasty==y){
    return 0;
    }
  int flag=now.f[x][y];
  bool flag2=1;
  for (int i=x;i<x+B;i++){
    for (int j=y;j<y+B;j++){
      if (now.f[i][j]!=2){
        flag2=0;
        }
      if (now.f[i][j]!=flag&&now.f[i][j]!=2){
        return 0;
        }
      }
    }
  if (flag2){
    return 0;
    }
  return 1;
  }

bool judge(int B){
  if (B==1){
    return 1;
    }
  ski now,newq;
  int l=0;
  int r=1;
  memcpy(now.f,f,sizeof(now.f));
  now.lastx=0;
  now.lasty=0;
  q[1]=now;
  while (l!=r){
    l=(l%1000000)+1;
    now=q[l];
    if (all(now)){
      return 1;
      }
    for (int i=1;i<=n-B+1;i++){
      for (int j=1;j<=m-B+1;j++){
        if (check(i,j,now,B)){
          memcpy(newq.f,now.f,sizeof(newq.f));
          newq.lastx=i;
          newq.lasty=j;
          for (int k=i;k<i+B;k++){
            for (int l=j;l<j+B;l++){
              newq.f[k][l]=2;
              }
            }
          if (all(newq)){
            return 1;
            }
          r=(r%1000000)+1;
          q[r]=newq;
          }
        }
      }
    }
  return 0;
  }

int main(){
  freopen("skicourse.in","r",stdin);
  freopen("skicourse.out","w",stdout);

  scanf("%d%d",&n,&m);
  for (int i=1;i<=n;i++){
    op=getchar();
    for (int j=1;j<=m;j++){
      op=getchar();
      if (op=='R'){
        f[i][j]=1;
        }
      else{
        f[i][j]=0;
        }
      }
    }
    
  for (int i=1;i<=n;i++){
    for (int j=1;j<=m;j++){
      if (f[i][j]){
        g[i][j]=min(g[i-1][j-1],min(g[i-1][j],g[i][j-1]))+1;
        h[i][j]=0;
        }
      else{
        h[i][j]=min(h[i-1][j-1],min(h[i-1][j],h[i][j-1]))+1;
        g[i][j]=0;
        }
      r=max(r,max(g[i][j],h[i][j]));
      }
    }
    
  /*while (l+1<r){
    mid=(l+r) >> 1;
    if (judge(mid)){
      l=mid;
      }
    else{
      r=mid;
      }
    }*/
  int ans=r;
  while (!judge(ans)){
    ans--;
    }
  printf("%d\n",ans);
    
  return 0;
  }