Artifact Content
Not logged in

Artifact 7d9c4ca801a229b36df4a7d20d994955afa2124b


#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 <tuple>
using namespace std;
typedef long long LL;
typedef complex<double> CMP;

class CountryGroupHard { public:
	string solve(vector <int> a)
	{
		return rec(0, a)==1 ? "Sufficient" : "Insufficient";
	}

	map<int, int> memo;
	int rec(int k, const vector<int>& a)
	{
		if(k == a.size())
			return 1;
		if(memo.count(k))
			return memo[k];

		int cnt = 0;
		for(int v=1; k+v<=int(a.size()); ++v) {
			set<int> s(a.begin()+k, a.begin()+k+v);
			s.erase(0);
			s.erase(v);
			if(s.empty())
				cnt += rec(k+v, a);
		}
		return memo[k] = (cnt>=2 ? 2 : cnt);
	}
};

// 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 string& Expected, const string& 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(_, CountryGroupHard().solve(a));}
int main(){

CASE(0)
	int a_[] = {0,2,3,0,0};
	  vector <int> a(a_, a_+sizeof(a_)/sizeof(*a_)); 
	string _ = "Sufficient"; 
END
CASE(1)
	int a_[] = {0,2,0};
	  vector <int> a(a_, a_+sizeof(a_)/sizeof(*a_)); 
	string _ = "Insufficient"; 
END
CASE(2)
	int a_[] = {0,3,0,0,3,0};
	  vector <int> a(a_, a_+sizeof(a_)/sizeof(*a_)); 
	string _ = "Sufficient"; 
END
CASE(3)
	int a_[] = {0,0,3,3,0,0};
	  vector <int> a(a_, a_+sizeof(a_)/sizeof(*a_)); 
	string _ = "Insufficient"; 
END
CASE(4)
	int a_[] = {2,2,0,2,2};
	  vector <int> a(a_, a_+sizeof(a_)/sizeof(*a_)); 
	string _ = "Sufficient"; 
END
/*
CASE(5)
	int a_[] = ;
	  vector <int> a(a_, a_+sizeof(a_)/sizeof(*a_)); 
	string _ = ; 
END
CASE(6)
	int a_[] = ;
	  vector <int> a(a_, a_+sizeof(a_)/sizeof(*a_)); 
	string _ = ; 
END
*/
}
// END CUT HERE