ADDED SRM/673-U/1A.cpp Index: SRM/673-U/1A.cpp ================================================================== --- SRM/673-U/1A.cpp +++ SRM/673-U/1A.cpp @@ -0,0 +1,153 @@ +#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; + +static const unsigned MODVAL = 1000000007; +struct mint +{ + unsigned val; + mint():val(0){} + mint(int x):val(x%MODVAL) {} + mint(unsigned x):val(x%MODVAL) {} + mint(LL x):val(x%MODVAL) {} +}; +mint& operator+=(mint& x, mint y) { return x = x.val+y.val; } +mint& operator-=(mint& x, mint y) { return x = x.val-y.val+MODVAL; } +mint& operator*=(mint& x, mint y) { return x = LL(x.val)*y.val; } +mint operator+(mint x, mint y) { return x+=y; } +mint operator-(mint x, mint y) { return x-=y; } +mint operator*(mint x, mint y) { return x*=y; } + +class BearCavalry { public: + int countAssignments(vector warriors, vector horses) + { + mint total = 0; + + const int W = warriors[0]; + warriors.erase(warriors.begin()); + sort(warriors.begin(), warriors.end()); + sort(horses.begin(), horses.end()); + + for(int x=0; x hs(horses.begin(), horses.begin()+x); + hs.insert(hs.end(), horses.begin()+x+1, horses.end()); + total += cnt(W*H, warriors, hs); + } + return total.val; + } + + mint cnt(int TOP, vector w, vector h) + { + mint total = 1; + 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(_, BearCavalry().countAssignments(warriors, horses));} +int main(){ + +CASE(0) + int warriors_[] = {5,8,4,8}; + vector warriors(warriors_, warriors_+sizeof(warriors_)/sizeof(*warriors_)); + int horses_[] = {19,40,25,20}; + vector horses(horses_, horses_+sizeof(horses_)/sizeof(*horses_)); + int _ = 2; +END +CASE(1) + int warriors_[] = {1,1}; + vector warriors(warriors_, warriors_+sizeof(warriors_)/sizeof(*warriors_)); + int horses_[] = {1,1}; + vector horses(horses_, horses_+sizeof(horses_)/sizeof(*horses_)); + int _ = 0; +END +CASE(2) + int warriors_[] = {10,2,10}; + vector warriors(warriors_, warriors_+sizeof(warriors_)/sizeof(*warriors_)); + int horses_[] = {100,150,200}; + vector horses(horses_, horses_+sizeof(horses_)/sizeof(*horses_)); + int _ = 3; +END +CASE(3) + int warriors_[] = {10,20}; + vector warriors(warriors_, warriors_+sizeof(warriors_)/sizeof(*warriors_)); + int horses_[] = {1,3}; + vector horses(horses_, horses_+sizeof(horses_)/sizeof(*horses_)); + int _ = 1; +END +CASE(4) + int warriors_[] = {20,20,25,23,24,24,21}; + vector warriors(warriors_, warriors_+sizeof(warriors_)/sizeof(*warriors_)); + int horses_[] = {20,25,25,20,25,23,20}; + vector horses(horses_, horses_+sizeof(horses_)/sizeof(*horses_)); + int _ = 0; +END +CASE(5) + int warriors_[] = {970,800,800,800,800,800,800,800,800,800,800,800,800,800,800,800,800,800,800,800,800,800,800,800,800, +800,800,800,800,800,800,800,800,800,800,800,800,800,800,800,800,800,800,800,800,800,800,800,800,800}; + vector warriors(warriors_, warriors_+sizeof(warriors_)/sizeof(*warriors_)); + int horses_[] = {1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000, +1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000, +1000,1000,1000,1000,1000,1000,1000,1000,1000,1000}; + vector horses(horses_, horses_+sizeof(horses_)/sizeof(*horses_)); + int _ = 318608048; +END +/* +CASE(6) + int warriors_[] = ; + vector warriors(warriors_, warriors_+sizeof(warriors_)/sizeof(*warriors_)); + int horses_[] = ; + vector horses(horses_, horses_+sizeof(horses_)/sizeof(*horses_)); + int _ = ; +END +CASE(7) + int warriors_[] = ; + vector warriors(warriors_, warriors_+sizeof(warriors_)/sizeof(*warriors_)); + int horses_[] = ; + vector horses(horses_, horses_+sizeof(horses_)/sizeof(*horses_)); + int _ = ; +END +*/ +} +// END CUT HERE ADDED SRM/673-U/1B-U.cpp Index: SRM/673-U/1B-U.cpp ================================================================== --- SRM/673-U/1B-U.cpp +++ SRM/673-U/1B-U.cpp @@ -0,0 +1,180 @@ +#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; + +static unsigned MODVAL = 1000000007; +struct mint +{ + unsigned val; + mint():val(0){} + mint(int x):val(x%MODVAL) {} + mint(unsigned x):val(x%MODVAL) {} + mint(LL x):val(x%MODVAL) {} +}; +mint& operator+=(mint& x, mint y) { return x = x.val+y.val; } +mint& operator-=(mint& x, mint y) { return x = x.val-y.val+MODVAL; } +mint& operator*=(mint& x, mint y) { return x = LL(x.val)*y.val; } +mint operator+(mint x, mint y) { return x+=y; } +mint operator-(mint x, mint y) { return x-=y; } +mint operator*(mint x, mint y) { return x*=y; } + +vector< vector > CP_; +mint C(int n, int k) { + while( CP_.size() <= n ) { + int nn = CP_.size(); + CP_.push_back(vector(nn+1,1)); + for(int kk=1; kk memo3; + int pat_exact(int N, int S) { + memo3.resize(101*101, -1); + auto key = N*101+S; + if(memo3[key]!=-1) + return memo3[key]; + + mint total = 0; + for(int c=0; c memo2; + int pat_exact_shifted(int N, int S, int score_offset) { + memo2.resize(101*101*101, -1); + auto key = (N*101+score_offset)*101+S; + if(memo2[key]!=-1) + return memo2[key]; + + mint total = 0; + for(int c=0; c memo; + int pat_center_exact(int N, int c, int S) + { + c = min(c, N-1-c); + + if(N==1) + return (S==0 ? 1 : 0); + if(c==0 || c==N-1) + return pat_exact(N-1, S); + + memo.resize(101*101*101, -1); + auto key = (N*101+c)*101+S; + if(memo[key]!=-1) + return memo[key]; + + LL total = 0; + for(int cl=0; cl +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(_, BearPermutations().countPermutations(N, S, MOD));} +int main(){ + +CASE(0) + int N = 3; + int S = 1; + int MOD = 71876209; + int _ = 4; +END +CASE(1) + int N = 4; + int S = 0; + int MOD = 1000003; + int _ = 8; +END +CASE(2) + int N = 4; + int S = 1; + int MOD = 483128897; + int _ = 8; +END +CASE(3) + int N = 5; + int S = 3; + int MOD = 907283243; + int _ = 82; +END +CASE(4) + int N = 5; + int S = 100; + int MOD = 101; + int _ = 19; +END +CASE(5) + int N = 20; + int S = 30; + int MOD = 3; + int _ = 2; +END +CASE(6) + int N = 100; + int S = 100; + int MOD = 1000000007; + int _ = -1; +END +/* +CASE(7) + int N = ; + int S = ; + int MOD = ; + int _ = ; +END +*/ +} +// END CUT HERE