Artifact 03422e036f8b28bb1d26f7084b6030ba8b1424a5
#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 SubstringReversal { public:
vector <int> solve(string S)
{
multiset<char> chars;
for(char c: S) chars.insert(c);
string T = S;
for(int i=0; i<S.size(); ++i) {
if(S[i] == *chars.begin()) {
chars.erase(chars.begin());
continue;
}
// here is the point.
int best_k = i;
string best = S.substr(i);
for(int k=i+1; k<S.size(); ++k) {
string T(S.begin()+i, S.begin()+k+1);
reverse(T.begin(), T.end());
T += S.substr(k+1);
if(best > T)
best=T, best_k=k;
}
vector<int> ans;
ans.push_back(i);
ans.push_back(best_k);
return ans;
}
// no need to reverse
vector<int> ans;
ans.push_back(0);
ans.push_back(0);
return ans;
}
};
// 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 vector <int>& Expected, const vector <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(_, SubstringReversal().solve(S));}
int main(){
CASE(0)
string S = "abdc";
int __[] = {2, 3 };
vector <int> _(__, __+sizeof(__)/sizeof(*__));
END
CASE(1)
string S = "aabbcc";
int __[] = {0, 0 };
vector <int> _(__, __+sizeof(__)/sizeof(*__));
END
CASE(2)
string S = "misof";
int __[] = {0, 4 };
vector <int> _(__, __+sizeof(__)/sizeof(*__));
END
CASE(3)
string S = "ivan";
int __[] = {0, 2 };
vector <int> _(__, __+sizeof(__)/sizeof(*__));
END
CASE(4)
string S = "thisseemstobeaneasyproblem";
int __[] = {0, 13 };
vector <int> _(__, __+sizeof(__)/sizeof(*__));
END
/*
CASE(5)
string S = ;
int __[] = ;
vector <int> _(__, __+sizeof(__)/sizeof(*__));
END
CASE(6)
string S = ;
int __[] = ;
vector <int> _(__, __+sizeof(__)/sizeof(*__));
END
*/
}
// END CUT HERE