1e11150f2a 2014-02-26 kinaba: #include <iostream> 1e11150f2a 2014-02-26 kinaba: #include <sstream> 1e11150f2a 2014-02-26 kinaba: #include <iomanip> 1e11150f2a 2014-02-26 kinaba: #include <vector> 1e11150f2a 2014-02-26 kinaba: #include <string> 1e11150f2a 2014-02-26 kinaba: #include <map> 1e11150f2a 2014-02-26 kinaba: #include <set> 1e11150f2a 2014-02-26 kinaba: #include <algorithm> 1e11150f2a 2014-02-26 kinaba: #include <numeric> 1e11150f2a 2014-02-26 kinaba: #include <iterator> 1e11150f2a 2014-02-26 kinaba: #include <functional> 1e11150f2a 2014-02-26 kinaba: #include <complex> 1e11150f2a 2014-02-26 kinaba: #include <queue> 1e11150f2a 2014-02-26 kinaba: #include <stack> 1e11150f2a 2014-02-26 kinaba: #include <cmath> 1e11150f2a 2014-02-26 kinaba: #include <cassert> 1e11150f2a 2014-02-26 kinaba: #include <tuple> 1e11150f2a 2014-02-26 kinaba: using namespace std; 1e11150f2a 2014-02-26 kinaba: typedef long long LL; 1e11150f2a 2014-02-26 kinaba: typedef complex<double> CMP; 1e11150f2a 2014-02-26 kinaba: 1e11150f2a 2014-02-26 kinaba: class MagicalStringDiv1 { public: 1e11150f2a 2014-02-26 kinaba: int getLongest(string S) 1e11150f2a 2014-02-26 kinaba: { 1e11150f2a 2014-02-26 kinaba: int best = 0; 1e11150f2a 2014-02-26 kinaba: for(int rBegin=0; rBegin<S.size(); ++rBegin) 1e11150f2a 2014-02-26 kinaba: { 1e11150f2a 2014-02-26 kinaba: int l = count(S.begin(), S.begin()+rBegin, '>'); 1e11150f2a 2014-02-26 kinaba: int r = count(S.begin()+rBegin, S.end(), '<'); 1e11150f2a 2014-02-26 kinaba: best = max(best, 2*min(l,r)); 1e11150f2a 2014-02-26 kinaba: } 1e11150f2a 2014-02-26 kinaba: return best; 1e11150f2a 2014-02-26 kinaba: } 1e11150f2a 2014-02-26 kinaba: }; 1e11150f2a 2014-02-26 kinaba: 1e11150f2a 2014-02-26 kinaba: // BEGIN CUT HERE 1e11150f2a 2014-02-26 kinaba: #include <ctime> 1e11150f2a 2014-02-26 kinaba: double start_time; string timer() 1e11150f2a 2014-02-26 kinaba: { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); } 1e11150f2a 2014-02-26 kinaba: template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) 1e11150f2a 2014-02-26 kinaba: { os << "{ "; 1e11150f2a 2014-02-26 kinaba: for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it) 1e11150f2a 2014-02-26 kinaba: os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; } 1e11150f2a 2014-02-26 kinaba: void verify_case(const int& Expected, const int& Received) { 1e11150f2a 2014-02-26 kinaba: bool ok = (Expected == Received); 1e11150f2a 2014-02-26 kinaba: if(ok) cerr << "PASSED" << timer() << endl; else { cerr << "FAILED" << timer() << endl; 1e11150f2a 2014-02-26 kinaba: cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } } 1e11150f2a 2014-02-26 kinaba: #define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock(); 1e11150f2a 2014-02-26 kinaba: #define END verify_case(_, MagicalStringDiv1().getLongest(S));} 1e11150f2a 2014-02-26 kinaba: int main(){ 1e11150f2a 2014-02-26 kinaba: 1e11150f2a 2014-02-26 kinaba: CASE(0) 1e11150f2a 2014-02-26 kinaba: string S = "<><><<>"; 1e11150f2a 2014-02-26 kinaba: int _ = 4; 1e11150f2a 2014-02-26 kinaba: END 1e11150f2a 2014-02-26 kinaba: CASE(1) 1e11150f2a 2014-02-26 kinaba: string S = ">>><<<"; 1e11150f2a 2014-02-26 kinaba: int _ = 6; 1e11150f2a 2014-02-26 kinaba: END 1e11150f2a 2014-02-26 kinaba: CASE(2) 1e11150f2a 2014-02-26 kinaba: string S = "<<<>>>"; 1e11150f2a 2014-02-26 kinaba: int _ = 0; 1e11150f2a 2014-02-26 kinaba: END 1e11150f2a 2014-02-26 kinaba: CASE(3) 1e11150f2a 2014-02-26 kinaba: string S = "<<<<><>>><>>><>><>><>>><<<<>><>>>>><<>>>>><><<<<>>"; 1e11150f2a 2014-02-26 kinaba: int _ = 24; 1e11150f2a 2014-02-26 kinaba: END 1e11150f2a 2014-02-26 kinaba: /* 1e11150f2a 2014-02-26 kinaba: CASE(4) 1e11150f2a 2014-02-26 kinaba: string S = ; 1e11150f2a 2014-02-26 kinaba: int _ = ; 1e11150f2a 2014-02-26 kinaba: END 1e11150f2a 2014-02-26 kinaba: CASE(5) 1e11150f2a 2014-02-26 kinaba: string S = ; 1e11150f2a 2014-02-26 kinaba: int _ = ; 1e11150f2a 2014-02-26 kinaba: END 1e11150f2a 2014-02-26 kinaba: */ 1e11150f2a 2014-02-26 kinaba: } 1e11150f2a 2014-02-26 kinaba: // END CUT HERE