Artifact 8773ddd5052442dbf52b48cddc7b7a8cd4a7987c
#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>
using namespace std;
typedef long long LL;
typedef long double LD;
typedef complex<LD> CMP;
template<typename T>
struct DP2
{
const int N1, N2;
vector<T> data;
DP2(int N1, int N2, const T& t = T())
: N1(N1), N2(N2), data(N1*N2, t) { assert(data.size()*sizeof(T)<(1<<26)); }
T& operator()(int i1, int i2)
{ return data[ (i1*N2)+i2 ]; }
void swap(DP2& rhs)
{ data.swap(rhs.data); }
};
class TheLargestString { public:
string find(string s, string t)
{
const int N = s.size();
DP2< pair<string,string> > best(N+1,N+1);
for(int i=N-1; i>=0; --i)
{
for(int len=1; len<=N-i; ++len)
{
pair<string, string> cand = best(i+1, len);
pair<string, string> cand2(s[i]+best(i+1, len-1).first, t[i]+best(i+1,len-1).second);
if(cand.first+cand.second < cand2.first+cand2.second)
cand = cand2;
best(i, len) = cand;
}
}
string ans;
for(int len=0; len<=N; ++len)
ans = max(ans, best(0,len).first + best(0,len).second);
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 string& Expected, const string& 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(_, TheLargestString().find(s, t));}
int main(){
CASE(0)
string s = "ab";
string t = "zy";
string _ = "by";
END
CASE(1)
string s = "abacaba";
string t = "zzzaaaa";
string _ = "cbaaaa";
END
CASE(2)
string s = "x";
string t = "x";
string _ = "xx";
END
CASE(3)
string s = "abbabbabbababaaaabbababab";
string t = "bababbaabbbababbbbababaab";
string _ = "bbbbbbbbbbbbbbbbbbaaab";
END
/*
CASE(4)
string s = ;
string t = ;
string _ = ;
END
CASE(5)
string s = ;
string t = ;
string _ = ;
END
*/
}
// END CUT HERE