Artifact c9dd78f697e51c5a2e453e474b047fdad105af83
#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;
class Stamp { public:
int getMinimumCost(string desiredColor, int stampCost, int pushCost)
{
const int N = desiredColor.size();
int best = 0x7fffffff;
for(int L=1; L<=N; ++L) {
vector<int> dp(N+1, 999);
dp[0] = 0;
for(int e=1; e<=N; ++e) {
set<char> colors;
for(int s=e-1; s>=0; --s) {
if(desiredColor[s] != '*')
colors.insert(desiredColor[s]);
if(colors.size()<=1 && e-s>=L) {
int nPush = (e-s+L-1)/L;
dp[e] = min(dp[e], dp[s]+nPush);
}
}
}
best = min(best, L*stampCost + dp[N]*pushCost);
}
return best;
}
};
// 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(_, Stamp().getMinimumCost(desiredColor, stampCost, pushCost));}
int main(){
CASE(0)
string desiredColor = "RRGGBB";
int stampCost = 1;
int pushCost = 1;
int _ = 5;
END
CASE(1)
string desiredColor = "R**GB*";
int stampCost = 1;
int pushCost = 1;
int _ = 5;
END
CASE(2)
string desiredColor = "BRRB";
int stampCost = 2;
int pushCost = 7;
int _ = 30;
END
CASE(3)
string desiredColor = "R*RR*GG";
int stampCost = 10;
int pushCost = 58;
int _ = 204;
END
CASE(4)
string desiredColor = "*B**B**B*BB*G*BBB**B**B*";
int stampCost = 5;
int pushCost = 2;
int _ = 33;
END
CASE(5)
string desiredColor = "*R*RG*G*GR*RGG*G*GGR***RR*GG";
int stampCost = 7;
int pushCost = 1;
int _ = 30;
END
/*
CASE(6)
string desiredColor = ;
int stampCost = ;
int pushCost = ;
int _ = ;
END
CASE(7)
string desiredColor = ;
int stampCost = ;
int pushCost = ;
int _ = ;
END
*/
}
// END CUT HERE