Artifact Content
Not logged in

Artifact bc240ca099bb34e9815cfa359e7734454f6abea1


#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;

class FoxSequence { public:
	string isValid(vector <int> seq) 
	{
		for(int b=2; b<seq.size(); ++b)
			for(int c=b; c<seq.size()-2; ++c)
				if( isFox(seq,b,c) )
					return "YES";
		return "NO";
	}

	bool isFox( const vector<int>& seq, const int b, const int c )
	{
		for(int i=b; i<=c; ++i)
			if( seq[i] != seq[b] )
				return false;
		return isUpDown(seq, 0, b) && isUpDown(seq, c, seq.size()-1);
	}

	bool isUpDown( const vector<int>& seq, const int L, const int R )
	{
		int i = max_element(seq.begin()+L, seq.begin()+R+1) - seq.begin();
		if( L<i && i<R )
		{
			if( seq[L+1]>seq[L] && isArith(seq, L, i, seq[L+1]-seq[L])
			 && seq[R-1]>seq[R] && isArith(seq, i, R, seq[i+1]-seq[i]) )
			 return true;
		}
		return false;
	}

	bool isArith( const vector<int>& seq, const int L, const int R, int d )
	{
		for(int i=L; i+1<=R; ++i)
			if( seq[i+1]-seq[i] != d )
				return false;
		return true;
	}
};

// 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 string& Expected, const string& 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(_, FoxSequence().isValid(seq));}
int main(){

CASE(0)
	int seq_[] = {1,3,5,7,5,3,1,1,1,3,5,7,5,3,1}
;
	  vector <int> seq(seq_, seq_+sizeof(seq_)/sizeof(*seq_)); 
	string _ = "YES"; 
END
CASE(1)
	int seq_[] = {1,2,3,4,5,4,3,2,2,2,3,4,5,6,4}
;
	  vector <int> seq(seq_, seq_+sizeof(seq_)/sizeof(*seq_)); 
	string _ = "YES"; 
END
CASE(2)
	int seq_[] = {3,6,9,1,9,5,1}
;
	  vector <int> seq(seq_, seq_+sizeof(seq_)/sizeof(*seq_)); 
	string _ = "YES"; 
END
CASE(3)
	int seq_[] = {1,2,3,2,1,2,3,2,1,2,3,2,1}
;
	  vector <int> seq(seq_, seq_+sizeof(seq_)/sizeof(*seq_)); 
	string _ = "NO"; 
END
CASE(4)
	int seq_[] = {1,3,4,3,1,1,1,1,3,4,3,1}
;
	  vector <int> seq(seq_, seq_+sizeof(seq_)/sizeof(*seq_)); 
	string _ = "NO"; 
END
CASE(5)
	int seq_[] = {6,1,6}
;
	  vector <int> seq(seq_, seq_+sizeof(seq_)/sizeof(*seq_)); 
	string _ = "NO"; 
END
/*
CASE(6)
	int seq_[] = ;
	  vector <int> seq(seq_, seq_+sizeof(seq_)/sizeof(*seq_)); 
	string _ = ; 
END
CASE(7)
	int seq_[] = ;
	  vector <int> seq(seq_, seq_+sizeof(seq_)/sizeof(*seq_)); 
	string _ = ; 
END
*/
}
// END CUT HERE