ADDED SRM/631-U/1A.cpp Index: SRM/631-U/1A.cpp ================================================================== --- SRM/631-U/1A.cpp +++ SRM/631-U/1A.cpp @@ -0,0 +1,125 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; +typedef long long LL; +typedef complex CMP; + +class TaroJiroGrid { public: + int getNumber(vector grid) + { + const int H = grid.size(); + const int W = grid[0].size(); + const string Change[2] = {string(W, 'B'), string(W, 'W')}; + + // 0 + if(ok(grid)) + return 0; + // 1 + for(int y1=0; y1& g) + { + const int H = g.size(); + const int W = g[0].size(); + for(int x=0; xH/2 || nb>H/2) + return false; + } + } + return true; + } +}; + +// 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(_, TaroJiroGrid().getNumber(grid));} +int main(){ + +CASE(0) + string grid_[] = {"WB", + "BB"}; + vector grid(grid_, grid_+sizeof(grid_)/sizeof(*grid_)); + int _ = 1; +END +CASE(1) + string grid_[] = {"WB", + "WW"}; + vector grid(grid_, grid_+sizeof(grid_)/sizeof(*grid_)); + int _ = 1; +END +CASE(2) + string grid_[] = {"WB", + "WB"}; + vector grid(grid_, grid_+sizeof(grid_)/sizeof(*grid_)); + int _ = 2; +END +CASE(3) + string grid_[] = {"WBBW", + "WBWB", + "WWBB", + "BWWW"}; + vector grid(grid_, grid_+sizeof(grid_)/sizeof(*grid_)); + int _ = 2; +END +CASE(4) + string grid_[] = {"WBBWBB", + "BBWBBW", + "WWBWBW", + "BWWBBB", + "WBWBBW", + "WWWBWB"}; + vector grid(grid_, grid_+sizeof(grid_)/sizeof(*grid_)); + int _ = 1; +END +/* +CASE(5) + string grid_[] = ; + vector grid(grid_, grid_+sizeof(grid_)/sizeof(*grid_)); + int _ = ; +END +CASE(6) + string grid_[] = ; + vector grid(grid_, grid_+sizeof(grid_)/sizeof(*grid_)); + int _ = ; +END +*/ +} +// END CUT HERE ADDED SRM/631-U/1B-U.cpp Index: SRM/631-U/1B-U.cpp ================================================================== --- SRM/631-U/1B-U.cpp +++ SRM/631-U/1B-U.cpp @@ -0,0 +1,163 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; +typedef long long LL; +typedef complex CMP; + +class CatsOnTheLineDiv1 { public: + int getNumber(vector position, vector count, int time) + { + const int N = position.size(); + vector> pc; + for(int i=0; i dp; + dp[(-400000000LL)<<32] = 0; + for(auto& pci: pc) { + const int p = pci.first; + const int c = pci.second; + map dp2; + for(auto& tk: dp) { + const LL t = tk.first; + const int k = tk.second; + const int occ_x = int(t>>32); + const int has_wan = t&0x80000000; + const int wan_x = int(t&0x3fffffff); + + int myleft = max(p-time, occ_x+1); + int myright = myleft + c - 1; + if(myright <= p+time) { + LL key = (LL(myright)<<32) | has_wan | wan_x; + int v = k; + cerr << "#" << myright << " " << (has_wan?1:0) << " " << wan_x << endl; + if(dp2.count(key)) dp2[key] = min(dp2[key], v); else dp2[key] = v; + } + if(has_wan && p-time <= wan_x) { + LL key = LL(occ_x)<<32 | 0x80000000 | wan_x; + int v = k; + cerr << "$" << occ_x << " " << 1 << " " << wan_x << endl; + if(dp2.count(key)) dp2[key] = min(dp2[key], v); else dp2[key] = v; + } + { + LL key = LL(occ_x)<<32 | 0x80000000 | (p+time); + int v = k + (has_wan?1:0); + cerr << "!" << occ_x << " " << 1 << " " << p+time << endl; + if(dp2.count(key)) dp2[key] = min(dp2[key], v); else dp2[key] = v; + } + } + dp = std::move(dp2); + } + + int best = N; + for(auto& tk: dp) { + const LL t = tk.first; + const int k = tk.second; + const int occ_x = int(t>>32); + const int has_wan = t&0x80000000; + const int wan_x = int(t&0x3fffffff); + best = min(best, k + (has_wan?1:0)); + } + return 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(_, CatsOnTheLineDiv1().getNumber(position, count, time));} +int main(){ + +CASE(0) + int position_[] = {0}; + vector position(position_, position_+sizeof(position_)/sizeof(*position_)); + int count_[] = {7}; + vector count(count_, count_+sizeof(count_)/sizeof(*count_)); + int time = 3; + int _ = 0; +END +CASE(1) + int position_[] = {0}; + vector position(position_, position_+sizeof(position_)/sizeof(*position_)); + int count_[] = {6}; + vector count(count_, count_+sizeof(count_)/sizeof(*count_)); + int time = 2; + int _ = 1; +END +CASE(2) + int position_[] = {4, 7, 47}; + vector position(position_, position_+sizeof(position_)/sizeof(*position_)); + int count_[] = {4, 7, 4}; + vector count(count_, count_+sizeof(count_)/sizeof(*count_)); + int time = 1; + int _ = 3; +END +CASE(3) + int position_[] = {3, 0, 7, 10}; + vector position(position_, position_+sizeof(position_)/sizeof(*position_)); + int count_[] = {3, 7, 4, 5}; + vector count(count_, count_+sizeof(count_)/sizeof(*count_)); + int time = 2; + int _ = 2; +END +CASE(4) + int position_[] = {-5, 0, 7}; + vector position(position_, position_+sizeof(position_)/sizeof(*position_)); + int count_[] = {47, 85, 10}; + vector count(count_, count_+sizeof(count_)/sizeof(*count_)); + int time = 6; + int _ = 1; +END +CASE(5) + int position_[] = {-8, 12, -15, -20, 17, -5, 7, 10}; + vector position(position_, position_+sizeof(position_)/sizeof(*position_)); + int count_[] = {20, 10, 7, 9, 2, 8, 11, 10}; + vector count(count_, count_+sizeof(count_)/sizeof(*count_)); + int time = 2; + int _ = 5; +END + /* +CASE(6) + int position_[] = ; + vector position(position_, position_+sizeof(position_)/sizeof(*position_)); + int count_[] = ; + vector count(count_, count_+sizeof(count_)/sizeof(*count_)); + int time = ; + int _ = ; +END +CASE(7) + int position_[] = ; + vector position(position_, position_+sizeof(position_)/sizeof(*position_)); + int count_[] = ; + vector count(count_, count_+sizeof(count_)/sizeof(*count_)); + int time = ; + int _ = ; +END + */ +} +// END CUT HERE