Artifact Content
Not logged in

Artifact 4452768ad937b4c9ecd1c5cf8eda0b015f3898ed


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

class BestView {
public:
	int numberOfBuildings(vector <int> heights) 
	{
		int maxCnt = -1;

		int N = heights.size();
		for(int from=0; from<N; ++from)
		{
			int cnt = 0;
			for(int to=0; to<N; ++to) if(to != from)
			{
				bool hidden = false;
				for(int h=min(from,to)+1; h<max(from,to); ++h)
				{
					LL X1 = from;
					LL Y1 = heights[from];
					LL X2 = to;
					LL Y2 = heights[to];
					LL x = h;
					LL y = heights[h];
					// hide = (Y2-Y1)/(X2-X1)*(x-X1)+Y1 <= y
					if( X2-X1 > 0 ) {
						if( (Y2-Y1)*(x-X1) + Y1*(X2-X1) <= y * (X2-X1) )
							hidden = true;
					} else {
						if( (Y2-Y1)*(x-X1) + Y1*(X2-X1) >= y * (X2-X1) )
							hidden = true;
					}
				}
				if(!hidden) cnt++;
			}
			maxCnt = max(maxCnt, cnt);
		}
		return maxCnt;
	}
};

// 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> string print_array(const vector<T> &V) { ostringstream os; os << "{ "; for (typename vector<T>::const_iterator iter = V.begin(); iter != V.end(); ++iter) os << '\"' << *iter << "\","; os << " }"; return os.str(); }
int verify_case(const int &Expected, const int &Received) { if (Expected == Received) cerr << "PASSED" << timer() << endl; else { cerr << "FAILED" << timer() << endl; cerr << "\tExpected: \"" << Expected << '\"' << endl; cerr << "\tReceived: \"" << Received << '\"' << endl; } return 0;}

template<int N> struct Case_ { Case_(){start_time=clock();} };
char Test_(...);
int Test_(Case_<0>) {
	int heights_[] = {10};
	  vector <int> heights(heights_, heights_+sizeof(heights_)/sizeof(*heights_)); 
	int RetVal = 0; 
	return verify_case(RetVal, BestView().numberOfBuildings(heights)); }
int Test_(Case_<1>) {
	int heights_[] = {5,5,5,5};
	  vector <int> heights(heights_, heights_+sizeof(heights_)/sizeof(*heights_)); 
	int RetVal = 2; 
	return verify_case(RetVal, BestView().numberOfBuildings(heights)); }
int Test_(Case_<2>) {
	int heights_[] = {1,2,7,3,2};
	  vector <int> heights(heights_, heights_+sizeof(heights_)/sizeof(*heights_)); 
	int RetVal = 4; 
	return verify_case(RetVal, BestView().numberOfBuildings(heights)); }
int Test_(Case_<3>) {
	int heights_[] = {1,5,3,2,6,3,2,6,4,2,5,7,3,1,5};
	  vector <int> heights(heights_, heights_+sizeof(heights_)/sizeof(*heights_)); 
	int RetVal = 7; 
	return verify_case(RetVal, BestView().numberOfBuildings(heights)); }
int Test_(Case_<4>) {
	int heights_[] = {1000000000,999999999,999999998,999999997,999999996,1,2,3,4,5};
	  vector <int> heights(heights_, heights_+sizeof(heights_)/sizeof(*heights_)); 
	int RetVal = 6; 
	return verify_case(RetVal, BestView().numberOfBuildings(heights)); }
int Test_(Case_<5>) {
	int heights_[] = {244645169,956664793,752259473,577152868,605440232,569378507,111664772,653430457,454612157,397154317};
	  vector <int> heights(heights_, heights_+sizeof(heights_)/sizeof(*heights_)); 
	int RetVal = 7; 
	return verify_case(RetVal, BestView().numberOfBuildings(heights)); }

template<int N> void Run_() { cerr << "Test Case #" << N << "..." << flush; Test_(Case_<N>()); Run_<sizeof(Test_(Case_<N+1>()))==1 ? -1 : N+1>(); }
template<>      void Run_<-1>() {}
int main() { Run_<0>(); }
// END CUT HERE