ea210c966f 2013-11-20 kinaba: #include <iostream> ea210c966f 2013-11-20 kinaba: #include <sstream> ea210c966f 2013-11-20 kinaba: #include <iomanip> ea210c966f 2013-11-20 kinaba: #include <vector> ea210c966f 2013-11-20 kinaba: #include <string> ea210c966f 2013-11-20 kinaba: #include <map> ea210c966f 2013-11-20 kinaba: #include <set> ea210c966f 2013-11-20 kinaba: #include <algorithm> ea210c966f 2013-11-20 kinaba: #include <numeric> ea210c966f 2013-11-20 kinaba: #include <iterator> ea210c966f 2013-11-20 kinaba: #include <functional> ea210c966f 2013-11-20 kinaba: #include <complex> ea210c966f 2013-11-20 kinaba: #include <queue> ea210c966f 2013-11-20 kinaba: #include <stack> ea210c966f 2013-11-20 kinaba: #include <cmath> ea210c966f 2013-11-20 kinaba: #include <cassert> ea210c966f 2013-11-20 kinaba: #include <tuple> ea210c966f 2013-11-20 kinaba: using namespace std; ea210c966f 2013-11-20 kinaba: typedef long long LL; ea210c966f 2013-11-20 kinaba: typedef complex<double> CMP; ea210c966f 2013-11-20 kinaba: ea210c966f 2013-11-20 kinaba: class IncrementAndDoubling { public: ea210c966f 2013-11-20 kinaba: int getMin(vector <int> d) ea210c966f 2013-11-20 kinaba: { ea210c966f 2013-11-20 kinaba: int cnt = 0; ea210c966f 2013-11-20 kinaba: for(;;++cnt) ea210c966f 2013-11-20 kinaba: { ea210c966f 2013-11-20 kinaba: for(auto& di : d) ea210c966f 2013-11-20 kinaba: if(di%2 == 1) ea210c966f 2013-11-20 kinaba: ++cnt, di--; ea210c966f 2013-11-20 kinaba: if(count(d.begin(), d.end(), 0) == d.size()) ea210c966f 2013-11-20 kinaba: break; ea210c966f 2013-11-20 kinaba: for(auto& di : d) ea210c966f 2013-11-20 kinaba: di /= 2; ea210c966f 2013-11-20 kinaba: } ea210c966f 2013-11-20 kinaba: return cnt; ea210c966f 2013-11-20 kinaba: } ea210c966f 2013-11-20 kinaba: }; ea210c966f 2013-11-20 kinaba: ea210c966f 2013-11-20 kinaba: // BEGIN CUT HERE ea210c966f 2013-11-20 kinaba: #include <ctime> ea210c966f 2013-11-20 kinaba: double start_time; string timer() ea210c966f 2013-11-20 kinaba: { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); } ea210c966f 2013-11-20 kinaba: template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) ea210c966f 2013-11-20 kinaba: { os << "{ "; ea210c966f 2013-11-20 kinaba: for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it) ea210c966f 2013-11-20 kinaba: os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; } ea210c966f 2013-11-20 kinaba: void verify_case(const int& Expected, const int& Received) { ea210c966f 2013-11-20 kinaba: bool ok = (Expected == Received); ea210c966f 2013-11-20 kinaba: if(ok) cerr << "PASSED" << timer() << endl; else { cerr << "FAILED" << timer() << endl; ea210c966f 2013-11-20 kinaba: cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } } ea210c966f 2013-11-20 kinaba: #define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock(); ea210c966f 2013-11-20 kinaba: #define END verify_case(_, IncrementAndDoubling().getMin(desiredArray));} ea210c966f 2013-11-20 kinaba: int main(){ ea210c966f 2013-11-20 kinaba: ea210c966f 2013-11-20 kinaba: CASE(0) ea210c966f 2013-11-20 kinaba: int desiredArray_[] = {2, 1}; ea210c966f 2013-11-20 kinaba: vector <int> desiredArray(desiredArray_, desiredArray_+sizeof(desiredArray_)/sizeof(*desiredArray_)); ea210c966f 2013-11-20 kinaba: int _ = 3; ea210c966f 2013-11-20 kinaba: END ea210c966f 2013-11-20 kinaba: CASE(1) ea210c966f 2013-11-20 kinaba: int desiredArray_[] = {16, 16, 16}; ea210c966f 2013-11-20 kinaba: vector <int> desiredArray(desiredArray_, desiredArray_+sizeof(desiredArray_)/sizeof(*desiredArray_)); ea210c966f 2013-11-20 kinaba: int _ = 7; ea210c966f 2013-11-20 kinaba: END ea210c966f 2013-11-20 kinaba: CASE(2) ea210c966f 2013-11-20 kinaba: int desiredArray_[] = {100}; ea210c966f 2013-11-20 kinaba: vector <int> desiredArray(desiredArray_, desiredArray_+sizeof(desiredArray_)/sizeof(*desiredArray_)); ea210c966f 2013-11-20 kinaba: int _ = 9; ea210c966f 2013-11-20 kinaba: END ea210c966f 2013-11-20 kinaba: CASE(3) ea210c966f 2013-11-20 kinaba: int desiredArray_[] = {0, 0, 1, 0, 1}; ea210c966f 2013-11-20 kinaba: vector <int> desiredArray(desiredArray_, desiredArray_+sizeof(desiredArray_)/sizeof(*desiredArray_)); ea210c966f 2013-11-20 kinaba: int _ = 2; ea210c966f 2013-11-20 kinaba: END ea210c966f 2013-11-20 kinaba: CASE(4) ea210c966f 2013-11-20 kinaba: int desiredArray_[] = {123, 234, 345, 456, 567, 789}; ea210c966f 2013-11-20 kinaba: vector <int> desiredArray(desiredArray_, desiredArray_+sizeof(desiredArray_)/sizeof(*desiredArray_)); ea210c966f 2013-11-20 kinaba: int _ = 40; ea210c966f 2013-11-20 kinaba: END ea210c966f 2013-11-20 kinaba: CASE(5) ea210c966f 2013-11-20 kinaba: int desiredArray_[] = {7,5,8,1,8,6,6,5,3,5,5,2,8,9,9,4,6,9,4,4,1,9,9,2,8,4,7,4,8,8,6,3,9,4,3,4,5,1,9,8,3,8,3,7,9,3,8,4,4,7}; ea210c966f 2013-11-20 kinaba: vector <int> desiredArray(desiredArray_, desiredArray_+sizeof(desiredArray_)/sizeof(*desiredArray_)); ea210c966f 2013-11-20 kinaba: int _ = 84; ea210c966f 2013-11-20 kinaba: END ea210c966f 2013-11-20 kinaba: /* ea210c966f 2013-11-20 kinaba: CASE(6) ea210c966f 2013-11-20 kinaba: int desiredArray_[] = ; ea210c966f 2013-11-20 kinaba: vector <int> desiredArray(desiredArray_, desiredArray_+sizeof(desiredArray_)/sizeof(*desiredArray_)); ea210c966f 2013-11-20 kinaba: int _ = ; ea210c966f 2013-11-20 kinaba: END ea210c966f 2013-11-20 kinaba: CASE(7) ea210c966f 2013-11-20 kinaba: int desiredArray_[] = ; ea210c966f 2013-11-20 kinaba: vector <int> desiredArray(desiredArray_, desiredArray_+sizeof(desiredArray_)/sizeof(*desiredArray_)); ea210c966f 2013-11-20 kinaba: int _ = ; ea210c966f 2013-11-20 kinaba: END ea210c966f 2013-11-20 kinaba: */ ea210c966f 2013-11-20 kinaba: } ea210c966f 2013-11-20 kinaba: // END CUT HERE