ADDED SRM/580-U/1A.cpp Index: SRM/580-U/1A.cpp ================================================================== --- SRM/580-U/1A.cpp +++ SRM/580-U/1A.cpp @@ -0,0 +1,111 @@ +#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 EelAndRabbit { public: + int getmax(vector l, vector t) + { + const int N = l.size(); + + vector ps; + for(int i=0; i +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(_, EelAndRabbit().getmax(l, t));} +int main(){ + +CASE(0) + int l_[] = {2, 4, 3, 2, 2, 1, 10}; + vector l(l_, l_+sizeof(l_)/sizeof(*l_)); + int t_[] = {2, 6, 3, 7, 0, 2, 0}; + vector t(t_, t_+sizeof(t_)/sizeof(*t_)); + int _ = 6; +END +CASE(1) + int l_[] = {1, 1, 1}; + vector l(l_, l_+sizeof(l_)/sizeof(*l_)); + int t_[] = {2, 0, 4}; + vector t(t_, t_+sizeof(t_)/sizeof(*t_)); + int _ = 2; +END +CASE(2) + int l_[] = {1}; + vector l(l_, l_+sizeof(l_)/sizeof(*l_)); + int t_[] = {1}; + vector t(t_, t_+sizeof(t_)/sizeof(*t_)); + int _ = 1; +END +CASE(3) + int l_[] = {8, 2, 1, 10, 8, 6, 3, 1, 2, 5}; + vector l(l_, l_+sizeof(l_)/sizeof(*l_)); + int t_[] = {17, 27, 26, 11, 1, 27, 23, 12, 11, 13}; + vector t(t_, t_+sizeof(t_)/sizeof(*t_)); + int _ = 7; +END +/* +CASE(4) + int l_[] = ; + vector l(l_, l_+sizeof(l_)/sizeof(*l_)); + int t_[] = ; + vector t(t_, t_+sizeof(t_)/sizeof(*t_)); + int _ = ; +END +CASE(5) + int l_[] = ; + vector l(l_, l_+sizeof(l_)/sizeof(*l_)); + int t_[] = ; + vector t(t_, t_+sizeof(t_)/sizeof(*t_)); + int _ = ; +END +*/ +} +// END CUT HERE ADDED SRM/580-U/1B.cpp Index: SRM/580-U/1B.cpp ================================================================== --- SRM/580-U/1B.cpp +++ SRM/580-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 ShoutterDiv1 { public: + int count(vector s1000, vector s100, vector s10, vector s1, vector t1000, vector t100, vector t10, vector t1) + { + vector s; + { + string S1000 = accumulate(s1000.begin(), s1000.end(), string()); + string S100 = accumulate(s100.begin() , s100.end() , string()); + string S10 = accumulate(s10.begin() , s10.end() , string()); + string S1 = accumulate(s1.begin() , s1.end() , string()); + for(int i=0; i t; + { + string T1000 = accumulate(t1000.begin(), t1000.end(), string()); + string T100 = accumulate(t100.begin(), t100.end(), string()); + string T10 = accumulate(t10.begin(), t10.end(), string()); + string T1 = accumulate(t1.begin(), t1.end(), string()); + for(int i=0; i > st; + for(int i=0; i >& st) + { + const int N = st.size(); + + int L = 99999; // the time first rabbit leaves. + int R = 0; // the time last rabbit comes. + for(int i=0; i >& st, int N, int I, int L, int R) + { + bool I_used = false; + int covered = L; + int used = 0; + for(int ks=0; ks +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(_, ShoutterDiv1().count(s1000, s100, s10, s1, t1000, t100, t10, t1));} +int main(){ + +CASE(0) + string s1000_[] = {"22", "2"}; + vector s1000(s1000_, s1000_+sizeof(s1000_)/sizeof(*s1000_)); + string s100_[] = {"00", "0"}; + vector s100(s100_, s100_+sizeof(s100_)/sizeof(*s100_)); + string s10_[] = {"11", "1"}; + vector s10(s10_, s10_+sizeof(s10_)/sizeof(*s10_)); + string s1_[] = {"21", "4"}; + vector s1(s1_, s1_+sizeof(s1_)/sizeof(*s1_)); + string t1000_[] = {"22", "2"}; + vector t1000(t1000_, t1000_+sizeof(t1000_)/sizeof(*t1000_)); + string t100_[] = {"00", "0"}; + vector t100(t100_, t100_+sizeof(t100_)/sizeof(*t100_)); + string t10_[] = {"11", "1"}; + vector t10(t10_, t10_+sizeof(t10_)/sizeof(*t10_)); + string t1_[] = {"43", "6"}; + vector t1(t1_, t1_+sizeof(t1_)/sizeof(*t1_)); + int _ = 2; +END +CASE(1) + string s1000_[] = {"00"}; + vector s1000(s1000_, s1000_+sizeof(s1000_)/sizeof(*s1000_)); + string s100_[] = {"00"}; + vector s100(s100_, s100_+sizeof(s100_)/sizeof(*s100_)); + string s10_[] = {"00"}; + vector s10(s10_, s10_+sizeof(s10_)/sizeof(*s10_)); + string s1_[] = {"13"}; + vector s1(s1_, s1_+sizeof(s1_)/sizeof(*s1_)); + string t1000_[] = {"00"}; + vector t1000(t1000_, t1000_+sizeof(t1000_)/sizeof(*t1000_)); + string t100_[] = {"00"}; + vector t100(t100_, t100_+sizeof(t100_)/sizeof(*t100_)); + string t10_[] = {"00"}; + vector t10(t10_, t10_+sizeof(t10_)/sizeof(*t10_)); + string t1_[] = {"24"}; + vector t1(t1_, t1_+sizeof(t1_)/sizeof(*t1_)); + int _ = -1; +END +CASE(2) + string s1000_[] = {"0000"}; + vector s1000(s1000_, s1000_+sizeof(s1000_)/sizeof(*s1000_)); + string s100_[] = {"0000"}; + vector s100(s100_, s100_+sizeof(s100_)/sizeof(*s100_)); + string s10_[] = {"0000"}; + vector s10(s10_, s10_+sizeof(s10_)/sizeof(*s10_)); + string s1_[] = {"1234"}; + vector s1(s1_, s1_+sizeof(s1_)/sizeof(*s1_)); + string t1000_[] = {"0000"}; + vector t1000(t1000_, t1000_+sizeof(t1000_)/sizeof(*t1000_)); + string t100_[] = {"0000"}; + vector t100(t100_, t100_+sizeof(t100_)/sizeof(*t100_)); + string t10_[] = {"0000"}; + vector t10(t10_, t10_+sizeof(t10_)/sizeof(*t10_)); + string t1_[] = {"2345"}; + vector t1(t1_, t1_+sizeof(t1_)/sizeof(*t1_)); + int _ = 6; +END +CASE(3) + string s1000_[] = {"0000000000"}; + vector s1000(s1000_, s1000_+sizeof(s1000_)/sizeof(*s1000_)); + string s100_[] = {"0000000000"}; + vector s100(s100_, s100_+sizeof(s100_)/sizeof(*s100_)); + string s10_[] = {"0000000000"}; + vector s10(s10_, s10_+sizeof(s10_)/sizeof(*s10_)); + string s1_[] = {"7626463146"}; + vector s1(s1_, s1_+sizeof(s1_)/sizeof(*s1_)); + string t1000_[] = {"0000000000"}; + vector t1000(t1000_, t1000_+sizeof(t1000_)/sizeof(*t1000_)); + string t100_[] = {"0000000000"}; + vector t100(t100_, t100_+sizeof(t100_)/sizeof(*t100_)); + string t10_[] = {"0000000000"}; + vector t10(t10_, t10_+sizeof(t10_)/sizeof(*t10_)); + string t1_[] = {"9927686479"}; + vector t1(t1_, t1_+sizeof(t1_)/sizeof(*t1_)); + int _ = 18; +END +CASE(4) + string s1000_[] = {"00000000000000000000000000000000000000000000000000"}; + vector s1000(s1000_, s1000_+sizeof(s1000_)/sizeof(*s1000_)); + string s100_[] = {"00000000000000000000000000000000000000000000000000"}; + vector s100(s100_, s100_+sizeof(s100_)/sizeof(*s100_)); + string s10_[] = {"50353624751857130208544645495168271486083954769538"}; + vector s10(s10_, s10_+sizeof(s10_)/sizeof(*s10_)); + string s1_[] = {"85748487990028258641117783760944852941545064635928"}; + vector s1(s1_, s1_+sizeof(s1_)/sizeof(*s1_)); + string t1000_[] = {"00000000000000000000000000000000000000000000000000"}; + vector t1000(t1000_, t1000_+sizeof(t1000_)/sizeof(*t1000_)); + string t100_[] = {"00000000000000000000000000000000000000000000000000"}; + vector t100(t100_, t100_+sizeof(t100_)/sizeof(*t100_)); + string t10_[] = {"61465744851859252308555855596388482696094965779649"}; + vector t10(t10_, t10_+sizeof(t10_)/sizeof(*t10_)); + string t1_[] = {"37620749792666153778227385275518278477865684777411"}; + vector t1(t1_, t1_+sizeof(t1_)/sizeof(*t1_)); + int _ = 333; +END +/* +CASE(5) + string s1000_[] = ; + vector s1000(s1000_, s1000_+sizeof(s1000_)/sizeof(*s1000_)); + string s100_[] = ; + vector s100(s100_, s100_+sizeof(s100_)/sizeof(*s100_)); + string s10_[] = ; + vector s10(s10_, s10_+sizeof(s10_)/sizeof(*s10_)); + string s1_[] = ; + vector s1(s1_, s1_+sizeof(s1_)/sizeof(*s1_)); + string t1000_[] = ; + vector t1000(t1000_, t1000_+sizeof(t1000_)/sizeof(*t1000_)); + string t100_[] = ; + vector t100(t100_, t100_+sizeof(t100_)/sizeof(*t100_)); + string t10_[] = ; + vector t10(t10_, t10_+sizeof(t10_)/sizeof(*t10_)); + string t1_[] = ; + vector t1(t1_, t1_+sizeof(t1_)/sizeof(*t1_)); + int _ = ; +END +CASE(6) + string s1000_[] = ; + vector s1000(s1000_, s1000_+sizeof(s1000_)/sizeof(*s1000_)); + string s100_[] = ; + vector s100(s100_, s100_+sizeof(s100_)/sizeof(*s100_)); + string s10_[] = ; + vector s10(s10_, s10_+sizeof(s10_)/sizeof(*s10_)); + string s1_[] = ; + vector s1(s1_, s1_+sizeof(s1_)/sizeof(*s1_)); + string t1000_[] = ; + vector t1000(t1000_, t1000_+sizeof(t1000_)/sizeof(*t1000_)); + string t100_[] = ; + vector t100(t100_, t100_+sizeof(t100_)/sizeof(*t100_)); + string t10_[] = ; + vector t10(t10_, t10_+sizeof(t10_)/sizeof(*t10_)); + string t1_[] = ; + vector t1(t1_, t1_+sizeof(t1_)/sizeof(*t1_)); + int _ = ; +END +*/ +} +// END CUT HERE ADDED SRM/580-U/1C-U.cpp Index: SRM/580-U/1C-U.cpp ================================================================== --- SRM/580-U/1C-U.cpp +++ SRM/580-U/1C-U.cpp @@ -0,0 +1,159 @@ +#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 WallGameDiv1 { public: + int play(vector costs) + { + int H = costs.size(); + int W = costs[0].size(); + vector > C(H, vector(W)); + for(int y=0; y > dp(H, vector(W)); + for(int x=0; x=0; --y) + for(int x=0; x CC = C[y], DD = dp[y+1]; + reverse(CC.begin(), CC.end()); + reverse(DD.begin(), DD.end()); + int ri = lefty(CC, DD, W-1-x); + + if(min(le, ri) < dp[y+1][x]) + dp[y][x] = C[y][x] + dp[y+1][x]; + else + dp[y][x] = C[y][x] + min(le, ri); + // no blocking score + vector s = dp[y+1]; + s[x] += C[y][x]; + for(int p=C[y][x], xx=x-1; xx>=0; --xx) + s[xx] += (p += C[y][xx]); + for(int p=C[y][x], xx=x+1; xx& cur, const vector& down, const int S) + { + // best score when moved to left from S first; + return -1; + } +}; + +// 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(_, WallGameDiv1().play(costs));} +int main(){ + +CASE(0) + string costs_[] = {"12" +,"34"}; + vector costs(costs_, costs_+sizeof(costs_)/sizeof(*costs_)); + int _ = 6; +END +CASE(1) + string costs_[] = {"99999" +,"99999" +,"99999"}; + vector costs(costs_, costs_+sizeof(costs_)/sizeof(*costs_)); + int _ = 99; +END +CASE(2) + string costs_[] = {"11111" +,"90005"}; + vector costs(costs_, costs_+sizeof(costs_)/sizeof(*costs_)); + int _ = 10; +END +CASE(3) + string costs_[] = {"4417231387449337370319219832088987579792" +,"3117295688208899006196193430472892512797" +,"0835796222361526836944954410684516919758" +,"1988200069973565052900745230547016216225" +,"8080511471118865780390486996601082102418" +,"4229084185957675819725844582167613108400" +,"9068653877952162764545674979144308771754" +,"8551565425951612499712254182109991511690" +,"7090525592007482152807163656647658543093" +,"9198968742256995592729889137556032960142" +,"2071864379877766468141740053503050313101" +,"1055375249261868472993219156394129253481" +,"2461178270502857106406495509025426298874" +,"8216781259733537757203421037984512664825" +,"4693452554407216935375049784445568498482" +,"2709693439640250842244170297203200674391" +,"5122217695676372684217182241705137947908" +,"6668814191410691246849638388008228444294" +,"4952122070212780440963814752538149378639" +,"9827737761436134120332969866554332504400" +,"3412406588339828249986707470540386748886" +,"7521506848088506994554600408372456405830" +,"1916926179183007872881163173153907665999" +,"6636166791472761992310264951474925339024" +,"6679667717747231380196787943691121008076" +,"3218993234115685151069259138068533004433" +,"4920152552986426962081492913852060211795" +,"0365186235986445521382132973036266396894" +,"3205351414936828189305188614651974318855" +,"3144278971529524658788277656125598825426" +,"5525287537572356662391582052968411726245" +,"2130137226726919525622574701068062252930" +,"2369996694245544770519574837226971226841" +,"6806769058165410189286521891570936341547" +,"0448109211631660241710734664066810078242" +,"4622919135804954122810530631429501069659" +,"0235247446548732490429856705369583140671" +,"2193399741215975228987754171460722199304" +,"1203037020703833716225328076959743850915" +,"5419885193880826109484912489603262199432"}; + vector costs(costs_, costs_+sizeof(costs_)/sizeof(*costs_)); + int _ = 7366; +END +CASE(4) + string costs_[] = ; + vector costs(costs_, costs_+sizeof(costs_)/sizeof(*costs_)); + int _ = ; +END +CASE(5) + string costs_[] = ; + vector costs(costs_, costs_+sizeof(costs_)/sizeof(*costs_)); + int _ = ; +END + +} +// END CUT HERE