589fb61dc1 2014-08-30 kinaba: #include <iostream> 589fb61dc1 2014-08-30 kinaba: #include <sstream> 589fb61dc1 2014-08-30 kinaba: #include <iomanip> 589fb61dc1 2014-08-30 kinaba: #include <vector> 589fb61dc1 2014-08-30 kinaba: #include <string> 589fb61dc1 2014-08-30 kinaba: #include <map> 589fb61dc1 2014-08-30 kinaba: #include <set> 589fb61dc1 2014-08-30 kinaba: #include <algorithm> 589fb61dc1 2014-08-30 kinaba: #include <numeric> 589fb61dc1 2014-08-30 kinaba: #include <iterator> 589fb61dc1 2014-08-30 kinaba: #include <functional> 589fb61dc1 2014-08-30 kinaba: #include <complex> 589fb61dc1 2014-08-30 kinaba: #include <queue> 589fb61dc1 2014-08-30 kinaba: #include <stack> 589fb61dc1 2014-08-30 kinaba: #include <cmath> 589fb61dc1 2014-08-30 kinaba: #include <cassert> 589fb61dc1 2014-08-30 kinaba: #include <tuple> 589fb61dc1 2014-08-30 kinaba: using namespace std; 589fb61dc1 2014-08-30 kinaba: typedef long long LL; 589fb61dc1 2014-08-30 kinaba: typedef complex<double> CMP; 589fb61dc1 2014-08-30 kinaba: 589fb61dc1 2014-08-30 kinaba: class SuffixArrayDiv1 { public: 589fb61dc1 2014-08-30 kinaba: int minimalCharacters(vector <int> SA) 589fb61dc1 2014-08-30 kinaba: { 589fb61dc1 2014-08-30 kinaba: int N = SA.size(); 589fb61dc1 2014-08-30 kinaba: 589fb61dc1 2014-08-30 kinaba: vector<int> rank(N); 589fb61dc1 2014-08-30 kinaba: for(int i=0; i<N; ++i) 589fb61dc1 2014-08-30 kinaba: rank[SA[i]] = i; 589fb61dc1 2014-08-30 kinaba: rank.push_back(-1); // EOS 589fb61dc1 2014-08-30 kinaba: 589fb61dc1 2014-08-30 kinaba: int cnt = 1; 589fb61dc1 2014-08-30 kinaba: for(int pi=1; pi<N; ++pi) { 589fb61dc1 2014-08-30 kinaba: int p = SA[pi-1]; 589fb61dc1 2014-08-30 kinaba: int q = SA[pi]; 589fb61dc1 2014-08-30 kinaba: if(rank[p+1] > rank[q+1]) 589fb61dc1 2014-08-30 kinaba: ++cnt; 589fb61dc1 2014-08-30 kinaba: } 589fb61dc1 2014-08-30 kinaba: return cnt; 589fb61dc1 2014-08-30 kinaba: } 589fb61dc1 2014-08-30 kinaba: }; 589fb61dc1 2014-08-30 kinaba: 589fb61dc1 2014-08-30 kinaba: // BEGIN CUT HERE 589fb61dc1 2014-08-30 kinaba: #include <ctime> 589fb61dc1 2014-08-30 kinaba: double start_time; string timer() 589fb61dc1 2014-08-30 kinaba: { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); } 589fb61dc1 2014-08-30 kinaba: template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) 589fb61dc1 2014-08-30 kinaba: { os << "{ "; 589fb61dc1 2014-08-30 kinaba: for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it) 589fb61dc1 2014-08-30 kinaba: os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; } 589fb61dc1 2014-08-30 kinaba: void verify_case(const int& Expected, const int& Received) { 589fb61dc1 2014-08-30 kinaba: bool ok = (Expected == Received); 589fb61dc1 2014-08-30 kinaba: if(ok) cerr << "PASSED" << timer() << endl; else { cerr << "FAILED" << timer() << endl; 589fb61dc1 2014-08-30 kinaba: cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } } 589fb61dc1 2014-08-30 kinaba: #define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock(); 589fb61dc1 2014-08-30 kinaba: #define END verify_case(_, SuffixArrayDiv1().minimalCharacters(SA));} 589fb61dc1 2014-08-30 kinaba: int main(){ 589fb61dc1 2014-08-30 kinaba: 589fb61dc1 2014-08-30 kinaba: CASE(0) 589fb61dc1 2014-08-30 kinaba: int SA_[] = {3,0,1,2}; 589fb61dc1 2014-08-30 kinaba: vector <int> SA(SA_, SA_+sizeof(SA_)/sizeof(*SA_)); 589fb61dc1 2014-08-30 kinaba: int _ = 2; 589fb61dc1 2014-08-30 kinaba: END 589fb61dc1 2014-08-30 kinaba: CASE(1) 589fb61dc1 2014-08-30 kinaba: int SA_[] = {3,2,1,0}; 589fb61dc1 2014-08-30 kinaba: vector <int> SA(SA_, SA_+sizeof(SA_)/sizeof(*SA_)); 589fb61dc1 2014-08-30 kinaba: int _ = 1; 589fb61dc1 2014-08-30 kinaba: END 589fb61dc1 2014-08-30 kinaba: CASE(2) 589fb61dc1 2014-08-30 kinaba: int SA_[] = {0,1,2,3}; 589fb61dc1 2014-08-30 kinaba: vector <int> SA(SA_, SA_+sizeof(SA_)/sizeof(*SA_)); 589fb61dc1 2014-08-30 kinaba: int _ = 2; 589fb61dc1 2014-08-30 kinaba: END 589fb61dc1 2014-08-30 kinaba: CASE(3) 589fb61dc1 2014-08-30 kinaba: int SA_[] = {7,4,8,6,1,5,2,9,3,0}; 589fb61dc1 2014-08-30 kinaba: vector <int> SA(SA_, SA_+sizeof(SA_)/sizeof(*SA_)); 589fb61dc1 2014-08-30 kinaba: int _ = 4; 589fb61dc1 2014-08-30 kinaba: END 589fb61dc1 2014-08-30 kinaba: CASE(4) 589fb61dc1 2014-08-30 kinaba: int SA_[] = {0}; 589fb61dc1 2014-08-30 kinaba: vector <int> SA(SA_, SA_+sizeof(SA_)/sizeof(*SA_)); 589fb61dc1 2014-08-30 kinaba: int _ = 1; 589fb61dc1 2014-08-30 kinaba: END 589fb61dc1 2014-08-30 kinaba: /* 589fb61dc1 2014-08-30 kinaba: CASE(5) 589fb61dc1 2014-08-30 kinaba: int SA_[] = ; 589fb61dc1 2014-08-30 kinaba: vector <int> SA(SA_, SA_+sizeof(SA_)/sizeof(*SA_)); 589fb61dc1 2014-08-30 kinaba: int _ = ; 589fb61dc1 2014-08-30 kinaba: END 589fb61dc1 2014-08-30 kinaba: CASE(6) 589fb61dc1 2014-08-30 kinaba: int SA_[] = ; 589fb61dc1 2014-08-30 kinaba: vector <int> SA(SA_, SA_+sizeof(SA_)/sizeof(*SA_)); 589fb61dc1 2014-08-30 kinaba: int _ = ; 589fb61dc1 2014-08-30 kinaba: END 589fb61dc1 2014-08-30 kinaba: */ 589fb61dc1 2014-08-30 kinaba: } 589fb61dc1 2014-08-30 kinaba: // END CUT HERE