d649a7e3ca 2015-03-26 kinaba: #include <iostream> d649a7e3ca 2015-03-26 kinaba: #include <sstream> d649a7e3ca 2015-03-26 kinaba: #include <iomanip> d649a7e3ca 2015-03-26 kinaba: #include <vector> d649a7e3ca 2015-03-26 kinaba: #include <string> d649a7e3ca 2015-03-26 kinaba: #include <map> d649a7e3ca 2015-03-26 kinaba: #include <set> d649a7e3ca 2015-03-26 kinaba: #include <algorithm> d649a7e3ca 2015-03-26 kinaba: #include <numeric> d649a7e3ca 2015-03-26 kinaba: #include <iterator> d649a7e3ca 2015-03-26 kinaba: #include <functional> d649a7e3ca 2015-03-26 kinaba: #include <complex> d649a7e3ca 2015-03-26 kinaba: #include <queue> d649a7e3ca 2015-03-26 kinaba: #include <stack> d649a7e3ca 2015-03-26 kinaba: #include <cmath> d649a7e3ca 2015-03-26 kinaba: #include <cassert> d649a7e3ca 2015-03-26 kinaba: #include <tuple> d649a7e3ca 2015-03-26 kinaba: using namespace std; d649a7e3ca 2015-03-26 kinaba: typedef long long LL; d649a7e3ca 2015-03-26 kinaba: typedef complex<double> CMP; d649a7e3ca 2015-03-26 kinaba: d649a7e3ca 2015-03-26 kinaba: class CountryGroupHard { public: d649a7e3ca 2015-03-26 kinaba: string solve(vector <int> a) d649a7e3ca 2015-03-26 kinaba: { d649a7e3ca 2015-03-26 kinaba: return rec(0, a)==1 ? "Sufficient" : "Insufficient"; d649a7e3ca 2015-03-26 kinaba: } d649a7e3ca 2015-03-26 kinaba: d649a7e3ca 2015-03-26 kinaba: map<int, int> memo; d649a7e3ca 2015-03-26 kinaba: int rec(int k, const vector<int>& a) d649a7e3ca 2015-03-26 kinaba: { d649a7e3ca 2015-03-26 kinaba: if(k == a.size()) d649a7e3ca 2015-03-26 kinaba: return 1; d649a7e3ca 2015-03-26 kinaba: if(memo.count(k)) d649a7e3ca 2015-03-26 kinaba: return memo[k]; d649a7e3ca 2015-03-26 kinaba: d649a7e3ca 2015-03-26 kinaba: int cnt = 0; d649a7e3ca 2015-03-26 kinaba: for(int v=1; k+v<=int(a.size()); ++v) { d649a7e3ca 2015-03-26 kinaba: set<int> s(a.begin()+k, a.begin()+k+v); d649a7e3ca 2015-03-26 kinaba: s.erase(0); d649a7e3ca 2015-03-26 kinaba: s.erase(v); d649a7e3ca 2015-03-26 kinaba: if(s.empty()) d649a7e3ca 2015-03-26 kinaba: cnt += rec(k+v, a); d649a7e3ca 2015-03-26 kinaba: } d649a7e3ca 2015-03-26 kinaba: return memo[k] = (cnt>=2 ? 2 : cnt); d649a7e3ca 2015-03-26 kinaba: } d649a7e3ca 2015-03-26 kinaba: }; d649a7e3ca 2015-03-26 kinaba: d649a7e3ca 2015-03-26 kinaba: // BEGIN CUT HERE d649a7e3ca 2015-03-26 kinaba: #include <ctime> d649a7e3ca 2015-03-26 kinaba: double start_time; string timer() d649a7e3ca 2015-03-26 kinaba: { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); } d649a7e3ca 2015-03-26 kinaba: template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) d649a7e3ca 2015-03-26 kinaba: { os << "{ "; d649a7e3ca 2015-03-26 kinaba: for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it) d649a7e3ca 2015-03-26 kinaba: os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; } d649a7e3ca 2015-03-26 kinaba: void verify_case(const string& Expected, const string& Received) { d649a7e3ca 2015-03-26 kinaba: bool ok = (Expected == Received); d649a7e3ca 2015-03-26 kinaba: if(ok) cerr << "PASSED" << timer() << endl; else { cerr << "FAILED" << timer() << endl; d649a7e3ca 2015-03-26 kinaba: cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } } d649a7e3ca 2015-03-26 kinaba: #define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock(); d649a7e3ca 2015-03-26 kinaba: #define END verify_case(_, CountryGroupHard().solve(a));} d649a7e3ca 2015-03-26 kinaba: int main(){ d649a7e3ca 2015-03-26 kinaba: d649a7e3ca 2015-03-26 kinaba: CASE(0) d649a7e3ca 2015-03-26 kinaba: int a_[] = {0,2,3,0,0}; d649a7e3ca 2015-03-26 kinaba: vector <int> a(a_, a_+sizeof(a_)/sizeof(*a_)); d649a7e3ca 2015-03-26 kinaba: string _ = "Sufficient"; d649a7e3ca 2015-03-26 kinaba: END d649a7e3ca 2015-03-26 kinaba: CASE(1) d649a7e3ca 2015-03-26 kinaba: int a_[] = {0,2,0}; d649a7e3ca 2015-03-26 kinaba: vector <int> a(a_, a_+sizeof(a_)/sizeof(*a_)); d649a7e3ca 2015-03-26 kinaba: string _ = "Insufficient"; d649a7e3ca 2015-03-26 kinaba: END d649a7e3ca 2015-03-26 kinaba: CASE(2) d649a7e3ca 2015-03-26 kinaba: int a_[] = {0,3,0,0,3,0}; d649a7e3ca 2015-03-26 kinaba: vector <int> a(a_, a_+sizeof(a_)/sizeof(*a_)); d649a7e3ca 2015-03-26 kinaba: string _ = "Sufficient"; d649a7e3ca 2015-03-26 kinaba: END d649a7e3ca 2015-03-26 kinaba: CASE(3) d649a7e3ca 2015-03-26 kinaba: int a_[] = {0,0,3,3,0,0}; d649a7e3ca 2015-03-26 kinaba: vector <int> a(a_, a_+sizeof(a_)/sizeof(*a_)); d649a7e3ca 2015-03-26 kinaba: string _ = "Insufficient"; d649a7e3ca 2015-03-26 kinaba: END d649a7e3ca 2015-03-26 kinaba: CASE(4) d649a7e3ca 2015-03-26 kinaba: int a_[] = {2,2,0,2,2}; d649a7e3ca 2015-03-26 kinaba: vector <int> a(a_, a_+sizeof(a_)/sizeof(*a_)); d649a7e3ca 2015-03-26 kinaba: string _ = "Sufficient"; d649a7e3ca 2015-03-26 kinaba: END d649a7e3ca 2015-03-26 kinaba: /* d649a7e3ca 2015-03-26 kinaba: CASE(5) d649a7e3ca 2015-03-26 kinaba: int a_[] = ; d649a7e3ca 2015-03-26 kinaba: vector <int> a(a_, a_+sizeof(a_)/sizeof(*a_)); d649a7e3ca 2015-03-26 kinaba: string _ = ; d649a7e3ca 2015-03-26 kinaba: END d649a7e3ca 2015-03-26 kinaba: CASE(6) d649a7e3ca 2015-03-26 kinaba: int a_[] = ; d649a7e3ca 2015-03-26 kinaba: vector <int> a(a_, a_+sizeof(a_)/sizeof(*a_)); d649a7e3ca 2015-03-26 kinaba: string _ = ; d649a7e3ca 2015-03-26 kinaba: END d649a7e3ca 2015-03-26 kinaba: */ d649a7e3ca 2015-03-26 kinaba: } d649a7e3ca 2015-03-26 kinaba: // END CUT HERE