求助,60分,Wa#5,MLE7,9,10

P1736 创意吃鱼法

NOIPOIER @ 2018-01-05 20:51:56

#include<bits/stdc++.h>
using namespace std;
bool map1[2000][2000];
int m,n;
int maxn;
bool exam(int x,int y,int s_size)
{
    if(x+s_size-1>m||y+s_size-1>n)return 0;
    for(int i=0;i<s_size;i++)
    for(int j=0;j<s_size;j++)
    {
        if(i-j==0&&map1[x+i][y+j]==0)return 0;
        else if(i-j!=0&&map1[x+i][y+j]==1)return 0;
        }
        return 1;    
}
bool sele(int x,int y,int s_size)
{
    if(x+s_size-1>m||y-s_size+1<1)return 0;
    for(int i=0;i<s_size;i++)
    for(int j=0;j<s_size;j++)
    {
        if(i-j==0&&map1[x+i][y-j]==0)return 0;
        else if(i-j!=0&&map1[x+i][y-j]==1)return 0;
        }
        return 1;    
}
void dfs(int x,int y){
    if(x>m-maxn&&y==1)return;
     if(map1[x][y]==1)
  {
    while(exam(x,y,maxn+1))maxn++;
    while(sele(x,y,maxn+1))maxn++;
   }    
   int nx=x,ny=y;
   ny++;
   if(ny==m+1){
        nx++;
        ny=1;
   }
   dfs(nx,ny);
}
int main(){
    std::ios::sync_with_stdio(false);
    cin>>m>>n;
    for(int i=1;i<=m;i++)
    for(int j=1;j<=n;j++)
        cin>>map1[i][j];
    dfs(1,1);
    cout<<maxn;
    return 0;
}

by NOIPOIER @ 2018-01-05 20:53:46

代码中map1打错了,为【2501】【2501】


by HuangBo @ 2018-03-06 21:09:13

同意楼上...


|