8a323e235a 2014-06-19 kinaba: #include <iostream> 8a323e235a 2014-06-19 kinaba: #include <sstream> 8a323e235a 2014-06-19 kinaba: #include <iomanip> 8a323e235a 2014-06-19 kinaba: #include <vector> 8a323e235a 2014-06-19 kinaba: #include <string> 8a323e235a 2014-06-19 kinaba: #include <map> 8a323e235a 2014-06-19 kinaba: #include <set> 8a323e235a 2014-06-19 kinaba: #include <algorithm> 8a323e235a 2014-06-19 kinaba: #include <numeric> 8a323e235a 2014-06-19 kinaba: #include <iterator> 8a323e235a 2014-06-19 kinaba: #include <functional> 8a323e235a 2014-06-19 kinaba: #include <complex> 8a323e235a 2014-06-19 kinaba: #include <queue> 8a323e235a 2014-06-19 kinaba: #include <stack> 8a323e235a 2014-06-19 kinaba: #include <cmath> 8a323e235a 2014-06-19 kinaba: #include <cassert> 8a323e235a 2014-06-19 kinaba: #include <tuple> 8a323e235a 2014-06-19 kinaba: using namespace std; 8a323e235a 2014-06-19 kinaba: typedef long long LL; 8a323e235a 2014-06-19 kinaba: typedef complex<double> CMP; 8a323e235a 2014-06-19 kinaba: 8a323e235a 2014-06-19 kinaba: class BuildingHeights { public: 8a323e235a 2014-06-19 kinaba: int minimum(vector <int> heights) 8a323e235a 2014-06-19 kinaba: { 8a323e235a 2014-06-19 kinaba: const int N = heights.size(); 8a323e235a 2014-06-19 kinaba: sort(heights.begin(), heights.end()); 8a323e235a 2014-06-19 kinaba: vector<int> sum(N+1); 8a323e235a 2014-06-19 kinaba: partial_sum(heights.begin(), heights.end(), sum.begin()+1); 8a323e235a 2014-06-19 kinaba: 8a323e235a 2014-06-19 kinaba: vector<int> A(N, 0x7fffffff); 8a323e235a 2014-06-19 kinaba: for(int s=0; s<N; ++s) 8a323e235a 2014-06-19 kinaba: for(int e=s+1; e<=N; ++e) 8a323e235a 2014-06-19 kinaba: { 8a323e235a 2014-06-19 kinaba: int M = e-s; 8a323e235a 2014-06-19 kinaba: int Max = heights[e-1]; 8a323e235a 2014-06-19 kinaba: int Sum = sum[e] - sum[s]; 8a323e235a 2014-06-19 kinaba: A[M-1] = min(A[M-1], Max*M-Sum); 8a323e235a 2014-06-19 kinaba: } 8a323e235a 2014-06-19 kinaba: 8a323e235a 2014-06-19 kinaba: int ans = 0; 8a323e235a 2014-06-19 kinaba: for(int a: A) ans ^= a; 8a323e235a 2014-06-19 kinaba: return ans; 8a323e235a 2014-06-19 kinaba: } 8a323e235a 2014-06-19 kinaba: }; 8a323e235a 2014-06-19 kinaba: 8a323e235a 2014-06-19 kinaba: // BEGIN CUT HERE 8a323e235a 2014-06-19 kinaba: #include <ctime> 8a323e235a 2014-06-19 kinaba: double start_time; string timer() 8a323e235a 2014-06-19 kinaba: { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); } 8a323e235a 2014-06-19 kinaba: template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) 8a323e235a 2014-06-19 kinaba: { os << "{ "; 8a323e235a 2014-06-19 kinaba: for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it) 8a323e235a 2014-06-19 kinaba: os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; } 8a323e235a 2014-06-19 kinaba: void verify_case(const int& Expected, const int& Received) { 8a323e235a 2014-06-19 kinaba: bool ok = (Expected == Received); 8a323e235a 2014-06-19 kinaba: if(ok) cerr << "PASSED" << timer() << endl; else { cerr << "FAILED" << timer() << endl; 8a323e235a 2014-06-19 kinaba: cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } } 8a323e235a 2014-06-19 kinaba: #define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock(); 8a323e235a 2014-06-19 kinaba: #define END verify_case(_, BuildingHeights().minimum(heights));} 8a323e235a 2014-06-19 kinaba: int main(){ 8a323e235a 2014-06-19 kinaba: 8a323e235a 2014-06-19 kinaba: CASE(0) 8a323e235a 2014-06-19 kinaba: int heights_[] = {1, 5, 4, 3, 8}; 8a323e235a 2014-06-19 kinaba: vector <int> heights(heights_, heights_+sizeof(heights_)/sizeof(*heights_)); 8a323e235a 2014-06-19 kinaba: int _ = 22; 8a323e235a 2014-06-19 kinaba: END 8a323e235a 2014-06-19 kinaba: CASE(1) 8a323e235a 2014-06-19 kinaba: int heights_[] = {1, 2, 3}; 8a323e235a 2014-06-19 kinaba: vector <int> heights(heights_, heights_+sizeof(heights_)/sizeof(*heights_)); 8a323e235a 2014-06-19 kinaba: int _ = 2; 8a323e235a 2014-06-19 kinaba: END 8a323e235a 2014-06-19 kinaba: CASE(2) 8a323e235a 2014-06-19 kinaba: int heights_[] = {3, 4, 1, 6, 8, 1}; 8a323e235a 2014-06-19 kinaba: vector <int> heights(heights_, heights_+sizeof(heights_)/sizeof(*heights_)); 8a323e235a 2014-06-19 kinaba: int _ = 21; 8a323e235a 2014-06-19 kinaba: END 8a323e235a 2014-06-19 kinaba: CASE(3) 8a323e235a 2014-06-19 kinaba: int heights_[] = {990, 20, 2359, 1667, 51, 2455, 1659, 1093, 2015, 205, 656, 752, 1760, 1594, 857, 8a323e235a 2014-06-19 kinaba: 2033, 1868, 1932, 2408, 1518, 91, 2220, 1696, 1552, 933, 143, 1888, 1261, 2298, 1975, 8a323e235a 2014-06-19 kinaba: 929, 2139, 1994, 2139, 158, 896, 2093, 1816, 841, 459, 2020, 1496, 63, 131, 589, 919, 8a323e235a 2014-06-19 kinaba: 1015, 1308, 350, 922, 326, 1792, 641, 2021, 843, 425, 1015, 231, 1685, 2165, 1057, 8a323e235a 2014-06-19 kinaba: 1465, 655, 550, 1103, 812, 297, 2048, 1479, 1137, 6, 2350, 1484, 1420, 1332, 925, 2338, 8a323e235a 2014-06-19 kinaba: 1198, 2232, 1539, 2119, 57, 830, 1611, 929, 525, 888}; 8a323e235a 2014-06-19 kinaba: vector <int> heights(heights_, heights_+sizeof(heights_)/sizeof(*heights_)); 8a323e235a 2014-06-19 kinaba: int _ = 56068; 8a323e235a 2014-06-19 kinaba: END 8a323e235a 2014-06-19 kinaba: /* 8a323e235a 2014-06-19 kinaba: CASE(4) 8a323e235a 2014-06-19 kinaba: int heights_[] = ; 8a323e235a 2014-06-19 kinaba: vector <int> heights(heights_, heights_+sizeof(heights_)/sizeof(*heights_)); 8a323e235a 2014-06-19 kinaba: int _ = ; 8a323e235a 2014-06-19 kinaba: END 8a323e235a 2014-06-19 kinaba: CASE(5) 8a323e235a 2014-06-19 kinaba: int heights_[] = ; 8a323e235a 2014-06-19 kinaba: vector <int> heights(heights_, heights_+sizeof(heights_)/sizeof(*heights_)); 8a323e235a 2014-06-19 kinaba: int _ = ; 8a323e235a 2014-06-19 kinaba: END 8a323e235a 2014-06-19 kinaba: */ 8a323e235a 2014-06-19 kinaba: } 8a323e235a 2014-06-19 kinaba: // END CUT HERE