Artifact Content
Not logged in

Artifact b64dedb5d55d1caf52577b4dfc6f93e5a88ea099


#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;

class SquareScores { public:
	double calcexpectation(vector <int> p, string s)
	{
		double ans = 0.0;
		for(int k=0; k<s.size(); ++k) {
			int num_q = 0;
			char ch = '*';
			for(int e=k; e<s.size(); ++e) {
				if(s[e]=='?')
					num_q++;
				if(ch == '*') {
					if(s[e] != '?')
						ch = s[e];
				} else {
					if(s[e] != '?' && s[e] != ch)
						break;
				}

				for(int ci=0; ci<p.size(); ++ci)
					if(ch=='*' || ch-'a'==ci)
						ans += pow(p[ci]/100.0, num_q);
			}
		}
		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 double& Expected, const double& Received) {
 bool ok = (abs(Expected - Received) < 1e-9);
 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(_, SquareScores().calcexpectation(p, s));}
int main(){

CASE(0)
	int p_[] = {1, 99};
	  vector <int> p(p_, p_+sizeof(p_)/sizeof(*p_)); 
	string s = "aaaba"; 
	double _ = 8.0; 
END
CASE(1)
	int p_[] = {10, 20, 70};
	  vector <int> p(p_, p_+sizeof(p_)/sizeof(*p_)); 
	string s = "aa?bbbb"; 
	double _ = 15.0; 
END
CASE(2)
	int p_[] = {10, 20, 30, 40};
	  vector <int> p(p_, p_+sizeof(p_)/sizeof(*p_)); 
	string s = "a??c?dc?b"; 
	double _ = 11.117; 
END
CASE(3)
	int p_[] = {25, 25, 21, 2, 2, 25};
	  vector <int> p(p_, p_+sizeof(p_)/sizeof(*p_)); 
	string s = "a??b???????ff??e"; 
	double _ = 21.68512690712425; 
END
CASE(4)
	int p_[] = {4, 4, 4, 3, 4, 4, 4, 4, 4, 4, 3, 4, 4, 4, 3, 4, 4, 4, 4, 4, 4, 4, 3, 4, 4, 4};
	  vector <int> p(p_, p_+sizeof(p_)/sizeof(*p_)); 
	string s = "??????????????????????????????"; 
	double _ = 31.16931963781721; 
END
CASE(5)
	int p_[] = {4, 3, 4, 3, 8, 2, 4, 3, 4, 4, 3, 2, 4, 4, 3, 4, 2, 4, 7, 6, 4, 4, 3, 4, 4, 3};
	  vector <int> p(p_, p_+sizeof(p_)/sizeof(*p_)); 
	string s = "makigotapresentfromniko"; 
	double _ = 23.0; 
END
/*
CASE(6)
	int p_[] = ;
	  vector <int> p(p_, p_+sizeof(p_)/sizeof(*p_)); 
	string s = ; 
	double _ = ; 
END
CASE(7)
	int p_[] = ;
	  vector <int> p(p_, p_+sizeof(p_)/sizeof(*p_)); 
	string s = ; 
	double _ = ; 
END
*/
}
// END CUT HERE