ADDED SRM/623-U/1A.cpp Index: SRM/623-U/1A.cpp ================================================================== --- SRM/623-U/1A.cpp +++ SRM/623-U/1A.cpp @@ -0,0 +1,162 @@ +#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 UniformBoard { public: + int getBoard(vector board, int K) + { + const int N = board.size(); + + int A=0, P=0; + for(int y=0; y A) + return INF; + + int move = 0; + if(e) { + move += e; + E += e; + A -= e; + a += e; + e = 0; + } + if(p) { + if(E == 0) + return INF; + move += 2*p; + } + return move; + } +}; + +// 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(_, UniformBoard().getBoard(board, K));} +int main(){ + +CASE(0) + string board_[] = {"AP", + ".A"}; + vector board(board_, board_+sizeof(board_)/sizeof(*board_)); + int K = 0; + int _ = 1; +END +CASE(1) + string board_[] = {"AP", + ".A"}; + vector board(board_, board_+sizeof(board_)/sizeof(*board_)); + int K = 1; + int _ = 2; +END +CASE(2) + string board_[] = {"PPP", + "APA", + "A.P"}; + vector board(board_, board_+sizeof(board_)/sizeof(*board_)); + int K = 2; + int _ = 3; +END +CASE(3) + string board_[] = {"AAA", + "PPP", + "AAA"}; + vector board(board_, board_+sizeof(board_)/sizeof(*board_)); + int K = 10; + int _ = 3; +END +CASE(4) + string board_[] = {"."}; + vector board(board_, board_+sizeof(board_)/sizeof(*board_)); + int K = 1000; + int _ = 0; +END +CASE(5) + string board_[] = {"PPAAPA..AP", + "PPA.APAP..", + "..P.AA.PPP", + "P.P..APAA.", + "P.P..P.APA", + "PPA..AP.AA", + "APP..AAPAA", + "P.P.AP...P", + ".P.A.PAPPA", + "..PAPAP..P"}; + vector board(board_, board_+sizeof(board_)/sizeof(*board_)); + int K = 10; + int _ = 15; +END +/* +CASE(6) + string board_[] = ; + vector board(board_, board_+sizeof(board_)/sizeof(*board_)); + int K = ; + int _ = ; +END +CASE(7) + string board_[] = ; + vector board(board_, board_+sizeof(board_)/sizeof(*board_)); + int K = ; + int _ = ; +END +*/ +} +// END CUT HERE ADDED SRM/623-U/1B-U.cpp Index: SRM/623-U/1B-U.cpp ================================================================== --- SRM/623-U/1B-U.cpp +++ SRM/623-U/1B-U.cpp @@ -0,0 +1,204 @@ +#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 CatchTheBeat { public: + int maxCatched(int n, int x0, int y0, int a, int b, int c, int d, int mod1, int mod2, int offset) + { + vector x(n), y(n); + x[0] = x0; + for(int i=1; i& x, const vector& y) + { + vector> tx; + for(int i=0; i> score_table(tx.size()); + score_table[0].push_back(0); + int best_score = 0; + for(int c=1; c=0; --bs) { + for(int p: score_table[bs]) + if(tx[c].first - tx[p].first >= abs(tx[c].second - tx[p].second)) + {pre = bs; goto found_pre;} + } + found_pre: + if(pre>=0) { + score_table[pre+1].push_back(c); + best_score = max(best_score, pre+1); + } + } + return best_score; + } +}; + +// 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(_, CatchTheBeat().maxCatched(n, x0, y0, a, b, c, d, mod1, mod2, offset));} +int main(){ + +CASE(0) + int n = 3; + int x0 = 0; + int y0 = 0; + int a = 1; + int b = 1; + int c = 1; + int d = 1; + int mod1 = 100; + int mod2 = 100; + int offset = 1; + int _ = 2; +END +CASE(1) + int n = 1; + int x0 = 0; + int y0 = 1234; + int a = 0; + int b = 0; + int c = 0; + int d = 0; + int mod1 = 1000000000; + int mod2 = 1000000000; + int offset = 1000; + int _ = 1; +END +CASE(2) + int n = 1; + int x0 = 0; + int y0 = 999; + int a = 0; + int b = 0; + int c = 0; + int d = 0; + int mod1 = 1000000000; + int mod2 = 1000000000; + int offset = 1000; + int _ = 0; +END +CASE(3) + int n = 100; + int x0 = 0; + int y0 = 0; + int a = 1; + int b = 1; + int c = 1; + int d = 1; + int mod1 = 3; + int mod2 = 58585858; + int offset = 1; + int _ = 66; +END +CASE(4) + int n = 500000; + int x0 = 123456; + int y0 = 0; + int a = 1; + int b = 0; + int c = 1; + int d = 1; + int mod1 = 1000000000; + int mod2 = 1000000000; + int offset = 0; + int _ = 376544; +END +CASE(5) + int n = 500000; + int x0 = 0; + int y0 = 0; + int a = 0; + int b = 0; + int c = 0; + int d = 0; + int mod1 = 1; + int mod2 = 1; + int offset = 0; + int _ = 500000; +END +CASE(6) + int n = 10; + int x0 = 999999957; + int y0 = 79; + int a = 993948167; + int b = 24597383; + int c = 212151897; + int d = 999940854; + int mod1 = 999999986; + int mod2 = 999940855; + int offset = 3404; + int _ = 3; +END +/* +CASE(7) + int n = ; + int x0 = ; + int y0 = ; + int a = ; + int b = ; + int c = ; + int d = ; + int mod1 = ; + int mod2 = ; + int offset = ; + int _ = ; +END +CASE(8) + int n = ; + int x0 = ; + int y0 = ; + int a = ; + int b = ; + int c = ; + int d = ; + int mod1 = ; + int mod2 = ; + int offset = ; + int _ = ; +END +*/ +} +// END CUT HERE ADDED SRM/623-U/1C-U.cpp Index: SRM/623-U/1C-U.cpp ================================================================== --- SRM/623-U/1C-U.cpp +++ SRM/623-U/1C-U.cpp @@ -0,0 +1,129 @@ +#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 AliceAndFriends { public: + double getMoney(vector cards) + { + int N = cards.size(); + double ex = 0.0; + for(int alice=0; alice R-B + // r-b > R+B + // r+b > R-B + // r+b > R+B + // ができるだけ成り立ちたい + for(int b=0; b<=r; ++b) + { + // Alice: [R-B or R+B] + // You: [r-b or r+b] + double s = 0.0; + s += (r-bR-B ? -0.25 : 0); + s += (r-bR+B ? -0.25 : 0); + s += (r+bR-B ? -0.25 : 0); + s += (r+bR+B ? -0.25 : 0); + best_you = min(best_you, s); + } + total_gain += best_you; + } + best = max(best, total_gain); + } + ex += best; + } + return ex / N; + } +}; + +// 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 double& Expected, const double& Received) { + bool ok = (abs(Expected - Received) < 1e-9); + 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(_, AliceAndFriends().getMoney(cards));} +int main(){ + +CASE(0) + int cards_[] = {10, 1}; + vector cards(cards_, cards_+sizeof(cards_)/sizeof(*cards_)); + double _ = 0.0; +END +CASE(1) + int cards_[] = {10, 9}; + vector cards(cards_, cards_+sizeof(cards_)/sizeof(*cards_)); + double _ = -0.25; +END +CASE(2) + int cards_[] = {1, 3}; + vector cards(cards_, cards_+sizeof(cards_)/sizeof(*cards_)); + double _ = 0.0; +END +CASE(3) + int cards_[] = {1000000000, 1000000000}; + vector cards(cards_, cards_+sizeof(cards_)/sizeof(*cards_)); + double _ = 0.0; +END +CASE(4) + int cards_[] = {42, 468, 335, 501, 170, 725, 479, 359, 963, 465, 706, 146, 282, 828, 962, 492, 996, + 943, 828, 437, 392, 605, 903, 154, 293, 383, 422, 717, 719, 896, 448, 727, 772, 539, + 870, 913, 668, 300, 36, 895, 704, 812, 323, 334, 674, 665, 142, 712, 254, 869}; + vector cards(cards_, cards_+sizeof(cards_)/sizeof(*cards_)); + double _ = -9.095; +END +/* +CASE(5) + int cards_[] = ; + vector cards(cards_, cards_+sizeof(cards_)/sizeof(*cards_)); + double _ = ; +END +CASE(6) + int cards_[] = ; + vector cards(cards_, cards_+sizeof(cards_)/sizeof(*cards_)); + double _ = ; +END +*/ +} +// END CUT HERE