Artifact Content
Not logged in

Artifact 49693ab4e53ef6821d81ccc5c7f2c4adffb75284


#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <iterator>
#include <functional>
#include <complex>
#include <queue>
#include <stack>
#include <cmath>
#include <cassert>
#include <cstring>
using namespace std;
typedef long long LL;
typedef complex<double> CMP;

double outer_prod(const CMP& a, const CMP& b) { return imag(conj(a)*b); }
double inner_prod(const CMP& a, const CMP& b) { return real(conj(a)*b); }
int ccw(const CMP& a, CMP b, CMP c) {
	b -= a; c -= a;
	if( outer_prod(b,c) > 0 ) return +1; // counter clockwise
	if( outer_prod(b,c) < 0 ) return -1; // clockwise
	if( inner_prod(b,c) < 0 ) return +2; // c--[a--b] on line
	if( norm(b) < norm(c) )   return -2; // [a--b]--c on line
	return 0; // [a--c--b] on line
}

class TimeTravellingGardener { public:
	int determineUsage(vector <int> distance, vector <int> height) 
	{
		const int N = height.size();

		distance.insert(distance.begin(), 0);
		partial_sum(distance.begin(), distance.end(), distance.begin());

		vector<CMP> p;
		for(int i=0; i<N; ++i)
			p.push_back( CMP(distance[i], height[i]) );

		int best = N-1;
		for(int i=0; i<N; ++i)
			for(int j=i+1; j<N; ++j)
			{
				best = min(best, score(p[i], p[j], p));
				best = min(best, score(p[i].real(), p[j], p));
				best = min(best, score(p[i], p[j].real(), p));
			}
		return best;
	}

	int score(const CMP& a, const CMP& b, const vector<CMP>& p)
	{
		int s = 0;
		for(int i=0; i<p.size(); ++i)
		{
			if( ccw(a, b, p[i]) == -1 ) return INT_MAX;
			if( ccw(a, b, p[i].real()) == +1 ) return INT_MAX;
			if( ccw(a, b, p[i]) == +1 ) ++s;
		}
		return s;
	}
};

// BEGIN CUT HERE
#include <ctime>
double start_time; string timer()
 { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); }
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v)
 { os << "{ ";
   for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it)
   os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; }
void verify_case(const int& Expected, const int& Received) {
 bool ok = (Expected == Received);
 if(ok) cerr << "PASSED" << timer() << endl;  else { cerr << "FAILED" << timer() << endl;
 cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } }
#define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock();
#define END	 verify_case(_, TimeTravellingGardener().determineUsage(distance, height));}
int main(){

CASE(0)
	int distance_[] = {2,2};
	  vector <int> distance(distance_, distance_+sizeof(distance_)/sizeof(*distance_)); 
	int height_[] = {1,3,10};
	  vector <int> height(height_, height_+sizeof(height_)/sizeof(*height_)); 
	int _ = 1; 
END
CASE(1)
	int distance_[] = {3,3};
	  vector <int> distance(distance_, distance_+sizeof(distance_)/sizeof(*distance_)); 
	int height_[] = {3,1,3};
	  vector <int> height(height_, height_+sizeof(height_)/sizeof(*height_)); 
	int _ = 2; 
END
CASE(2)
	int distance_[] = {1,3};
	  vector <int> distance(distance_, distance_+sizeof(distance_)/sizeof(*distance_)); 
	int height_[] = {4,4,4};
	  vector <int> height(height_, height_+sizeof(height_)/sizeof(*height_)); 
	int _ = 0; 
END
CASE(3)
	int distance_[] = {4,2};
	  vector <int> distance(distance_, distance_+sizeof(distance_)/sizeof(*distance_)); 
	int height_[] = {9,8,5};
	  vector <int> height(height_, height_+sizeof(height_)/sizeof(*height_)); 
	int _ = 1; 
END
CASE(4)
	int distance_[] = {476,465,260,484};
	  vector <int> distance(distance_, distance_+sizeof(distance_)/sizeof(*distance_)); 
	int height_[] = {39,13,8,72,80};
	  vector <int> height(height_, height_+sizeof(height_)/sizeof(*height_)); 
	int _ = 3; 
END
CASE(5)
	int distance_[] = {173,36,668,79,26,544};
	  vector <int> distance(distance_, distance_+sizeof(distance_)/sizeof(*distance_)); 
	int height_[] = {488,743,203,446,444,91,453};
	  vector <int> height(height_, height_+sizeof(height_)/sizeof(*height_)); 
	int _ = 5; 
END
CASE(6)
	int distance_[] = {2,4,2,2,4,2,4,2,2,4};
	  vector <int> distance(distance_, distance_+sizeof(distance_)/sizeof(*distance_)); 
	int height_[] = {2,2,10,10,10,16,16,22,22,28,28};
	  vector <int> height(height_, height_+sizeof(height_)/sizeof(*height_)); 
	int _ = 6; 
END
}
// END CUT HERE