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