ADDED SRM/549-U/1A.cpp Index: SRM/549-U/1A.cpp ================================================================== --- SRM/549-U/1A.cpp +++ SRM/549-U/1A.cpp @@ -0,0 +1,204 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; +typedef long long LL; +typedef long double LD; +typedef complex CMP; + +typedef int vert; +typedef vert edge; +typedef vector edges; +typedef vector graph; + +bool augment( graph& G, int v, vector& matchTo, bool visited[] ) +{ + for(int i=0; i +int biMatch( graph& G, int L ) // [0,L):left, [L,?):right +{ + vector matchTo(G.size(), -1); + int ans = 0; + for(vert v=0; v topHeight, vector topRadius, vector bottomHeight, vector bottomRadius) + { + int L = topHeight.size(); + int R = bottomHeight.size(); + graph G(L+R); + for(int i=0; i(G, L); + } + + bool ok(int th, int tr, int bh, int br) + { + if( th*br > bh*tr ) { + return br > tr; + } + return false; + } +}; + +// 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 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(_, PointyWizardHats().getNumHats(topHeight, topRadius, bottomHeight, bottomRadius));} +int main(){ + +CASE(0) + int topHeight_[] = {30}; + vector topHeight(topHeight_, topHeight_+sizeof(topHeight_)/sizeof(*topHeight_)); + int topRadius_[] = {3}; + vector topRadius(topRadius_, topRadius_+sizeof(topRadius_)/sizeof(*topRadius_)); + int bottomHeight_[] = {3}; + vector bottomHeight(bottomHeight_, bottomHeight_+sizeof(bottomHeight_)/sizeof(*bottomHeight_)); + int bottomRadius_[] = {30}; + vector bottomRadius(bottomRadius_, bottomRadius_+sizeof(bottomRadius_)/sizeof(*bottomRadius_)); + int _ = 1; +END +CASE(1) + int topHeight_[] = {4,4}; + vector topHeight(topHeight_, topHeight_+sizeof(topHeight_)/sizeof(*topHeight_)); + int topRadius_[] = {4,3}; + vector topRadius(topRadius_, topRadius_+sizeof(topRadius_)/sizeof(*topRadius_)); + int bottomHeight_[] = {5,12}; + vector bottomHeight(bottomHeight_, bottomHeight_+sizeof(bottomHeight_)/sizeof(*bottomHeight_)); + int bottomRadius_[] = {5,4}; + vector bottomRadius(bottomRadius_, bottomRadius_+sizeof(bottomRadius_)/sizeof(*bottomRadius_)); + int _ = 1; +END +CASE(2) + int topHeight_[] = {3}; + vector topHeight(topHeight_, topHeight_+sizeof(topHeight_)/sizeof(*topHeight_)); + int topRadius_[] = {3}; + vector topRadius(topRadius_, topRadius_+sizeof(topRadius_)/sizeof(*topRadius_)); + int bottomHeight_[] = {1,1}; + vector bottomHeight(bottomHeight_, bottomHeight_+sizeof(bottomHeight_)/sizeof(*bottomHeight_)); + int bottomRadius_[] = {2,4}; + vector bottomRadius(bottomRadius_, bottomRadius_+sizeof(bottomRadius_)/sizeof(*bottomRadius_)); + int _ = 1; +END +CASE(3) + int topHeight_[] = {10,10}; + vector topHeight(topHeight_, topHeight_+sizeof(topHeight_)/sizeof(*topHeight_)); + int topRadius_[] = {2,5}; + vector topRadius(topRadius_, topRadius_+sizeof(topRadius_)/sizeof(*topRadius_)); + int bottomHeight_[] = {2,9}; + vector bottomHeight(bottomHeight_, bottomHeight_+sizeof(bottomHeight_)/sizeof(*bottomHeight_)); + int bottomRadius_[] = {3,6}; + vector bottomRadius(bottomRadius_, bottomRadius_+sizeof(bottomRadius_)/sizeof(*bottomRadius_)); + int _ = 2; +END +CASE(4) + int topHeight_[] = {3,4,5}; + vector topHeight(topHeight_, topHeight_+sizeof(topHeight_)/sizeof(*topHeight_)); + int topRadius_[] = {5,4,3}; + vector topRadius(topRadius_, topRadius_+sizeof(topRadius_)/sizeof(*topRadius_)); + int bottomHeight_[] = {3,4,5}; + vector bottomHeight(bottomHeight_, bottomHeight_+sizeof(bottomHeight_)/sizeof(*bottomHeight_)); + int bottomRadius_[] = {3,8,5}; + vector bottomRadius(bottomRadius_, bottomRadius_+sizeof(bottomRadius_)/sizeof(*bottomRadius_)); + int _ = 2; +END +CASE(5) + int topHeight_[] = {1,2,3,4,5}; + vector topHeight(topHeight_, topHeight_+sizeof(topHeight_)/sizeof(*topHeight_)); + int topRadius_[] = {2,3,4,5,6}; + vector topRadius(topRadius_, topRadius_+sizeof(topRadius_)/sizeof(*topRadius_)); + int bottomHeight_[] = {2,3,4,5,6}; + vector bottomHeight(bottomHeight_, bottomHeight_+sizeof(bottomHeight_)/sizeof(*bottomHeight_)); + int bottomRadius_[] = {1,2,3,4,5}; + vector bottomRadius(bottomRadius_, bottomRadius_+sizeof(bottomRadius_)/sizeof(*bottomRadius_)); + int _ = 0; +END +CASE(6) + int topHeight_[] = {123,214,232,323,342,343}; + vector topHeight(topHeight_, topHeight_+sizeof(topHeight_)/sizeof(*topHeight_)); + int topRadius_[] = {123,123,232,123,323,434}; + vector topRadius(topRadius_, topRadius_+sizeof(topRadius_)/sizeof(*topRadius_)); + int bottomHeight_[] = {545,322,123,545,777,999}; + vector bottomHeight(bottomHeight_, bottomHeight_+sizeof(bottomHeight_)/sizeof(*bottomHeight_)); + int bottomRadius_[] = {323,443,123,656,767,888}; + vector bottomRadius(bottomRadius_, bottomRadius_+sizeof(bottomRadius_)/sizeof(*bottomRadius_)); + int _ = 5; +END +CASE(7) + int topHeight_[] = {999,999,999,10000,10000,10000}; + vector topHeight(topHeight_, topHeight_+sizeof(topHeight_)/sizeof(*topHeight_)); + int topRadius_[] = {10000,10000,10000,1,2,3}; + vector topRadius(topRadius_, topRadius_+sizeof(topRadius_)/sizeof(*topRadius_)); + int bottomHeight_[] = {2324,2323,234,5454,323,232}; + vector bottomHeight(bottomHeight_, bottomHeight_+sizeof(bottomHeight_)/sizeof(*bottomHeight_)); + int bottomRadius_[] = {1,2,3222,434,5454,23}; + vector bottomRadius(bottomRadius_, bottomRadius_+sizeof(bottomRadius_)/sizeof(*bottomRadius_)); + int _ = 3; +END +/* +CASE(8) + int topHeight_[] = ; + vector topHeight(topHeight_, topHeight_+sizeof(topHeight_)/sizeof(*topHeight_)); + int topRadius_[] = ; + vector topRadius(topRadius_, topRadius_+sizeof(topRadius_)/sizeof(*topRadius_)); + int bottomHeight_[] = ; + vector bottomHeight(bottomHeight_, bottomHeight_+sizeof(bottomHeight_)/sizeof(*bottomHeight_)); + int bottomRadius_[] = ; + vector bottomRadius(bottomRadius_, bottomRadius_+sizeof(bottomRadius_)/sizeof(*bottomRadius_)); + int _ = ; +END +CASE(9) + int topHeight_[] = ; + vector topHeight(topHeight_, topHeight_+sizeof(topHeight_)/sizeof(*topHeight_)); + int topRadius_[] = ; + vector topRadius(topRadius_, topRadius_+sizeof(topRadius_)/sizeof(*topRadius_)); + int bottomHeight_[] = ; + vector bottomHeight(bottomHeight_, bottomHeight_+sizeof(bottomHeight_)/sizeof(*bottomHeight_)); + int bottomRadius_[] = ; + vector bottomRadius(bottomRadius_, bottomRadius_+sizeof(bottomRadius_)/sizeof(*bottomRadius_)); + int _ = ; +END +*/ +} +// END CUT HERE ADDED SRM/549-U/1B.cpp Index: SRM/549-U/1B.cpp ================================================================== --- SRM/549-U/1B.cpp +++ SRM/549-U/1B.cpp @@ -0,0 +1,265 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; +typedef long long LL; +typedef long double LD; +typedef complex CMP; + +class MagicalHats { public: + int NC, NH, H, W, NG; + vector gain; + vector< pair > hats; + vector tate_base, yoko_base; + + int findMaximumReward(vector board, vector coins, int numGuesses) + { + NC = coins.size(); + sort(coins.begin(), coins.end()); + gain.assign(NC+1, 0); + partial_sum(coins.begin(), coins.end(), gain.begin()+1); + + H = board.size(); + W = board[0].size(); + hats.clear(); + tate_base.resize(W); + yoko_base.resize(H); + for(int y=0; y p_memo; + vector p_memo_set; + bool is_possible(int state) + { + if(p_memo_set[state]) + return p_memo[state]; + p_memo_set[state] = true; + + vector yoko = yoko_base, tate = tate_base, next; + int cnt = 0; + for(int i=0,m=1; i b_memo; + vector b_memo_set; + char best_num(int state, int guess) + { + if( guess==0 ) + return 0; + if(b_memo_set[state]) + return b_memo[state]; + b_memo_set[state] = true; + + char best = 0; + for(int i=0,m=1; i(score, best_num(s[1], guess-1)+1); + best = max(best, score); + } + } + return b_memo[state] = best; + } +}; + +// 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 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(_, MagicalHats().findMaximumReward(board, coins, numGuesses));} +int main(){ + +CASE(0) + string board_[] = {"H"}; + vector board(board_, board_+sizeof(board_)/sizeof(*board_)); + int coins_[] = {1}; + vector coins(coins_, coins_+sizeof(coins_)/sizeof(*coins_)); + int numGuesses = 1; + int _ = 1; +END +CASE(1) + string board_[] = {"HHH", + "H.H", + "HH."}; + vector board(board_, board_+sizeof(board_)/sizeof(*board_)); + int coins_[] = {9}; + vector coins(coins_, coins_+sizeof(coins_)/sizeof(*coins_)); + int numGuesses = 1; + int _ = 9; +END +CASE(2) + string board_[] = {"HH", + "HH"}; + vector board(board_, board_+sizeof(board_)/sizeof(*board_)); + int coins_[] = {1,2,3,4}; + vector coins(coins_, coins_+sizeof(coins_)/sizeof(*coins_)); + int numGuesses = 3; + int _ = 6; +END +CASE(3) + string board_[] = {"HHH", + "HHH", + "H.H"}; + vector board(board_, board_+sizeof(board_)/sizeof(*board_)); + int coins_[] = {13,13,13,13}; + vector coins(coins_, coins_+sizeof(coins_)/sizeof(*coins_)); + int numGuesses = 2; + int _ = 13; +END +CASE(4) + string board_[] = {"HHH", + "HHH", + "H.H"}; + vector board(board_, board_+sizeof(board_)/sizeof(*board_)); + int coins_[] = {13,13,13,13}; + vector coins(coins_, coins_+sizeof(coins_)/sizeof(*coins_)); + int numGuesses = 3; + int _ = 26; +END +CASE(5) + string board_[] = {"H.H.", + ".H.H", + "H.H."}; + vector board(board_, board_+sizeof(board_)/sizeof(*board_)); + int coins_[] = {17}; + vector coins(coins_, coins_+sizeof(coins_)/sizeof(*coins_)); + int numGuesses = 6; + int _ = -1; +END +CASE(6) + string board_[] = {"HHH..........", + "H.H..........", + "HHH..........", + "H.H..........", + "HHH.........." +".............", +".............", +".............", +".............", +".............", +".............", +".............", +".............", +}; + vector board(board_, board_+sizeof(board_)/sizeof(*board_)); + int coins_[] = {33,337,1007,2403,5601,6003,9999}; + vector coins(coins_, coins_+sizeof(coins_)/sizeof(*coins_)); + int numGuesses = 5; + int _ = 1377; +END +CASE(7) + string board_[] = {".............", + ".............", + ".............", + ".............", + ".............", + ".............", + ".....H.H.....", + "......H......", + ".....H.H.....", + ".............", + ".............", + ".............", + "............."}; + vector board(board_, board_+sizeof(board_)/sizeof(*board_)); + int coins_[] = {22}; + vector coins(coins_, coins_+sizeof(coins_)/sizeof(*coins_)); + int numGuesses = 3; + int _ = 22; +END +/* +CASE(8) + string board_[] = ; + vector board(board_, board_+sizeof(board_)/sizeof(*board_)); + int coins_[] = ; + vector coins(coins_, coins_+sizeof(coins_)/sizeof(*coins_)); + int numGuesses = ; + int _ = ; +END +CASE(9) + string board_[] = ; + vector board(board_, board_+sizeof(board_)/sizeof(*board_)); + int coins_[] = ; + vector coins(coins_, coins_+sizeof(coins_)/sizeof(*coins_)); + int numGuesses = ; + int _ = ; +END +*/ +} +// END CUT HERE