ADDED SRM/528/2A.cpp Index: SRM/528/2A.cpp ================================================================== --- SRM/528/2A.cpp +++ SRM/528/2A.cpp @@ -0,0 +1,124 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#ifdef __GNUC__ +#include +#define unordered_map __gnu_cxx::hash_map +#else +#include +#endif +using namespace std; +typedef long long LL; +typedef complex CMP; + +class MinCostPalindrome { public: + int getMinimum(string s, int oCost, int xCost) + { + int total = 0; + for(int i=0; i +double start_time; string timer() + { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); } +template ostream& operator<<(ostream& os, const vector& v) + { os << "{ "; + for(typename vector::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(_, MinCostPalindrome().getMinimum(s, oCost, xCost));} +int main(){ + +CASE(0) + string s = "oxo?xox?"; + int oCost = 3; + int xCost = 5; + int _ = 8; +END +CASE(1) + string s = "x??x"; + int oCost = 9; + int xCost = 4; + int _ = 8; +END +CASE(2) + string s = "ooooxxxx"; + int oCost = 12; + int xCost = 34; + int _ = -1; +END +CASE(3) + string s = "oxoxooxxxxooxoxo"; + int oCost = 7; + int xCost = 4; + int _ = 0; +END +CASE(4) + string s = "?o"; + int oCost = 6; + int xCost = 2; + int _ = 6; +END +CASE(5) + string s = "????????????????????"; + int oCost = 50; + int xCost = 49; + int _ = 980; +END +CASE(6) + string s = "o??oxxo?xoox?ox??x??" ; + int oCost = 3; + int xCost = 10; + int _ = 38; +END +/* +CASE(7) + string s = ; + int oCost = ; + int xCost = ; + int _ = ; +END +CASE(8) + string s = ; + int oCost = ; + int xCost = ; + int _ = ; +END +*/ +} +// END CUT HERE