1fbde9e2e2 2012-02-09 kinaba: #include <iostream> 1fbde9e2e2 2012-02-09 kinaba: #include <sstream> 1fbde9e2e2 2012-02-09 kinaba: #include <iomanip> 1fbde9e2e2 2012-02-09 kinaba: #include <vector> 1fbde9e2e2 2012-02-09 kinaba: #include <string> 1fbde9e2e2 2012-02-09 kinaba: #include <map> 1fbde9e2e2 2012-02-09 kinaba: #include <set> 1fbde9e2e2 2012-02-09 kinaba: #include <algorithm> 1fbde9e2e2 2012-02-09 kinaba: #include <numeric> 1fbde9e2e2 2012-02-09 kinaba: #include <iterator> 1fbde9e2e2 2012-02-09 kinaba: #include <functional> 1fbde9e2e2 2012-02-09 kinaba: #include <complex> 1fbde9e2e2 2012-02-09 kinaba: #include <queue> 1fbde9e2e2 2012-02-09 kinaba: #include <stack> 1fbde9e2e2 2012-02-09 kinaba: #include <cmath> 1fbde9e2e2 2012-02-09 kinaba: #include <cassert> 1fbde9e2e2 2012-02-09 kinaba: #include <cstring> 1fbde9e2e2 2012-02-09 kinaba: #ifdef __GNUC__ 1fbde9e2e2 2012-02-09 kinaba: #include <ext/hash_map> 1fbde9e2e2 2012-02-09 kinaba: #define unordered_map __gnu_cxx::hash_map 1fbde9e2e2 2012-02-09 kinaba: #else 1fbde9e2e2 2012-02-09 kinaba: #include <unordered_map> 1fbde9e2e2 2012-02-09 kinaba: #endif 1fbde9e2e2 2012-02-09 kinaba: using namespace std; 1fbde9e2e2 2012-02-09 kinaba: typedef long long LL; 1fbde9e2e2 2012-02-09 kinaba: typedef complex<double> CMP; 1fbde9e2e2 2012-02-09 kinaba: 1fbde9e2e2 2012-02-09 kinaba: class GogoXBallsAndBinsEasy { public: 1fbde9e2e2 2012-02-09 kinaba: int solve(vector <int> T) 1fbde9e2e2 2012-02-09 kinaba: { 1fbde9e2e2 2012-02-09 kinaba: int maxMove = 0; 1fbde9e2e2 2012-02-09 kinaba: 1fbde9e2e2 2012-02-09 kinaba: vector<int> S = T; 1fbde9e2e2 2012-02-09 kinaba: 1fbde9e2e2 2012-02-09 kinaba: reverse(S.begin(), S.end()); 1fbde9e2e2 2012-02-09 kinaba: int dif = 0; 1fbde9e2e2 2012-02-09 kinaba: for(int i=0; i<S.size(); ++i) 1fbde9e2e2 2012-02-09 kinaba: dif += abs(S[i]-T[i]); 1fbde9e2e2 2012-02-09 kinaba: maxMove = max(maxMove, dif/2); 1fbde9e2e2 2012-02-09 kinaba: /* 1fbde9e2e2 2012-02-09 kinaba: sort(S.begin(), S.end()); 1fbde9e2e2 2012-02-09 kinaba: do { 1fbde9e2e2 2012-02-09 kinaba: int dif = 0; 1fbde9e2e2 2012-02-09 kinaba: for(int i=0; i<S.size(); ++i) 1fbde9e2e2 2012-02-09 kinaba: dif += abs(S[i]-T[i]); 1fbde9e2e2 2012-02-09 kinaba: maxMove = max(maxMove, dif/2); 1fbde9e2e2 2012-02-09 kinaba: } while( next_permutation(S.begin(), S.end()) ); 1fbde9e2e2 2012-02-09 kinaba: */ 1fbde9e2e2 2012-02-09 kinaba: return maxMove; 1fbde9e2e2 2012-02-09 kinaba: } 1fbde9e2e2 2012-02-09 kinaba: }; 1fbde9e2e2 2012-02-09 kinaba: 1fbde9e2e2 2012-02-09 kinaba: // BEGIN CUT HERE 1fbde9e2e2 2012-02-09 kinaba: #include <ctime> 1fbde9e2e2 2012-02-09 kinaba: double start_time; string timer() 1fbde9e2e2 2012-02-09 kinaba: { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); } 1fbde9e2e2 2012-02-09 kinaba: template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) 1fbde9e2e2 2012-02-09 kinaba: { os << "{ "; 1fbde9e2e2 2012-02-09 kinaba: for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it) 1fbde9e2e2 2012-02-09 kinaba: os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; } 1fbde9e2e2 2012-02-09 kinaba: void verify_case(const int& Expected, const int& Received) { 1fbde9e2e2 2012-02-09 kinaba: bool ok = (Expected == Received); 1fbde9e2e2 2012-02-09 kinaba: if(ok) cerr << "PASSED" << timer() << endl; else { cerr << "FAILED" << timer() << endl; 1fbde9e2e2 2012-02-09 kinaba: cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } } 1fbde9e2e2 2012-02-09 kinaba: #define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock(); 1fbde9e2e2 2012-02-09 kinaba: #define END verify_case(_, GogoXBallsAndBinsEasy().solve(T));} 1fbde9e2e2 2012-02-09 kinaba: int main(){ 1fbde9e2e2 2012-02-09 kinaba: 1fbde9e2e2 2012-02-09 kinaba: CASE(0) 1fbde9e2e2 2012-02-09 kinaba: int T_[] = {0, 2, 5}; 1fbde9e2e2 2012-02-09 kinaba: vector <int> T(T_, T_+sizeof(T_)/sizeof(*T_)); 1fbde9e2e2 2012-02-09 kinaba: int _ = 5; 1fbde9e2e2 2012-02-09 kinaba: END 1fbde9e2e2 2012-02-09 kinaba: CASE(1) 1fbde9e2e2 2012-02-09 kinaba: int T_[] = {5, 6, 7, 8}; 1fbde9e2e2 2012-02-09 kinaba: vector <int> T(T_, T_+sizeof(T_)/sizeof(*T_)); 1fbde9e2e2 2012-02-09 kinaba: int _ = 4; 1fbde9e2e2 2012-02-09 kinaba: END 1fbde9e2e2 2012-02-09 kinaba: CASE(2) 1fbde9e2e2 2012-02-09 kinaba: int T_[] = {0, 1, 2, 10}; 1fbde9e2e2 2012-02-09 kinaba: vector <int> T(T_, T_+sizeof(T_)/sizeof(*T_)); 1fbde9e2e2 2012-02-09 kinaba: int _ = 11; 1fbde9e2e2 2012-02-09 kinaba: END 1fbde9e2e2 2012-02-09 kinaba: CASE(3) 1fbde9e2e2 2012-02-09 kinaba: int T_[] = {1, 2, 3, 4, 5, 6, 7, 8}; 1fbde9e2e2 2012-02-09 kinaba: vector <int> T(T_, T_+sizeof(T_)/sizeof(*T_)); 1fbde9e2e2 2012-02-09 kinaba: int _ = 16; 1fbde9e2e2 2012-02-09 kinaba: END 1fbde9e2e2 2012-02-09 kinaba: /* 1fbde9e2e2 2012-02-09 kinaba: CASE(4) 1fbde9e2e2 2012-02-09 kinaba: int T_[] = ; 1fbde9e2e2 2012-02-09 kinaba: vector <int> T(T_, T_+sizeof(T_)/sizeof(*T_)); 1fbde9e2e2 2012-02-09 kinaba: int _ = ; 1fbde9e2e2 2012-02-09 kinaba: END 1fbde9e2e2 2012-02-09 kinaba: CASE(5) 1fbde9e2e2 2012-02-09 kinaba: int T_[] = ; 1fbde9e2e2 2012-02-09 kinaba: vector <int> T(T_, T_+sizeof(T_)/sizeof(*T_)); 1fbde9e2e2 2012-02-09 kinaba: int _ = ; 1fbde9e2e2 2012-02-09 kinaba: END 1fbde9e2e2 2012-02-09 kinaba: */ 1fbde9e2e2 2012-02-09 kinaba: } 1fbde9e2e2 2012-02-09 kinaba: // END CUT HERE