ADDED SRM/520-U/1A.cpp Index: SRM/520-U/1A.cpp ================================================================== --- SRM/520-U/1A.cpp +++ SRM/520-U/1A.cpp @@ -0,0 +1,128 @@ +#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 SRMCodingPhase { public: + int countScore(vector points, vector skills, int luck) + { + const int dec[] = {2,4,8}; + + int pBest = 0; + + int i[3]; + for(i[0]=0; i[0] +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(_, SRMCodingPhase().countScore(points, skills, luck));} +int main(){ + +CASE(0) + int points_[] = {250, 500, 1000}; + vector points(points_, points_+sizeof(points_)/sizeof(*points_)); + int skills_[] = {10, 25, 40}; + vector skills(skills_, skills_+sizeof(skills_)/sizeof(*skills_)); + int luck = 0; + int _ = 1310; +END +CASE(1) + int points_[] = {300, 600, 900}; + vector points(points_, points_+sizeof(points_)/sizeof(*points_)); + int skills_[] = {30, 65, 90}; + vector skills(skills_, skills_+sizeof(skills_)/sizeof(*skills_)); + int luck = 25; + int _ = 680; +END +CASE(2) + int points_[] = {250, 550, 950}; + vector points(points_, points_+sizeof(points_)/sizeof(*points_)); + int skills_[] = {10, 25, 40}; + vector skills(skills_, skills_+sizeof(skills_)/sizeof(*skills_)); + int luck = 75; + int _ = 1736; +END +CASE(3) + int points_[] = {256, 512, 1024}; + vector points(points_, points_+sizeof(points_)/sizeof(*points_)); + int skills_[] = {35, 30, 25}; + vector skills(skills_, skills_+sizeof(skills_)/sizeof(*skills_)); + int luck = 0; + int _ = 1216; +END +CASE(4) + int points_[] = {300, 600, 1100}; + vector points(points_, points_+sizeof(points_)/sizeof(*points_)); + int skills_[] = {80, 90, 100}; + vector skills(skills_, skills_+sizeof(skills_)/sizeof(*skills_)); + int luck = 4; + int _ = 0; +END +CASE(5) +int points_[] = {300,600,1100}; + vector points(points_, points_+sizeof(points_)/sizeof(*points_)); + int skills_[] = {30,30,30}; + vector skills(skills_, skills_+sizeof(skills_)/sizeof(*skills_)); + int luck = 100; + int _ = -1; +END +/* +CASE(6) + int points_[] = ; + vector points(points_, points_+sizeof(points_)/sizeof(*points_)); + int skills_[] = ; + vector skills(skills_, skills_+sizeof(skills_)/sizeof(*skills_)); + int luck = ; + int _ = ; +END +*/ +} +// END CUT HERE ADDED SRM/520-U/1B.cpp Index: SRM/520-U/1B.cpp ================================================================== --- SRM/520-U/1B.cpp +++ SRM/520-U/1B.cpp @@ -0,0 +1,187 @@ +#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 int MODVAL = 1000000007; // must be prime for op/ +struct mint +{ + int val; + mint():val(0){} + mint(int x):val(x%MODVAL) {} + mint(size_t 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 POW(mint x, LL e) { mint v=1; for(;e;x*=x,e>>=1) if(e&1) v*=x; return v; } +mint& operator/=(mint& x, mint y) { return x *= POW(y, MODVAL-2); } +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; } +mint operator/(mint x, mint y) { return x/=y; } +vector FAC_(1,1); +mint FAC(LL n) { while( FAC_.size()<=n ) FAC_.push_back( FAC_.back()*FAC_.size() ); return FAC_[n]; } +mint C(LL n, LL k) { return k<0 || n +struct DP4 +{ + int N1, N2, N3, N4; + vector data; + DP4(int N1, int N2, int N3, int N4, const T& t = T()) + : N1(N1), N2(N2), N3(N3), N4(N4), data(N1*N2*N3*N4, t) { assert(data.size()*sizeof(T)<(1<<26)); } + T& operator()(int i1, int i2, int i3, int i4) + { return data[ (((i1*N2)+i2)*N3+i3)*N4+i4 ]; } + void swap(DP4& rhs) + { data.swap(rhs.data); } +}; + +class SRMIntermissionPhase { public: + int countWays(vector points, vector description) + { + const int TOTAL = accumulate(points.begin(), points.end(), 0); + + DP4 patnum(2,2,2,TOTAL+1); + int a[3]; + for(a[0]=0; a[0]<2; ++a[0]) + for(a[1]=0; a[1]<2; ++a[1]) + for(a[2]=0; a[2]<2; ++a[2]) + { + patnum(a[0],a[1],a[2],0) = 1; + for(int i=0; i<3; ++i) if(a[i]) { + for(int p=1; p<=TOTAL; ++p) + patnum(a[0],a[1],a[2],p) += patnum(a[0],a[1],a[2],p-1); + for(int p=TOTAL; p>=points[i]+1; --p) + patnum(a[0],a[1],a[2],p) = patnum(a[0],a[1],a[2],p-1) - patnum(a[0],a[1],a[2],p-points[i]-1); + for(int p=points[i]; p>=0; --p) + patnum(a[0],a[1],a[2],p) = p>0 ? patnum(a[0],a[1],a[2],p-1) : 0; + } + } + + vector dp(TOTAL+2); + dp[0] = 1; // -1 + for(int i=description.size()-1; i>=0; --i) + { + partial_sum(dp.begin(), dp.end(), dp.begin()); + for(int s=TOTAL; s>=0; --s) + dp[s+1] = dp[s] * patnum( + description[i][0]=='Y', + description[i][1]=='Y', + description[i][2]=='Y', + s + ); + dp[0] = 0; + } + return accumulate(dp.begin()+1, dp.end(), mint(0)).val; + } +}; + +// 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(_, SRMIntermissionPhase().countWays(points, description));} +int main(){ + +CASE(4) +int points_[] = {1,2,3}; + vector points(points_, points_+sizeof(points_)/sizeof(*points_)); + string description_[] = {"YNN","NNN"}; + vector description(description_, description_+sizeof(description_)/sizeof(*description_)); + int _ = 1; +END +CASE(0) + int points_[] = {25000, 50000, 100000}; + vector points(points_, points_+sizeof(points_)/sizeof(*points_)); + string description_[] = {"YNN", + "NNN"}; + vector description(description_, description_+sizeof(description_)/sizeof(*description_)); + int _ = 25000; +END +CASE(1) + int points_[] = {30000, 60000, 90000}; + vector points(points_, points_+sizeof(points_)/sizeof(*points_)); + string description_[] = {"NYN", + "NYN"}; + vector description(description_, description_+sizeof(description_)/sizeof(*description_)); + int _ = 799969993; +END +CASE(2) + int points_[] = {25000, 45000, 110000}; + vector points(points_, points_+sizeof(points_)/sizeof(*points_)); + string description_[] = {"NNN", + "YYY"}; + vector description(description_, description_+sizeof(description_)/sizeof(*description_)); + int _ = 0; +END +CASE(3) + int points_[] = {25600, 51200, 102400}; + vector points(points_, points_+sizeof(points_)/sizeof(*points_)); + string description_[] = {"NYY", + "YNY", + "YYY", + "YNN", + "YYN", + "NNY", + "NYN", + "NNN"}; + vector description(description_, description_+sizeof(description_)/sizeof(*description_)); + int _ = 867560805; +END +CASE(5) +int points_[] = {30000,60000,110000}; + vector points(points_, points_+sizeof(points_)/sizeof(*points_)); + string description_[] = { + "YYY", + "YYY", + "YYY", + "YYY", + "YYY", + "YYY", + "YYY", + "YYY", + "YYY", + "YYY", + "YYY", + "YYY", + "YYY", + "YYY", + "YYY", + "YYY", + "YYY", + "YYY", + "YYY", + "YYY", + }; + vector description(description_, description_+sizeof(description_)/sizeof(*description_)); + int _ = -1; +END +} +// END CUT HERE ADDED SRM/520-U/1C-U.cpp Index: SRM/520-U/1C-U.cpp ================================================================== --- SRM/520-U/1C-U.cpp +++ SRM/520-U/1C-U.cpp @@ -0,0 +1,167 @@ +#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 int MODVAL = 1000000007; +struct mint +{ + int val; + mint():val(0){} + mint(int x):val(x%MODVAL) {} + mint(size_t 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 POW(mint x, LL e) { mint v=1; for(;e;x*=x,e>>=1) if(e&1) v*=x; return v; } +mint& operator/=(mint& x, mint y) { return x *= POW(y, MODVAL-2); } +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; } +mint operator/(mint x, mint y) { return x/=y; } +vector FAC_(1,1); +mint FAC(LL n) { while( FAC_.size()<=n ) FAC_.push_back( FAC_.back()*FAC_.size() ); return FAC_[n]; } +mint C(LL n, LL k) { return k<0 || n codersAttempted, vector codersChallenged) + { + string at = accumulate(codersAttempted.begin(), codersAttempted.end(), string("")); + string sc = accumulate(codersChallenged.begin(), codersChallenged.end(), string("")); + const int N = at.size(); + int NN=0, NY=0, YN=0, YY=0; + for(int i=0; i,int>, mint> memo; + int TOTAL; + mint rec(int YN, int NY, int YY) + { + if(YN+YY < YY+NY) + return 0; + if(YN==0 && YY==0) + return 1; + + pair,int> key(make_pair(YN,NY),YY); + if( memo.count(key) ) + return memo[key]; + mint ans = 0; + + // YN, unsuc + if(YN) ans += rec(YN-1, NY, YY) * YN * (TOTAL-1); + // YN, suc + if(YN&&NY) ans += rec(YN-1, NY-1, YY) * YN * NY; + // YY, unsuc + if(YY) ans += rec(YN, NY+1, YY-1) * YY * (TOTAL-1); + // YY, suc + if(YY&&NY) ans += rec(YN, NY, YY-1) * YY * NY; + return memo[key] = ans; + } +}; + +// 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(_, SRMChallengePhase().countWays(codersAttempted, codersChallenged));} +int main(){ + +CASE(0) + string codersAttempted_[] = {"YY"}; + vector codersAttempted(codersAttempted_, codersAttempted_+sizeof(codersAttempted_)/sizeof(*codersAttempted_)); + string codersChallenged_[] = {"NY"}; + vector codersChallenged(codersChallenged_, codersChallenged_+sizeof(codersChallenged_)/sizeof(*codersChallenged_)); + int _ = 1; +END +CASE(1) + string codersAttempted_[] = {"YY", "NN"}; + vector codersAttempted(codersAttempted_, codersAttempted_+sizeof(codersAttempted_)/sizeof(*codersAttempted_)); + string codersChallenged_[] = {"N", "NYY"}; + vector codersChallenged(codersChallenged_, codersChallenged_+sizeof(codersChallenged_)/sizeof(*codersChallenged_)); + int _ = 4; +END +CASE(2) + string codersAttempted_[] = {"YNNN"}; + vector codersAttempted(codersAttempted_, codersAttempted_+sizeof(codersAttempted_)/sizeof(*codersAttempted_)); + string codersChallenged_[] = {"NYY", "Y"}; + vector codersChallenged(codersChallenged_, codersChallenged_+sizeof(codersChallenged_)/sizeof(*codersChallenged_)); + int _ = 0; +END +CASE(3) + string codersAttempted_[] = {"N"}; + vector codersAttempted(codersAttempted_, codersAttempted_+sizeof(codersAttempted_)/sizeof(*codersAttempted_)); + string codersChallenged_[] = {"N"}; + vector codersChallenged(codersChallenged_, codersChallenged_+sizeof(codersChallenged_)/sizeof(*codersChallenged_)); + int _ = 1; +END +CASE(4) + string codersAttempted_[] = {"YYY"}; + vector codersAttempted(codersAttempted_, codersAttempted_+sizeof(codersAttempted_)/sizeof(*codersAttempted_)); + string codersChallenged_[] = {"NNY"}; + vector codersChallenged(codersChallenged_, codersChallenged_+sizeof(codersChallenged_)/sizeof(*codersChallenged_)); + int _ = 24; +END +CASE(5) + string codersAttempted_[] = {"YY", "N", "YYYY", "NN", "YYYYY"}; + vector codersAttempted(codersAttempted_, codersAttempted_+sizeof(codersAttempted_)/sizeof(*codersAttempted_)); + string codersChallenged_[] = {"N", "YYYYY", "N", "Y", "N", "YYYY", "N"}; + vector codersChallenged(codersChallenged_, codersChallenged_+sizeof(codersChallenged_)/sizeof(*codersChallenged_)); + int _ = 807026001; +END +/* +CASE(6) + string codersAttempted_[] = ; + vector codersAttempted(codersAttempted_, codersAttempted_+sizeof(codersAttempted_)/sizeof(*codersAttempted_)); + string codersChallenged_[] = ; + vector codersChallenged(codersChallenged_, codersChallenged_+sizeof(codersChallenged_)/sizeof(*codersChallenged_)); + int _ = ; +END +CASE(7) + string codersAttempted_[] = ; + vector codersAttempted(codersAttempted_, codersAttempted_+sizeof(codersAttempted_)/sizeof(*codersAttempted_)); + string codersChallenged_[] = ; + vector codersChallenged(codersChallenged_, codersChallenged_+sizeof(codersChallenged_)/sizeof(*codersChallenged_)); + int _ = ; +END +*/ +} +// END CUT HERE