POJ 3494(超时,和没超时的程序测试过,只差10%的速度,应该可以过的,不知道为什么过不了)

#include <iostream>
#include<ctime>
using namespace std;
typedef struct Line{
	unsigned long long arg[32];
} Line;
Line map[2000];
Line a,b;
int lineTemp[2000];
int M,N;
int res,range,max;
unsigned long long flag;
void init(){	
	res = 0;	
	range = N%64? N/64 + 1 : N/64;
	int i,j,t,x,ss=0;		
	for(i = 0; i < M; ++i){
		for(j = 0,x = 0; j < range && x<N; ++j){
			flag = 0;
			for(t = 0; t<64 && x<N; t++){
				scanf("%d",&ss);
				if(ss)
					flag += ((unsigned long long)1<<t);
				++x;
			}						
			map[i].arg[j] = flag;			
		}		
	}
}

void aYUb(){		
	for(int i = 0; i < range; ++i){
		a.arg[i]  =  a.arg[i] & b.arg[i];		
	}
}

int getOne(){
	int max = 0,col = 0,i,j;	
	for(i = range-1; i >= 0; --i){		
		for(j = 63; j >= 0; --j){			
			if ( (a.arg[i] & ((unsigned long long)1<<j ))){
				++col;				
			}
			else{
				if(max < col) max = col;				
				col = 0;
			}			
		}
	}
	if(max < col) max = col;
	return max;
}

void nextLine(int nowLine){
	a = map[nowLine];
	int n = 1,max = 0;
	while(n <= M){
		max = getOne() * n;					
		if(max == 0)
			return ;
		if(res < max){
			res = max;			
		}
		if ( (max = nowLine + n) < M )
			b = map[max];
		else{
			break;
		}
		aYUb();		
		++n;
	}	
}

int main(){	
	clock_t start,finish;	
	start=clock();	
	//freopen("a.txt","r",stdin);
	//freopen("b.txt","w",stdout);
	int count=0;	
	while(scanf("%d%d",&M,&N)==2){
		++count;		
		init();			
		for(int i = 0; i < M; ++i)
			nextLine(i);
		printf("%d\n",res);
	}
	finish=clock();
    //cout << finish-start   << "/" << CLOCKS_PER_SEC  << " (s) "<< endl;
}		

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值