Artifact 8b8fcd4c1b87b026a215dd15eec988f9aeb2f577
#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;
static const char* BAD = "XXX";
class AB { public:
map<tuple<int,int,int>, string> memo;
string create(int N, int KPair, int NumB)
{
if(N==0)
return (KPair==0 && NumB==0 ? "" : BAD);
tuple<int,int,int> key(N, KPair, NumB);
if(memo.count(key))
return memo[key];
auto a = create(N-1, KPair-NumB, NumB);
if(a != BAD)
return memo[key] = "A" + a;
if(NumB>=1) {
auto b = create(N-1, KPair, NumB-1);
if(b != BAD)
return memo[key] = "B" + b;
}
return memo[key] = BAD;
}
string createString(int N, int K)
{
for(int NumB=0; NumB<=N; ++NumB) {
auto s = create(N, K, NumB);
if(s != BAD)
return s;
}
return "";
}
};
// 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(_, AB().createString(N, K));}
int main(){
CASE(0)
int N = 3;
int K = 2;
string _ = "ABB";
END
CASE(1)
int N = 2;
int K = 0;
string _ = "BA";
END
CASE(2)
int N = 5;
int K = 8;
string _ = "";
END
CASE(3)
int N = 10;
int K = 12;
string _ = "BAABBABAAB";
END
/*
CASE(4)
int N = ;
int K = ;
string _ = ;
END
CASE(5)
int N = ;
int K = ;
string _ = ;
END
*/
}
// END CUT HERE