Artifact Content
Not logged in

Artifact 3b1dbfbdda0d225408027105083b946f84957a19


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

template<typename T>
struct DP2
{
	const int N1, N2;
	vector<T> data;
	DP2(int N1, int N2, const T& t = T())
		: N1(N1), N2(N2), data(N1*N2, t) { assert(data.size()*sizeof(T)<(1<<26)); }
	T& operator()(int i1, int i2)
		{ return data[ (i1*N2)+i2 ]; }
	void swap(DP2& rhs)
		{ data.swap(rhs.data); }
};

class MagicalGirl { public:
	double maxExpectation(int M, vector <int> day, vector <int> win, vector <int> gain)
	{
		vector< pair< int, pair<double, int> > > majos;
		for(int i=0; i<day.size(); ++i)
			majos.push_back( make_pair(day[i], make_pair(win[i]/100.0, gain[i])) );
		sort(majos.begin(), majos.end());

		DP2<double> dp(day.size()+1, M+1);
		for(int i=majos.size(); i>=0; --i)
		for(int hp=0; hp<=M; ++hp)
		{
			// Days passed from the last Witch's attack.
			const int days = i==majos.size() ? INT_MAX
			                                 : majos[i].first - (i==0 ? 0 : majos[i-1].first);
			if( hp <= days )
				dp(i, hp) = hp; // no way to gain power any more...
			else {
				const double pWin = majos[i].second.first;
				const int gain = majos[i].second.second;
				dp(i, hp) = days + max(pWin*dp(i+1, min(M, hp-days+gain)), // fight or
				                       dp(i+1, min(M, hp-days))); // skip
			}
		}
		return dp(0, M);
	}
};

// 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(_, MagicalGirl().maxExpectation(M, day, win, gain));}
int main(){

CASE(0)
	int M = 2; 
	int day_[] = {1};
	  vector <int> day(day_, day_+sizeof(day_)/sizeof(*day_)); 
	int win_[] = {75};
	  vector <int> win(win_, win_+sizeof(win_)/sizeof(*win_)); 
	int gain_[] = {1};
	  vector <int> gain(gain_, gain_+sizeof(gain_)/sizeof(*gain_)); 
	double _ = 2.5; 
END
CASE(1)
	int M = 10; 
	int day_[] = {5,5,5,5};
	  vector <int> day(day_, day_+sizeof(day_)/sizeof(*day_)); 
	int win_[] = {100,100,100,100};
	  vector <int> win(win_, win_+sizeof(win_)/sizeof(*win_)); 
	int gain_[] = {1,1,1,1};
	  vector <int> gain(gain_, gain_+sizeof(gain_)/sizeof(*gain_)); 
	double _ = 14.0; 
END
CASE(2)
	int M = 10; 
	int day_[] = {5,5,5,5,5};
	  vector <int> day(day_, day_+sizeof(day_)/sizeof(*day_)); 
	int win_[] = {40,80,60,20,0};
	  vector <int> win(win_, win_+sizeof(win_)/sizeof(*win_)); 
	int gain_[] = {10,10,10,10,10};
	  vector <int> gain(gain_, gain_+sizeof(gain_)/sizeof(*gain_)); 
	double _ = 13.0; 
END
CASE(3)
	int M = 2; 
	int day_[] = {2};
	  vector <int> day(day_, day_+sizeof(day_)/sizeof(*day_)); 
	int win_[] = {100};
	  vector <int> win(win_, win_+sizeof(win_)/sizeof(*win_)); 
	int gain_[] = {2};
	  vector <int> gain(gain_, gain_+sizeof(gain_)/sizeof(*gain_)); 
	double _ = 2.0; 
END
CASE(4)
	int M = 20; 
	int day_[] = {2,13,8,7,9,4,6,21};
	  vector <int> day(day_, day_+sizeof(day_)/sizeof(*day_)); 
	int win_[] = {18,83,75,23,45,23,10,98};
	  vector <int> win(win_, win_+sizeof(win_)/sizeof(*win_)); 
	int gain_[] = {10,9,8,10,7,16,13,20};
	  vector <int> gain(gain_, gain_+sizeof(gain_)/sizeof(*gain_)); 
	double _ = 35.908; 
END
CASE(5)
	int M = 11; 
	int day_[] = {10,20,30,40,50,60,70,80,90};
	  vector <int> day(day_, day_+sizeof(day_)/sizeof(*day_)); 
	int win_[] = {100,100,100,100,100,100,100,100,100};
	  vector <int> win(win_, win_+sizeof(win_)/sizeof(*win_)); 
	int gain_[] = {10,10,10,10,10,10,10,10,10};
	  vector <int> gain(gain_, gain_+sizeof(gain_)/sizeof(*gain_)); 
	double _ = 101.0; 
END
CASE(6)
	int M = 100000; 
	int day_[] = {1000000};
	  vector <int> day(day_, day_+sizeof(day_)/sizeof(*day_)); 
	int win_[] = {100};
	  vector <int> win(win_, win_+sizeof(win_)/sizeof(*win_)); 
	int gain_[] = {100000};
	  vector <int> gain(gain_, gain_+sizeof(gain_)/sizeof(*gain_)); 
	double _ = 100000.0; 
END
/*
CASE(7)
	int M = ; 
	int day_[] = ;
	  vector <int> day(day_, day_+sizeof(day_)/sizeof(*day_)); 
	int win_[] = ;
	  vector <int> win(win_, win_+sizeof(win_)/sizeof(*win_)); 
	int gain_[] = ;
	  vector <int> gain(gain_, gain_+sizeof(gain_)/sizeof(*gain_)); 
	double _ = ; 
END
CASE(8)
	int M = ; 
	int day_[] = ;
	  vector <int> day(day_, day_+sizeof(day_)/sizeof(*day_)); 
	int win_[] = ;
	  vector <int> win(win_, win_+sizeof(win_)/sizeof(*win_)); 
	int gain_[] = ;
	  vector <int> gain(gain_, gain_+sizeof(gain_)/sizeof(*gain_)); 
	double _ = ; 
END
*/
}
// END CUT HERE