ADDED SRM/573-U/1A-U.cpp Index: SRM/573-U/1A-U.cpp ================================================================== --- SRM/573-U/1A-U.cpp +++ SRM/573-U/1A-U.cpp @@ -0,0 +1,141 @@ +#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 TeamContest { public: + int worstRank(vector s) + { + int N = s.size()/3; + int us = str(s[0], s[1], s[2]); + sort(s.begin()+3, s.end()); + int L = 0; // |<=us| <= 0 is impossible + int R = N-1; // |<=us| <= N-1 is possible + while(R-L>1) + { + int C = (L+R)/2; + (possible(us, C, s) ? R : L) = C; + } + return N-R; + } + + int str(int a, int b, int c) + { + return max(max(a,b),c) + min(min(a,b),c); + } + + // |<=us| <= UB possible? + bool possible(int us, int UB, const vector& s) + { + int si = 3; + + // from weak teams + while(UB > 0) { + if(si==s.size()) + return true; + si += 3; + --UB; + } + + if(si==s.size()) + return true; // no more team left + + // can we make every other teams stronger than ourselves? + vector ss(s.begin()+si, s.end()); + while(!ss.empty()) + if(!takeOut(us, ss)) + return false; + return true; + } + + bool takeOut(int us, vector& s) + { + int a = s[0]; + s.erase(s.begin()); + int b = s[0]; + s.erase(s.begin()); + for(int i=0; i us) { + s.erase(s.begin()+i); + return true; + } + } + 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(_, TeamContest().worstRank(strength));} +int main(){ + +CASE(0) + int strength_[] = {5, 7, 3, 5, 7, 3, 5, 7, 3}; + vector strength(strength_, strength_+sizeof(strength_)/sizeof(*strength_)); + int _ = 2; +END +CASE(1) + int strength_[] = {5, 7, 3} +; + vector strength(strength_, strength_+sizeof(strength_)/sizeof(*strength_)); + int _ = 1; +END +CASE(2) + int strength_[] = {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}; + vector strength(strength_, strength_+sizeof(strength_)/sizeof(*strength_)); + int _ = 1; +END +CASE(3) + int strength_[] = {3,9,4,6,2,6,1,6,9,1,4,1,3,8,5} +; + vector strength(strength_, strength_+sizeof(strength_)/sizeof(*strength_)); + int _ = 3; +END +CASE(4) + int strength_[] = {53,47,88,79,99,75,28,54,65,14,22,13,11,31,43} +; + vector strength(strength_, strength_+sizeof(strength_)/sizeof(*strength_)); + int _ = 3; +END +CASE(5) + int strength_[] = {2,2,2,1,1,1,1,1,5}; + vector strength(strength_, strength_+sizeof(strength_)/sizeof(*strength_)); + int _ = 2; +END +/* +CASE(6) + int strength_[] = ; + vector strength(strength_, strength_+sizeof(strength_)/sizeof(*strength_)); + int _ = ; +END +*/ +} +// END CUT HERE ADDED SRM/573-U/1B.cpp Index: SRM/573-U/1B.cpp ================================================================== --- SRM/573-U/1B.cpp +++ SRM/573-U/1B.cpp @@ -0,0 +1,152 @@ +#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 SkiResorts { public: + long long minCost(vector road, vector altitude) + { + typedef int Vert; + typedef int Alt; + typedef pair State; + typedef LL Cost; + typedef pair Edge; + const int N = altitude.size(); + + priority_queue< Edge, vector, greater > Q; + set V; + 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 long long& Expected, const long long& 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(_, SkiResorts().minCost(road, altitude));} +int main(){ +CASE(0) + string road_[] = {"NYN", + "YNY", + "NYN"}; + vector road(road_, road_+sizeof(road_)/sizeof(*road_)); + int altitude_[] = {30, 20, 10}; + vector altitude(altitude_, altitude_+sizeof(altitude_)/sizeof(*altitude_)); + long long _ = 0LL; +END +CASE(1) + string road_[] = {"NY", + "YN"}; + vector road(road_, road_+sizeof(road_)/sizeof(*road_)); + int altitude_[] = {10, 20}; + vector altitude(altitude_, altitude_+sizeof(altitude_)/sizeof(*altitude_)); + long long _ = 10LL; +END +CASE(2) + string road_[] = {"NYN", + "YNN", + "NNN"}; + vector road(road_, road_+sizeof(road_)/sizeof(*road_)); + int altitude_[] = {573, 573, 573}; + vector altitude(altitude_, altitude_+sizeof(altitude_)/sizeof(*altitude_)); + long long _ = -1LL; +END +CASE(3) + string road_[] = {"NNYNNYYYNN", + "NNNNYNYNNN", + "YNNNNYYNNN", + "NNNNNNYNYY", + "NYNNNNNNYY", + "YNYNNNNYNN", + "YYYYNNNYNN", + "YNNNNYYNNN", + "NNNYYNNNNN", + "NNNYYNNNNN"}; + vector road(road_, road_+sizeof(road_)/sizeof(*road_)); + int altitude_[] = {7, 4, 13, 2, 8, 1, 8, 15, 5, 15}; + vector altitude(altitude_, altitude_+sizeof(altitude_)/sizeof(*altitude_)); + long long _ = 12LL; +END +CASE(4) + string road_[] = { + "NYNNNNNN", + "YNYNNNNN", + "NYNYNNNN", + "NNYNYNNN", + "NNNYNYNN", + "NNNNYNYN", + "NNNNNYNY", + "NNNNNNYN" + }; + vector road(road_, road_+sizeof(road_)/sizeof(*road_)); + int altitude_[] = { + 1,2,3,3,3,3,3,3 + }; + vector altitude(altitude_, altitude_+sizeof(altitude_)/sizeof(*altitude_)); + long long _ = 3LL; +END +/* +CASE(5) + string road_[] = ; + vector road(road_, road_+sizeof(road_)/sizeof(*road_)); + int altitude_[] = ; + vector altitude(altitude_, altitude_+sizeof(altitude_)/sizeof(*altitude_)); + long long _ = LL; +END +*/ +} +// END CUT HERE