Artifact Content
Not logged in

Artifact 66d130730b42345ebe1bd3c04a80608706a51daf


#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 TheHexagonsDivOne { public:
	long long count(int n) 
	{
		// at least there must be 7<=2*n numbers...
		if( n <= 3 )
			return 0;

		// center hex has 2n possibility
		// choose others from 2(n-1) candidates
		// normalize by /6 to classify by the least number

		LL ans = 0;
		vector<int> pat;
		count_pat( pat, n-1, ans );
		return ans*2*n/6;
	}

	void count_pat( vector<int>& pat, LL n, LL& ans )
	{
		int i = pat.size();
		if( i == 6 )
		{
			LL distinct = set<int>(pat.begin(), pat.end()).size();
			LL tmp = 1;
			for(int d=0; d<distinct; ++d)
				tmp *= (n-d);

			LL dup = 6 - distinct;
			for(int d=0; d<dup; ++d)
				tmp *= 2;

			LL nodup = 6 - 2*dup;
			for(int d=0; d<nodup; ++d)
				tmp *= 2;

			ans += tmp;
			return;
		}

		vector<int> use(7);
		int next = 1;
		for(int k=0; k<pat.size(); ++k) {
			use[pat[k]]++;
			next = max(next, pat[k]+1);
		}

		if( next <= n )
		{
			pat.push_back(next);
			count_pat( pat, n, ans );
			pat.pop_back();
		}

		for(int p=1; p<next; ++p)
			if( use[p]<=1 )
				if( i==0 || (pat[i-1]!=p && (i<5 || pat[0]!=p)) )
				{
					pat.push_back(p);
					count_pat( pat, n, ans );
					pat.pop_back();
				}
	}
};

// 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> ostream& operator<<(ostream& os, const vector<T>& v)
 { os << "{ ";
   for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it)
   os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; }
void verify_case(const long long& Expected, const long long& Received) {
 bool ok = (Expected == Received);
 if(ok) cerr << "PASSED" << timer() << endl;  else { cerr << "FAILED" << timer() << endl;
 cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } }
#define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock();
#define END	 verify_case(_, TheHexagonsDivOne().count(n));}
int main(){

CASE(0)
	int n = 3; 
	long long _ = 0LL; 
END
CASE(1)
	int n = 4; 
	long long _ = 256LL; 
END
CASE(2)
	int n = 8; 
	long long _ = 3458560LL; 
END
CASE(3)
	int n = 20; 
	long long _ = 11193888000LL; 
END
CASE(4)
	int n = 1; 
	long long _ = 0LL; 
END
CASE(5)
	int n = 150; 
	long long _ = -1LL; 
END

}
// END CUT HERE