Artifact Content
Not logged in

Artifact ae2c1c3a335778aa5bb60ba9d9d7a70bc95fa662


#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 SuffixArrayDiv1 { public:
	int minimalCharacters(vector <int> SA)
	{
		int N = SA.size();

		vector<int> rank(N);
		for(int i=0; i<N; ++i)
			rank[SA[i]] = i;
		rank.push_back(-1); // EOS

		int cnt = 1;
		for(int pi=1; pi<N; ++pi) {
			int p = SA[pi-1];
			int q = SA[pi];
			if(rank[p+1] > rank[q+1])
				++cnt;
		}
		return cnt;
	}
};

// 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(_, SuffixArrayDiv1().minimalCharacters(SA));}
int main(){

CASE(0)
	int SA_[] = {3,0,1,2};
	  vector <int> SA(SA_, SA_+sizeof(SA_)/sizeof(*SA_)); 
	int _ = 2; 
END
CASE(1)
	int SA_[] = {3,2,1,0};
	  vector <int> SA(SA_, SA_+sizeof(SA_)/sizeof(*SA_)); 
	int _ = 1; 
END
CASE(2)
	int SA_[] = {0,1,2,3};
	  vector <int> SA(SA_, SA_+sizeof(SA_)/sizeof(*SA_)); 
	int _ = 2; 
END
CASE(3)
	int SA_[] = {7,4,8,6,1,5,2,9,3,0};
	  vector <int> SA(SA_, SA_+sizeof(SA_)/sizeof(*SA_)); 
	int _ = 4; 
END
CASE(4)
	int SA_[] = {0};
	  vector <int> SA(SA_, SA_+sizeof(SA_)/sizeof(*SA_)); 
	int _ = 1; 
END
/*
CASE(5)
	int SA_[] = ;
	  vector <int> SA(SA_, SA_+sizeof(SA_)/sizeof(*SA_)); 
	int _ = ; 
END
CASE(6)
	int SA_[] = ;
	  vector <int> SA(SA_, SA_+sizeof(SA_)/sizeof(*SA_)); 
	int _ = ; 
END
*/
}
// END CUT HERE