Artifact Content
Not logged in

Artifact 716106b188541b813bb2db552bcd868a80993fe2


#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 <tuple>
using namespace std;
typedef long long LL;
typedef complex<double> CMP;

class PotentialArithmeticSequence { public:
	int numberOfSubsequences(vector <int> d)
	{
		int cnt = 0;
		for(int s=0; s<d.size(); ++s)
			for(int e=s+1; e<=d.size(); ++e)
				if(incr(vector<int>(d.begin()+s, d.begin()+e)))
					++cnt;
		return cnt;
	}

	bool incr(vector<int> d)
	{
		int mi = max_element(d.begin(), d.end()) - d.begin();
		int& M = d[mi];

		// Can assume a[mi] == 1<<M.
		M = min(M, 8);
		for(int i=0; i<d.size(); ++i) {
			int a = (1<<M)-mi+i;
			if(a<=0)
				return false;
			if(d[i]>M)
				return false;
			if(((a>>d[i])&1) == 0)
				return false;
			if(a & ((1<<d[i])-1))
				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 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(_, PotentialArithmeticSequence().numberOfSubsequences(d));}
int main(){

CASE(0)
	int d_[] = {0,1,0,2,0,1,0};
	  vector <int> d(d_, d_+sizeof(d_)/sizeof(*d_)); 
	int _ = 28; 
END
CASE(1)
	int d_[] = {0,0,0,0,0,0,0};
	  vector <int> d(d_, d_+sizeof(d_)/sizeof(*d_)); 
	int _ = 7; 
END
CASE(2)
	int d_[] = {0,0,0,0,1,1,1};
	  vector <int> d(d_, d_+sizeof(d_)/sizeof(*d_)); 
	int _ = 8; 
END
CASE(3)
	int d_[] = {0,100,0,2,0};
	  vector <int> d(d_, d_+sizeof(d_)/sizeof(*d_)); 
	int _ = 11; 
END
CASE(4)
	int d_[] = {1,11,3,0,1,0,1,0,1,0,1,0,3,0,2,0,0,0,0,1,2,3,20};
	  vector <int> d(d_, d_+sizeof(d_)/sizeof(*d_)); 
	int _ = 49; 
END
/*
CASE(5)
	int d_[] = ;
	  vector <int> d(d_, d_+sizeof(d_)/sizeof(*d_)); 
	int _ = ; 
END
CASE(6)
	int d_[] = ;
	  vector <int> d(d_, d_+sizeof(d_)/sizeof(*d_)); 
	int _ = ; 
END
*/
}
// END CUT HERE