Artifact Content
Not logged in

Artifact 65e4989f51362500ee86032ec2e73b4cc4a07495


#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <iterator>
#include <functional>
#include <complex>
#include <queue>
#include <stack>
#include <cmath>
#include <cassert>
#include <cstring>
using namespace std;
typedef long long LL;
typedef complex<double> CMP;

class UnluckyIntervals {
public:
	vector <int> getLuckiest(vector <int> luckySet, int n) 
	{
		sort(luckySet.begin(), luckySet.end());

		// zeros
		vector<int> luk = luckySet;
		for(LL i=0; i+1<luckySet.size(); ++i)
			if( i+1 < luckySet.size() )
				if( luckySet[i]+2 == luckySet[i+1] )
					luk.push_back( luckySet[i]+1 );
		if( luckySet[0]==2 )
			luk.push_back(1);
		sort(luk.begin(), luk.end());
		if( luk.size() >= n )
			return vector<int>(luk.begin(), luk.begin()+n);

		// finites
		vector< pair<LL, LL> > luk_val;
		LL from = 1;
		for(int i=0; i<luckySet.size(); ++i)
		{
			LL to = luckySet[i]; // [from,to)
			if( from+2 <= to )
			{
				for(LL j=0; j<min<LL>(to-from,n); ++j) {
					LL val = (j%2==0 ? from+j/2 : to-1-j/2);
					LL unluk = (j/2+1) * (to-from-j/2) - 1;
					luk_val.push_back( make_pair(unluk,val) );
				}
			}
			from = luckySet[i]+1;
		}
		sort( luk_val.begin(), luk_val.end() );
		for(int i=0; i<luk_val.size(); ++i)
			luk.push_back(luk_val[i].second);

		if( luk.size() >= n )
			return vector<int>(luk.begin(), luk.begin()+n);

		// infinites
		int v = luckySet.back()+1;
		while( luk.size() < n )
			luk.push_back(v++);
		return luk;
	}
};

// BEGIN CUT HERE
#include <ctime>
double start_time;string timer() { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); }

template <typename T> string print_array(const vector<T> &V) { ostringstream os; os << "{ "; for (typename vector<T>::const_iterator iter = V.begin(); iter != V.end(); ++iter) os << '\"' << *iter << "\","; os << " }"; return os.str(); }
int verify_case(const vector <int> &Expected, const vector <int> &Received) { if (Expected == Received) cerr << "PASSED" << timer() << endl; else { cerr << "FAILED" << timer() << endl; cerr << "\tExpected: " << print_array(Expected) << endl; cerr << "\tReceived: " << print_array(Received) << endl; } return 0;}

template<int N> struct Case_ { Case_(){start_time=clock();} };
char Test_(...);
int Test_(Case_<0>) {
	int luckySet_[] = {3};
	  vector <int> luckySet(luckySet_, luckySet_+sizeof(luckySet_)/sizeof(*luckySet_)); 
	int n = 6; 
	int RetVal_[] = {3, 1, 2, 4, 5, 6 };
	  vector <int> RetVal(RetVal_, RetVal_+sizeof(RetVal_)/sizeof(*RetVal_)); 
	return verify_case(RetVal, UnluckyIntervals().getLuckiest(luckySet, n)); }
int Test_(Case_<1>) {
	int luckySet_[] = {5, 11, 18};
	  vector <int> luckySet(luckySet_, luckySet_+sizeof(luckySet_)/sizeof(*luckySet_)); 
	int n = 9; 
	int RetVal_[] = {5, 11, 18, 1, 4, 6, 10, 2, 3 };
	  vector <int> RetVal(RetVal_, RetVal_+sizeof(RetVal_)/sizeof(*RetVal_)); 
	return verify_case(RetVal, UnluckyIntervals().getLuckiest(luckySet, n)); }
int Test_(Case_<2>) {
	int luckySet_[] = {7, 13, 18};
	  vector <int> luckySet(luckySet_, luckySet_+sizeof(luckySet_)/sizeof(*luckySet_)); 
	int n = 9; 
	int RetVal_[] = {7, 13, 18, 14, 17, 8, 12, 1, 6 };
	  vector <int> RetVal(RetVal_, RetVal_+sizeof(RetVal_)/sizeof(*RetVal_)); 
	return verify_case(RetVal, UnluckyIntervals().getLuckiest(luckySet, n)); }
int Test_(Case_<3>) {
	int luckySet_[] = {1000, 1004, 4000, 4003, 5000};
	  vector <int> luckySet(luckySet_, luckySet_+sizeof(luckySet_)/sizeof(*luckySet_)); 
	int n = 19; 
	int RetVal_[] = {1000, 1004, 4000, 4003, 5000, 4001, 4002, 1001, 1003, 1002, 4004, 4999, 1, 999, 4005, 4998, 2, 998, 4006 };
	  vector <int> RetVal(RetVal_, RetVal_+sizeof(RetVal_)/sizeof(*RetVal_)); 
	return verify_case(RetVal, UnluckyIntervals().getLuckiest(luckySet, n)); }
int Test_(Case_<4>) {
	int luckySet_[] = {1000000000};
	  vector <int> luckySet(luckySet_, luckySet_+sizeof(luckySet_)/sizeof(*luckySet_)); 
	int n = 8; 
	int RetVal_[] = {1000000000, 1, 999999999, 2, 999999998, 3, 999999997, 4 };
	  vector <int> RetVal(RetVal_, RetVal_+sizeof(RetVal_)/sizeof(*RetVal_)); 
	return verify_case(RetVal, UnluckyIntervals().getLuckiest(luckySet, n)); }
int Test_(Case_<5>) {
	int luckySet_[] = {2};
	  vector <int> luckySet(luckySet_, luckySet_+sizeof(luckySet_)/sizeof(*luckySet_)); 
	int n = 1;
	int RetVal_[] = {1};
	  vector <int> RetVal(RetVal_, RetVal_+sizeof(RetVal_)/sizeof(*RetVal_)); 
	return verify_case(RetVal, UnluckyIntervals().getLuckiest(luckySet, n)); }

template<int N> void Run_() { cerr << "Test Case #" << N << "..." << flush; Test_(Case_<N>()); Run_<sizeof(Test_(Case_<N+1>()))==1 ? -1 : N+1>(); }
template<>      void Run_<-1>() {}
int main() { Run_<0>(); }
// END CUT HERE