Artifact Content
Not logged in

Artifact 294b894277ee8322a2473f30483522080c6fc1da


#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 <cstring>
#ifdef __GNUC__
#include <ext/hash_map>
#define unordered_map __gnu_cxx::hash_map
#else
#include <unordered_map>
#endif
using namespace std;
typedef long long LL;
typedef complex<double> CMP;

class MinCostPalindrome { public:
	int getMinimum(string s, int oCost, int xCost)
	{
		int total = 0;
		for(int i=0; i<s.size()-i-1; ++i)
			if( s[i]=='o' && s[s.size()-i-1]=='x' )
				return -1;
			else if( s[i]=='x' && s[s.size()-i-1]=='o' )
				return -1;
			else if( s[i]=='o' && s[s.size()-i-1]=='?'
				  || s[i]=='?' && s[s.size()-i-1]=='o' )
				total += oCost;
			else if( s[i]=='x' && s[s.size()-i-1]=='?'
				  || s[i]=='?' && s[s.size()-i-1]=='x' )
				total += xCost;
			else if( s[i]=='?' && s[s.size()-i-1]=='?' )
				total += min(oCost, xCost) * 2;
		if( s.size()%2 == 1 && s[s.size()/2]=='?' )
			total += min(oCost, xCost);
		return total;
	}
};

// 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(_, 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