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