ADDED SRM/TCO16-2B-U/1A.cpp Index: SRM/TCO16-2B-U/1A.cpp ================================================================== --- SRM/TCO16-2B-U/1A.cpp +++ SRM/TCO16-2B-U/1A.cpp @@ -0,0 +1,182 @@ +#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; } +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; } + +class TriangleTriples { public: + int count(int A, int B, int C) + { + return (mint(A)*B*C - cut(A,B,C) - cut(B,C,A) - cut(C,A,B)).val; + } + + // #{(a,b,c)<=(A,B,C) | a+b<=c} + mint cut(LL A, LL B, LL C) + { + if(A>B) swap(A,B); + + //---------------------------- + // Sigma + // #{a+b <= 1} + // #{a+b <= 2} + // ... + // #{a+b <= C} + //---------------------------- + // Sigma + // #{a+b == 1} * C + // #{a+b == 2} * C-1 + // ... + // #{a+b == C} * 1 + //---------------------------- + // where + // + // #{a+b == k} + //= + // k-1 for k <= A + // A for A+1<= k <= B + // A-(k-B)+1 for B+1<= k <= A+B + // 0 for A+B< k + //---------------------------- + + mint total = 0; + + //for(int k=1; k<=min(C,A); ++k) + // total += mint(k-1) * (C-k+1); + { + LL x = min(C,A); + total += mint(0+x-1)*x/2 * C - mint(x-1)*x*(2*x-1)/6; + } + + // for(int k=A+1; k<=min(C,B); ++k) + // total += mint(A) * (C-k+1); + if(A+1 <= min(C,B)) { + LL x = A+1, y = min(C,B); + total += mint(A) * (C-x+1+C-y+1) * (y-x+1) / 2; + } + + //for(int k=B+1; k<=min(C,A+B); ++k) + // total += mint(A-(k-B)+1) * (C-k+1); + + if(B+1 <= min(C,A+B)) { + LL X = min(C,A+B)-B, D = C-B; + //for(LL k=0; k<=X; ++k) + // total += mint(A-k)*(D-k); + + LL E = abs(D-A); + //for(LL k=0; k<=X; ++k) + // total += mint(k)*(k+E); + total += mint(X)*(X+1)/2*E + mint(X)*(X+1)*(2*X+1)/6; + } + return total; + } +}; + +// 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(_, TriangleTriples().count(A, B, C));} +int main(){ + +CASE(0) + int A = 1; + int B = 10; + int C = 20; + int _ = 10; +END +CASE(2) + int A = 10; + int B = 10; + int C = 10; + int _ = 505; +END +CASE(3) + int A = 1; + int B = 1; + int C = 1; + int _ = 1; +END +CASE(1) + int A = 2; + int B = 2; + int C = 1000000000; + int _ = 6; +END +CASE(4) + int A = 123456789; + int B = 987654321; + int C = 555555555; + int _ = 64296241; +END +CASE(4) + int A = 123456789; + int B = 555555555; + int C = 987654321; + int _ = 64296241; +END +CASE(4) + int A = 555555555; + int B = 987654321; + int C = 123456789; + int _ = 64296241; +END +/* +CASE(5) + int A = ; + int B = ; + int C = ; + int _ = ; +END +CASE(6) + int A = ; + int B = ; + int C = ; + int _ = ; +END +*/ +} +// END CUT HERE ADDED SRM/TCO16-2B-U/1B-U.cpp Index: SRM/TCO16-2B-U/1B-U.cpp ================================================================== --- SRM/TCO16-2B-U/1B-U.cpp +++ SRM/TCO16-2B-U/1B-U.cpp @@ -0,0 +1,154 @@ +#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; + +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 bags) + { + set gems; + for(auto& bag: bags) + for(char gem: bag) + gems.insert(gem); + + vector g(gems.begin(), gems.end()); + do { + bool ok = false; + for(int x=0; x= w[b] for sure + bool surely_heavy(const string& a, const string& b, vector g) + { + if(a.size() < b.size()) + return false; + + graph G(a.size()+b.size()); + for(int x=0; x= find(g.begin(),g.end(),b[y])) + G[x].emplace_back(a.size()+y); + + return biMatch<100>(G, a.size()) == b.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 string& Expected, const string& 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(_, FoxAndGemstone().isPossible(bags));} +int main(){ + +CASE(0) + string bags_[] = {"AB", "AC"}; + vector bags(bags_, bags_+sizeof(bags_)/sizeof(*bags_)); + string _ = "Possible"; +END +CASE(1) + string bags_[] = {"A", "BC"}; + vector bags(bags_, bags_+sizeof(bags_)/sizeof(*bags_)); + string _ = "Impossible"; +END +CASE(2) + string bags_[] = {"A", "B", "C", "AB", "AC", "BC", "ABC"}; + vector bags(bags_, bags_+sizeof(bags_)/sizeof(*bags_)); + string _ = "Possible"; +END +CASE(3) + string bags_[] = {"AB","AC","AD","BC","BD","CD"}; + vector bags(bags_, bags_+sizeof(bags_)/sizeof(*bags_)); + string _ = "Possible"; +END +CASE(4) + string bags_[] = {"AB", "CD"}; + vector bags(bags_, bags_+sizeof(bags_)/sizeof(*bags_)); + string _ = "Impossible"; +END +CASE(5) + string bags_[] = {"A", "A", "A"}; + vector bags(bags_, bags_+sizeof(bags_)/sizeof(*bags_)); + string _ = "Possible"; +END +/* +CASE(6) + string bags_[] = ; + vector bags(bags_, bags_+sizeof(bags_)/sizeof(*bags_)); + string _ = ; +END +CASE(7) + string bags_[] = ; + vector bags(bags_, bags_+sizeof(bags_)/sizeof(*bags_)); + string _ = ; +END +*/ +} +// END CUT HERE