Artifact Content
Not logged in

Artifact d4a4f9e31f2db32bd5fd717fb25bb2389b4321d7


#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>
#ifdef __GNUC__
#include <ext/hash_map>
#define unordered_map __gnu_cxx::hash_map
#else
#include <unordered_map>
#endif
using namespace std;
typedef long long LL;
typedef complex<double> CMP;

class EllysString { public:
	int theMin(vector <string> s, vector <string> t)
	{
		string S = accumulate(s.begin(), s.end(), string(""));
		string T = accumulate(t.begin(), t.end(), string(""));
		int N = S.size();
		int total = 0;
		for(int i=0; i<N; )
		{
			if( S[i] == T[i] ) {
				++i;
				continue;
			}
			int rot_k = -1;

			// abcdef
			// bcdefa
			for(int k=i+1; k<N; ++k)
			{
				if( S[k] != T[k-1] )
					break;
				if( T[k] == S[i] )
					rot_k = max(rot_k, k+1);
			}
			// bcdefa
			// abcdef
			for(int k=i+1; k<N; ++k)
			{
				if( T[k] != S[k-1] )
					break;
				if( S[k] == T[i] )
					rot_k = max(rot_k, k+1);
			}

			if( rot_k == -1 ) {
				total += 1;
				++i;
				continue;
			} else {
				total += rot_k - i - 1;
				i = rot_k;
				continue;
			}
		}
		return total;
	}
};

// 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(_, EllysString().theMin(s, t));}
int main(){

CASE(0)
	string s_[] = {"usagi"};
	  vector <string> s(s_, s_+sizeof(s_)/sizeof(*s_)); 
	string t_[] = {"unagi"};
	  vector <string> t(t_, t_+sizeof(t_)/sizeof(*t_)); 
	int _ = 1; 
END
CASE(1)
	string s_[] = {"unagi"};
	  vector <string> s(s_, s_+sizeof(s_)/sizeof(*s_)); 
	string t_[] = {"nugai"};
	  vector <string> t(t_, t_+sizeof(t_)/sizeof(*t_)); 
	int _ = 2; 
END
CASE(2)
	string s_[] = {"ellys", "string"};
	  vector <string> s(s_, s_+sizeof(s_)/sizeof(*s_)); 
	string t_[] = {"e", "ll", "ysst", "ring"};
	  vector <string> t(t_, t_+sizeof(t_)/sizeof(*t_)); 
	int _ = 0; 
END
CASE(3)
	string s_[] = {"fox"};
	  vector <string> s(s_, s_+sizeof(s_)/sizeof(*s_)); 
	string t_[] = {"xfo"};
	  vector <string> t(t_, t_+sizeof(t_)/sizeof(*t_)); 
	int _ = 2; 
END
CASE(4)
	string s_[] = {"salmon"};
	  vector <string> s(s_, s_+sizeof(s_)/sizeof(*s_)); 
	string t_[] = {"camlon"};
	  vector <string> t(t_, t_+sizeof(t_)/sizeof(*t_)); 
	int _ = 2; 
END
CASE(5)
	string s_[] = {"boajxuidva"};
	  vector <string> s(s_, s_+sizeof(s_)/sizeof(*s_)); 
	string t_[] = {"jcayduvida"};
	  vector <string> t(t_, t_+sizeof(t_)/sizeof(*t_)); 
	int _ = 6; 
END
CASE(6)
	string s_[] = {"vykdnujyezbcbmnatipqfuxqmgkvtn"};
	  vector <string> s(s_, s_+sizeof(s_)/sizeof(*s_)); 
	string t_[] = {"qokbqyujeqcbwsinatupqfoegmvkdz"};
	  vector <string> t(t_, t_+sizeof(t_)/sizeof(*t_)); 
	int _ = 22; 
END
/*
CASE(7)
	string s_[] = ;
	  vector <string> s(s_, s_+sizeof(s_)/sizeof(*s_)); 
	string t_[] = ;
	  vector <string> t(t_, t_+sizeof(t_)/sizeof(*t_)); 
	int _ = ; 
END
CASE(8)
	string s_[] = ;
	  vector <string> s(s_, s_+sizeof(s_)/sizeof(*s_)); 
	string t_[] = ;
	  vector <string> t(t_, t_+sizeof(t_)/sizeof(*t_)); 
	int _ = ; 
END
*/
}
// END CUT HERE