1 条题解

  • 0
    @ 2024-7-27 15:08:50
    #include<bits/stdc++.h>
    using namespace std;
    int t,n,a;
    int sumz,sumf,sum0;
    long long zup[6],zdown[6],fup[6],fdown[6];
    long long maxn;
    void init(){
    	sumz=0;
    	sumf=0;
    	sum0=0;
    	memset(zup,20005,sizeof(zup));
    	memset(zdown,-20005,sizeof(zdown));
    	memset(fup,20005,sizeof(fup));
    	memset(fdown,-20005,sizeof(fdown));
    	maxn=-20005;
    	return;
    }
    bool cmp_up(int a,int b){//i 
    	return a<b;
    }
    bool cmp_down(int a,int b){
    	return a>b;
    }
    int main(){
    	cin>>t;
    	for(int s=1;s<=t;s++){
    		cin>>n;
    		init();
    		for(int i=1;i<=n;i++){
    			cin>>a;
    			if(a>0){
    				sumz++;
    				zup[5]=a;
    				zdown[5]=a;
    				sort(zup+1,zup+6,cmp_up);
    				sort(zdown+1,zdown+6,cmp_down);
    			}else if(a==0)sum0++;
    			else if(a<0){
    				sumf++;
    				fup[5]=a;
    				fdown[5]=a;
    				sort(fup+1,fup+6,cmp_up);
    				sort(fdown+1,fdown+6,cmp_down);
    			}
    		}
    		if(sum0>0)maxn=max(maxn,(long long)0);
    		if(sumz>=4)maxn=max(maxn,zdown[1]*zdown[2]*zdown[3]*zdown[4]);
    		if(sumz>=3&&sumf>=1)maxn=max(maxn,zup[1]*zup[2]*zup[3]*fdown[1]);
    		if(sumz>=2&&sumf>=2)maxn=max(maxn,zdown[1]*zdown[2]*fup[1]*fup[2]);
    		if(sumz>=1&&sumf>=3)maxn=max(maxn,zup[1]*fdown[1]*fdown[2]*fdown[3]);
    		if(sumf>=4)maxn=max(maxn,fup[1]*fup[2]*fup[3]*fup[4]);
    		cout<<maxn<<endl;
    	}
    	return 0;
    }
    
    • 1

    信息

    ID
    2983
    时间
    1000ms
    内存
    512MiB
    难度
    8
    标签
    递交数
    235
    已通过
    29
    上传者