ADDED SRM/539-U/1A.cpp Index: SRM/539-U/1A.cpp ================================================================== --- SRM/539-U/1A.cpp +++ SRM/539-U/1A.cpp @@ -0,0 +1,143 @@ +#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 Over9000Rocks { public: + int countPossibilities(vector lowerBound, vector upperBound) + { + vector< pair > ev; + const int MIN = 9001; + const int N = lowerBound.size(); + for(int mask=1; mask<(1< +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(_, Over9000Rocks().countPossibilities(lowerBound, upperBound));} +int main(){ + +CASE(0) + int lowerBound_[] = {9000}; + vector lowerBound(lowerBound_, lowerBound_+sizeof(lowerBound_)/sizeof(*lowerBound_)); + int upperBound_[] = {9001}; + vector upperBound(upperBound_, upperBound_+sizeof(upperBound_)/sizeof(*upperBound_)); + int _ = 1; +END +CASE(1) + int lowerBound_[] = {9000, 1, 10}; + vector lowerBound(lowerBound_, lowerBound_+sizeof(lowerBound_)/sizeof(*lowerBound_)); + int upperBound_[] = {9000, 2, 20}; + vector upperBound(upperBound_, upperBound_+sizeof(upperBound_)/sizeof(*upperBound_)); + int _ = 15; +END +CASE(2) + int lowerBound_[] = {1001, 2001, 3001, 3001}; + vector lowerBound(lowerBound_, lowerBound_+sizeof(lowerBound_)/sizeof(*lowerBound_)); + int upperBound_[] = {1003, 2003, 3003, 3003}; + vector upperBound(upperBound_, upperBound_+sizeof(upperBound_)/sizeof(*upperBound_)); + int _ = 9; +END +CASE(3) + int lowerBound_[] = {9000,90000,1,10}; + vector lowerBound(lowerBound_, lowerBound_+sizeof(lowerBound_)/sizeof(*lowerBound_)); + int upperBound_[] = {9000,90000,3,15}; + vector upperBound(upperBound_, upperBound_+sizeof(upperBound_)/sizeof(*upperBound_)); + int _ = 38; +END +CASE(4) + int lowerBound_[] = {1,1,1,1,1,1}; + vector lowerBound(lowerBound_, lowerBound_+sizeof(lowerBound_)/sizeof(*lowerBound_)); + int upperBound_[] = {3,4,5,6,7,8}; + vector upperBound(upperBound_, upperBound_+sizeof(upperBound_)/sizeof(*upperBound_)); + int _ = 0; +END +CASE(5) + int lowerBound_[] = {242,7393,3738,2594,3051,7711,3386,4363,6035,4752,5384,7607,5702,2226,7792}; + vector lowerBound(lowerBound_, lowerBound_+sizeof(lowerBound_)/sizeof(*lowerBound_)); + int upperBound_[] = {9138,9120,9027,9185,9081,9114,9044,9089,9178,9103,9089,9026,9129,9050,9173}; + vector upperBound(upperBound_, upperBound_+sizeof(upperBound_)/sizeof(*upperBound_)); + int _ = -1; +END +CASE(6) + int lowerBound_[] = {9001}; + vector lowerBound(lowerBound_, lowerBound_+sizeof(lowerBound_)/sizeof(*lowerBound_)); + int upperBound_[] = {9002}; + vector upperBound(upperBound_, upperBound_+sizeof(upperBound_)/sizeof(*upperBound_)); + int _ = 2; +END +CASE(7) + int lowerBound_[] = {9000, 1, 2, 3}; + vector lowerBound(lowerBound_, lowerBound_+sizeof(lowerBound_)/sizeof(*lowerBound_)); + int upperBound_[] = {9000, 1, 2, 3}; + vector upperBound(upperBound_, upperBound_+sizeof(upperBound_)/sizeof(*upperBound_)); + int _ = 10; +END + +} +// END CUT HERE ADDED SRM/539-U/1B-U.cpp Index: SRM/539-U/1B-U.cpp ================================================================== --- SRM/539-U/1B-U.cpp +++ SRM/539-U/1B-U.cpp @@ -0,0 +1,159 @@ +#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; + +static const int INF = 0x3fffffff; + +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 + // only left->right edges are used during computation +{ + vector matchTo(G.size(), -1); + int ans = 0; + for(vert v=0; v streets) + { + int T = streets.size(); + vector< vector > g(T, vector(T, INF)); + for(int i=0; i > d = g; + for(int k=0; k(G, N+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(_, SafeReturn().minRisk(N, streets));} +int main(){ + +CASE(0) + int N = 3; + string streets_[] = {"-234", + "2---", + "3---", + "4---"}; + vector streets(streets_, streets_+sizeof(streets_)/sizeof(*streets_)); + int _ = 3; +END +CASE(1) + int N = 2; + string streets_[] = {"-12", + "1-1", + "21-"}; + vector streets(streets_, streets_+sizeof(streets_)/sizeof(*streets_)); + int _ = 1; +END +CASE(2) + int N = 3; + string streets_[] = {"-----7", + "--1---", + "-1-5--", + "--5-1-", + "---1-3", + "7---3-"}; + vector streets(streets_, streets_+sizeof(streets_)/sizeof(*streets_)); + int _ = 1; +END +CASE(3) + int N = 2; + string streets_[] = {"-11", + "1-1", + "11-"}; + vector streets(streets_, streets_+sizeof(streets_)/sizeof(*streets_)); + int _ = 2; +END +/* +CASE(4) + int N = ; + string streets_[] = ; + vector streets(streets_, streets_+sizeof(streets_)/sizeof(*streets_)); + int _ = ; +END +CASE(5) + int N = ; + string streets_[] = ; + vector streets(streets_, streets_+sizeof(streets_)/sizeof(*streets_)); + int _ = ; +END +*/ +} +// END CUT HERE ADDED SRM/539-U/1C-U.cpp Index: SRM/539-U/1C-U.cpp ================================================================== --- SRM/539-U/1C-U.cpp +++ SRM/539-U/1C-U.cpp @@ -0,0 +1,229 @@ +#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 +class IdGen +{ + map v2id_; + vector id2v_; +public: + int v2id(const T& v) { + if( !v2id_.count(v) ) { v2id_[v] = size(); id2v_.push_back(v); } + return v2id_[v]; + } + const T& id2v(int i) const { return id2v_[i]; } + int size() const { return id2v_.size(); } +}; + +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 + // only left->right edges are used during computation +{ + vector matchTo(G.size(), -1); + int ans = 0; + for(vert v=0; v grid) + { + int H = grid.size(); + int W = grid[0].size(); + + IdGen< pair< int,pair > > hline; + for(int y=0; y > > vline; + for(int x=0; x >& hh = hline.id2v(i); + const pair< int,pair >& vv = vline.id2v(k); + int y = hh.first; + int sx = hh.second.first; + int ex = hh.second.second; + int x = vv.first; + int sy = vv.second.first; + int ey = vv.second.second; + if( sx<=x && x(G, hline.size()); + } +}; + +// 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(_, FoxBomb().getMinimumCost(grid));} +int main(){ + +CASE(0) + string grid_[] = {"#..." +,"..##" +,"#.##"}; + vector grid(grid_, grid_+sizeof(grid_)/sizeof(*grid_)); + int _ = 2; +END +CASE(1) + string grid_[] = {".#.#.#." +,"......." +,".#.#.#."}; + vector grid(grid_, grid_+sizeof(grid_)/sizeof(*grid_)); + int _ = 4; +END +CASE(2) + string grid_[] = {"######################################" +,"######################################" +,"###.....................##############" +,"###.###################.###....#...###" +,"###.###################.###.######.###" +,"###.###################.###.######.###" +,"###.###################.###.######.###" +,"###.###################.###.######.###" +,"###.###################.###.######.###" +,"###.........####........###.######.###" +,"###########.###########.###........###" +,"###########.###########.##########.###" +,"###########.###########.##########.###" +,"###########.###########.##########.###" +,"###########.###########.##########.###" +,"##..........##..........##########.###" +,"#######################............###" +,"######################################"}; + vector grid(grid_, grid_+sizeof(grid_)/sizeof(*grid_)); + int _ = 9; +END +CASE(3) + string grid_[] = {".#." +,"..." +,"#.#" +,"..." +,".#."} +; + vector grid(grid_, grid_+sizeof(grid_)/sizeof(*grid_)); + int _ = 5; +END +CASE(4) + string grid_[] = {"."}; + vector grid(grid_, grid_+sizeof(grid_)/sizeof(*grid_)); + int _ = 1; +END +CASE(5) +string grid_[] = {"..."}; + vector grid(grid_, grid_+sizeof(grid_)/sizeof(*grid_)); + int _ = 1; +END +CASE(6) +string grid_[] = {".",".","."}; + vector grid(grid_, grid_+sizeof(grid_)/sizeof(*grid_)); + int _ = 1; +END +CASE(7) +string grid_[] = { + "...#.", + "####.", + "...#."}; + vector grid(grid_, grid_+sizeof(grid_)/sizeof(*grid_)); + int _ = 3; +END +} +// END CUT HERE