e474130ec2 2016-08-18 kinaba: #include <iostream> e474130ec2 2016-08-18 kinaba: #include <sstream> e474130ec2 2016-08-18 kinaba: #include <iomanip> e474130ec2 2016-08-18 kinaba: #include <vector> e474130ec2 2016-08-18 kinaba: #include <string> e474130ec2 2016-08-18 kinaba: #include <map> e474130ec2 2016-08-18 kinaba: #include <set> e474130ec2 2016-08-18 kinaba: #include <algorithm> e474130ec2 2016-08-18 kinaba: #include <numeric> e474130ec2 2016-08-18 kinaba: #include <iterator> e474130ec2 2016-08-18 kinaba: #include <functional> e474130ec2 2016-08-18 kinaba: #include <complex> e474130ec2 2016-08-18 kinaba: #include <queue> e474130ec2 2016-08-18 kinaba: #include <stack> e474130ec2 2016-08-18 kinaba: #include <cmath> e474130ec2 2016-08-18 kinaba: #include <cassert> e474130ec2 2016-08-18 kinaba: #include <tuple> e474130ec2 2016-08-18 kinaba: using namespace std; e474130ec2 2016-08-18 kinaba: typedef long long LL; e474130ec2 2016-08-18 kinaba: typedef complex<double> CMP; e474130ec2 2016-08-18 kinaba: e474130ec2 2016-08-18 kinaba: class TrySail { public: e474130ec2 2016-08-18 kinaba: int get(vector <int> strength) e474130ec2 2016-08-18 kinaba: { e474130ec2 2016-08-18 kinaba: vector<bool> possible(65536, false); e474130ec2 2016-08-18 kinaba: possible[0] = true; e474130ec2 2016-08-18 kinaba: for(int s: strength) { e474130ec2 2016-08-18 kinaba: vector<bool> p2 = possible; e474130ec2 2016-08-18 kinaba: for(int a=0; a<256; ++a) e474130ec2 2016-08-18 kinaba: for(int b=0; b<256; ++b) if(possible[a*256+b]) e474130ec2 2016-08-18 kinaba: p2[(a^s)*256+b] = p2[a*256+(b^s)] = true; e474130ec2 2016-08-18 kinaba: possible.swap(p2); e474130ec2 2016-08-18 kinaba: } e474130ec2 2016-08-18 kinaba: e474130ec2 2016-08-18 kinaba: int all = 0; e474130ec2 2016-08-18 kinaba: for(int s: strength) all ^= s; e474130ec2 2016-08-18 kinaba: e474130ec2 2016-08-18 kinaba: int best = 0; e474130ec2 2016-08-18 kinaba: for(int a=0; a<256; ++a) e474130ec2 2016-08-18 kinaba: for(int b=0; b<256; ++b) if(possible[a*256+b]) e474130ec2 2016-08-18 kinaba: best = max(best, a+b+(all^a^b)); e474130ec2 2016-08-18 kinaba: return best; e474130ec2 2016-08-18 kinaba: } e474130ec2 2016-08-18 kinaba: }; e474130ec2 2016-08-18 kinaba: e474130ec2 2016-08-18 kinaba: // BEGIN CUT HERE e474130ec2 2016-08-18 kinaba: #include <ctime> e474130ec2 2016-08-18 kinaba: double start_time; string timer() e474130ec2 2016-08-18 kinaba: { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); } e474130ec2 2016-08-18 kinaba: template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) e474130ec2 2016-08-18 kinaba: { os << "{ "; e474130ec2 2016-08-18 kinaba: for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it) e474130ec2 2016-08-18 kinaba: os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; } e474130ec2 2016-08-18 kinaba: void verify_case(const int& Expected, const int& Received) { e474130ec2 2016-08-18 kinaba: bool ok = (Expected == Received); e474130ec2 2016-08-18 kinaba: if(ok) cerr << "PASSED" << timer() << endl; else { cerr << "FAILED" << timer() << endl; e474130ec2 2016-08-18 kinaba: cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } } e474130ec2 2016-08-18 kinaba: #define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock(); e474130ec2 2016-08-18 kinaba: #define END verify_case(_, TrySail().get(strength));} e474130ec2 2016-08-18 kinaba: int main(){ e474130ec2 2016-08-18 kinaba: e474130ec2 2016-08-18 kinaba: CASE(0) e474130ec2 2016-08-18 kinaba: int strength_[] = {2,3,3}; e474130ec2 2016-08-18 kinaba: vector <int> strength(strength_, strength_+sizeof(strength_)/sizeof(*strength_)); e474130ec2 2016-08-18 kinaba: int _ = 8; e474130ec2 2016-08-18 kinaba: END e474130ec2 2016-08-18 kinaba: CASE(1) e474130ec2 2016-08-18 kinaba: int strength_[] = {7,3,5,2}; e474130ec2 2016-08-18 kinaba: vector <int> strength(strength_, strength_+sizeof(strength_)/sizeof(*strength_)); e474130ec2 2016-08-18 kinaba: int _ = 17; e474130ec2 2016-08-18 kinaba: END e474130ec2 2016-08-18 kinaba: CASE(2) e474130ec2 2016-08-18 kinaba: int strength_[] = {13,13,13,13,13,13,13,13}; e474130ec2 2016-08-18 kinaba: vector <int> strength(strength_, strength_+sizeof(strength_)/sizeof(*strength_)); e474130ec2 2016-08-18 kinaba: int _ = 26; e474130ec2 2016-08-18 kinaba: END e474130ec2 2016-08-18 kinaba: CASE(3) e474130ec2 2016-08-18 kinaba: int strength_[] = {114,51,4,191,9,81,0,89,3}; e474130ec2 2016-08-18 kinaba: vector <int> strength(strength_, strength_+sizeof(strength_)/sizeof(*strength_)); e474130ec2 2016-08-18 kinaba: int _ = 470; e474130ec2 2016-08-18 kinaba: END e474130ec2 2016-08-18 kinaba: CASE(4) e474130ec2 2016-08-18 kinaba: int strength_[] = {108,66,45,82,163,30,83,244,200,216,241,249,89,128,36,28,250,190,70,95,117,196,19,160,255,129,10,109,189,24,22,25,134,144,110,15,235,205,186,103,116,191,119,183,45,217,156,44,97,197}; e474130ec2 2016-08-18 kinaba: vector <int> strength(strength_, strength_+sizeof(strength_)/sizeof(*strength_)); e474130ec2 2016-08-18 kinaba: int _ = 567; e474130ec2 2016-08-18 kinaba: END e474130ec2 2016-08-18 kinaba: /* e474130ec2 2016-08-18 kinaba: CASE(5) e474130ec2 2016-08-18 kinaba: int strength_[] = ; e474130ec2 2016-08-18 kinaba: vector <int> strength(strength_, strength_+sizeof(strength_)/sizeof(*strength_)); e474130ec2 2016-08-18 kinaba: int _ = ; e474130ec2 2016-08-18 kinaba: END e474130ec2 2016-08-18 kinaba: CASE(6) e474130ec2 2016-08-18 kinaba: int strength_[] = ; e474130ec2 2016-08-18 kinaba: vector <int> strength(strength_, strength_+sizeof(strength_)/sizeof(*strength_)); e474130ec2 2016-08-18 kinaba: int _ = ; e474130ec2 2016-08-18 kinaba: END e474130ec2 2016-08-18 kinaba: */ e474130ec2 2016-08-18 kinaba: } e474130ec2 2016-08-18 kinaba: // END CUT HERE