ADDED SRM/533-U/2A.cpp Index: SRM/533-U/2A.cpp ================================================================== --- SRM/533-U/2A.cpp +++ SRM/533-U/2A.cpp @@ -0,0 +1,101 @@ +#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 PikachuEasy { public: + string check(string word) + { + string zz[] = {"pi", "ka", "chu"}; + while(!word.empty()) + { + for(int i=0; i<3; ++i) + if( word.size()>=zz[i].size() && word.substr(0,zz[i].size())==zz[i] ) { + word = word.substr(zz[i].size()); + goto next; + } + return "NO"; + next:; + } + return "YES"; + } +}; + +// BEGIN CUT HERE +#include +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 string& Expected, const string& 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(_, PikachuEasy().check(word));} +int main(){ + +CASE(0) + string word = "pikapi"; + string _ = "YES"; +END +CASE(1) + string word = "pipikachu"; + string _ = "YES"; +END +CASE(2) + string word = "pikaqiu"; + string _ = "NO"; +END +CASE(3) + string word = "topcoder"; + string _ = "NO"; +END +CASE(4) + string word = "piika"; + string _ = "NO"; +END +CASE(5) + string word = "chupikachupipichu"; + string _ = "YES"; +END +CASE(6) + string word = "pikapipachu"; + string _ = "NO"; +END +/* +CASE(7) + string word = ; + string _ = ; +END +CASE(8) + string word = ; + string _ = ; +END +*/ +} +// END CUT HERE ADDED SRM/533-U/2C.cpp Index: SRM/533-U/2C.cpp ================================================================== --- SRM/533-U/2C.cpp +++ SRM/533-U/2C.cpp @@ -0,0 +1,178 @@ +#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; + +template +struct DP2 +{ + const int N1, N2; + vector 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 day, vector win, vector gain) + { + vector< pair< int, pair > > majos; + for(int i=0; i 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 +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 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 day(day_, day_+sizeof(day_)/sizeof(*day_)); + int win_[] = {75}; + vector win(win_, win_+sizeof(win_)/sizeof(*win_)); + int gain_[] = {1}; + vector gain(gain_, gain_+sizeof(gain_)/sizeof(*gain_)); + double _ = 2.5; +END +CASE(1) + int M = 10; + int day_[] = {5,5,5,5}; + vector day(day_, day_+sizeof(day_)/sizeof(*day_)); + int win_[] = {100,100,100,100}; + vector win(win_, win_+sizeof(win_)/sizeof(*win_)); + int gain_[] = {1,1,1,1}; + vector gain(gain_, gain_+sizeof(gain_)/sizeof(*gain_)); + double _ = 14.0; +END +CASE(2) + int M = 10; + int day_[] = {5,5,5,5,5}; + vector day(day_, day_+sizeof(day_)/sizeof(*day_)); + int win_[] = {40,80,60,20,0}; + vector win(win_, win_+sizeof(win_)/sizeof(*win_)); + int gain_[] = {10,10,10,10,10}; + vector gain(gain_, gain_+sizeof(gain_)/sizeof(*gain_)); + double _ = 13.0; +END +CASE(3) + int M = 2; + int day_[] = {2}; + vector day(day_, day_+sizeof(day_)/sizeof(*day_)); + int win_[] = {100}; + vector win(win_, win_+sizeof(win_)/sizeof(*win_)); + int gain_[] = {2}; + vector 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 day(day_, day_+sizeof(day_)/sizeof(*day_)); + int win_[] = {18,83,75,23,45,23,10,98}; + vector win(win_, win_+sizeof(win_)/sizeof(*win_)); + int gain_[] = {10,9,8,10,7,16,13,20}; + vector 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 day(day_, day_+sizeof(day_)/sizeof(*day_)); + int win_[] = {100,100,100,100,100,100,100,100,100}; + vector win(win_, win_+sizeof(win_)/sizeof(*win_)); + int gain_[] = {10,10,10,10,10,10,10,10,10}; + vector gain(gain_, gain_+sizeof(gain_)/sizeof(*gain_)); + double _ = 101.0; +END +CASE(6) + int M = 100000; + int day_[] = {1000000}; + vector day(day_, day_+sizeof(day_)/sizeof(*day_)); + int win_[] = {100}; + vector win(win_, win_+sizeof(win_)/sizeof(*win_)); + int gain_[] = {100000}; + vector gain(gain_, gain_+sizeof(gain_)/sizeof(*gain_)); + double _ = 100000.0; +END +/* +CASE(7) + int M = ; + int day_[] = ; + vector day(day_, day_+sizeof(day_)/sizeof(*day_)); + int win_[] = ; + vector win(win_, win_+sizeof(win_)/sizeof(*win_)); + int gain_[] = ; + vector gain(gain_, gain_+sizeof(gain_)/sizeof(*gain_)); + double _ = ; +END +CASE(8) + int M = ; + int day_[] = ; + vector day(day_, day_+sizeof(day_)/sizeof(*day_)); + int win_[] = ; + vector win(win_, win_+sizeof(win_)/sizeof(*win_)); + int gain_[] = ; + vector gain(gain_, gain_+sizeof(gain_)/sizeof(*gain_)); + double _ = ; +END +*/ +} +// END CUT HERE