/ SeriousOJ /

Record Detail

Time Exceeded


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Accepted 2ms 512.0 KiB
#3 Accepted 2ms 532.0 KiB
#4 Accepted 2ms 564.0 KiB
#5 Accepted 1ms 532.0 KiB
#6 Accepted 1ms 532.0 KiB
#7 Accepted 1ms 532.0 KiB
#8 Accepted 1ms 532.0 KiB
#9 Accepted 2ms 516.0 KiB
#10 Accepted 2ms 484.0 KiB
#11 Accepted 2ms 532.0 KiB
#12 Accepted 1ms 532.0 KiB
#13 Accepted 726ms 564.0 KiB
#14 Accepted 714ms 564.0 KiB
#15 Accepted 3ms 532.0 KiB
#16 Accepted 8ms 572.0 KiB
#17 Accepted 5ms 532.0 KiB
#18 Accepted 301ms 560.0 KiB
#19 Accepted 203ms 560.0 KiB
#20 Accepted 19ms 532.0 KiB
#21 Accepted 2ms 532.0 KiB
#22 Accepted 13ms 564.0 KiB
#23 Time Exceeded ≥4096ms ≥532.0 KiB
#24 Accepted 2971ms 564.0 KiB
#25 Accepted 970ms 564.0 KiB
#26 Accepted 646ms 560.0 KiB
#27 Accepted 1776ms 560.0 KiB

Code

/**
Author : Kamonasish Roy (Bullet)
**/
#include<bits/stdc++.h>
using namespace std;
const long long M=5e5,MOD=1e9+7;
typedef long long ll;


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t=1;
    cin>>t;
    while(t--){
    	int n;
    	cin>>n;
    	vector<int>a(n);
    	for(auto &i:a)cin>>i;
    	sort(a.begin(),a.end());
    	vector<int>dif;
    	if(n==2){
    		cout<<1<<"\n";
    		continue;
    	}
    	for(int i=1;i<n;i++){
    		dif.push_back(a[i]-a[0]);
    	}
    	int mx=1;
    	for(auto id:dif){
    		multiset<int>st;
    		for(int i=0;i<n;i++)st.insert(a[i]);
    		vector<int>rem;
    		vector<pair<int,int>>pi;
    		int x=0;
    		pi.push_back({a[0],a[0]+id});
    		st.erase(st.find(a[0]));
    		st.erase(st.find(a[0]+id));
    		if(st.find(a[n-1])==st.end()){
    			continue;
    		}
    		st.erase(st.find(a[n-1]));
    		if(st.find(a[n-1]-id)==st.end()){
    			continue;
    		}
    		st.erase(st.find(a[n-1]-id));
    		while((int)st.size()>1){
    			auto it=st.begin();
    			int cur=*it;
    			st.erase(it);
    			if(st.find(cur+id)!=st.end()){
    				pi.push_back({cur,cur+id});
    				st.erase(st.find(cur+id));
    			}
    			else{
    				rem.push_back(cur);
    			}
    		}
    		pi.push_back({a[n-1]-id,a[n-1]});
    		for(auto i:st)rem.push_back(i);
    	//	for(auto i:pi)cout<<i.first<<" "<<i.second<<endl;
    		if((int)pi.size()<=1){
    			continue;
    		}
    		//continue;
    		int len=pi.size();
    		len=1<<len;
    		for(int mask=0;mask<len;mask++){
    			vector<int>temp;
    			vector<int>vis((int)pi.size(),0);
    			int cnt=0;
    			for(int j=0;j<(int)pi.size();j++){
    				int f=1<<j;
    				if((f & mask)!=0){
    					temp.push_back(j);
    					vis[j]=1;
    					cnt++;
    				}
    			}
    			if(cnt<2 || !vis[0] || !vis[(int)pi.size()-1])continue;
    			if(n%cnt!=0)continue;
    			vector<int>baki=rem;
    			for(int j=0;j<pi.size();j++){
    				if(!vis[j]){
    				   baki.push_back(pi[j].first);
    				   baki.push_back(pi[j].second);
    				}
    			}
    			if((int)baki.size()==0){
    				mx=max(mx,(int)temp.size());
    				continue;
    			}
    			//continue;
    			
    			sort(baki.begin(),baki.end());
    			int lagba=n/cnt;
    			lagba-=2;
    			int kk=0;
    			int f=1;
    			for(int ii:temp){
    				int x=pi[ii].first;
    				int y=pi[ii].second;
    				int d=lagba;
    				while(d>0){
    					f&=(x<=baki[kk] && y>=baki[kk]);
    					kk++;
    					d--;
    					
    				}
    				if(!f)break;
    			}
    			if(f)mx=max(mx,(int)temp.size());
    		}
    	}
    	cout<<mx<<"\n";
    	
    	
    	}
    	
    	   
    return 0;
 
}

Information

Submit By
Type
Submission
Problem
P1162 Roy and Maximum Partition
Language
C++17 (G++ 13.2.0)
Submit At
2025-01-26 19:21:23
Judged At
2025-02-17 12:43:14
Judged By
Score
99
Total Time
≥4096ms
Peak Memory
≥572.0 KiB