Index: CheckList.pptx ================================================================== --- CheckList.pptx +++ CheckList.pptx cannot compute difference between binary files ADDED SRM/398/2C.cpp Index: SRM/398/2C.cpp ================================================================== --- SRM/398/2C.cpp +++ SRM/398/2C.cpp @@ -0,0 +1,134 @@ +#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 MatchString { public: + int placeWords(string matchString, vector matchWords) + { + const int N = matchString.size(); + vector< vector > idx(N); + set all_idx; + + for(int i=0; i::iterator it=all_idx.begin(); it!=all_idx.end(); ++it) + { + int T = *it; + int score = 0; + 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(_, MatchString().placeWords(matchString, matchWords));} +int main(){ + +CASE(0) + string matchString = "TOP"; + string matchWords_[] = {"TIK", + "PPPO", + "OP"}; + vector matchWords(matchWords_, matchWords_+sizeof(matchWords_)/sizeof(*matchWords_)); + int _ = 5; +END +CASE(1) + string matchString = "EEA"; + string matchWords_[] = {"GEGA", + "TOPCODER", + "TEST"}; + vector matchWords(matchWords_, matchWords_+sizeof(matchWords_)/sizeof(*matchWords_)); + int _ = -1; +END +CASE(2) + string matchString = "AB"; + string matchWords_[] = {"ABA", + "ABAB"}; + vector matchWords(matchWords_, matchWords_+sizeof(matchWords_)/sizeof(*matchWords_)); + int _ = 1; +END +CASE(3) + string matchString = "FIND"; + string matchWords_[] = {"VERYFAST", + "OPINION", + "SPENDING", + "ODD"}; + vector matchWords(matchWords_, matchWords_+sizeof(matchWords_)/sizeof(*matchWords_)); + int _ = 3; +END +CASE(4) + string matchString = "TOP"; + string matchWords_[] = {"OUTTHERE", + "FROM", + "NOPQRSTU"}; + vector matchWords(matchWords_, matchWords_+sizeof(matchWords_)/sizeof(*matchWords_)); + int _ = 0; +END +/* +CASE(5) + string matchString = ; + string matchWords_[] = ; + vector matchWords(matchWords_, matchWords_+sizeof(matchWords_)/sizeof(*matchWords_)); + int _ = ; +END +CASE(6) + string matchString = ; + string matchWords_[] = ; + vector matchWords(matchWords_, matchWords_+sizeof(matchWords_)/sizeof(*matchWords_)); + int _ = ; +END +*/ +} +// END CUT HERE ADDED SRM/499-U/1A.cpp Index: SRM/499-U/1A.cpp ================================================================== --- SRM/499-U/1A.cpp +++ SRM/499-U/1A.cpp @@ -0,0 +1,90 @@ +#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 ColorfulRabbits { public: + int getMinimum(vector replies) + { + map m; + for(int i=0; i::iterator it=m.begin(); it!=m.end(); ++it) + { + int s = it->first + 1; + int n = it->second; + total += (n+s-1) / s * s; + } + 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(_, ColorfulRabbits().getMinimum(replies));} +int main(){ + +CASE(0) + int replies_[] = { 1, 1, 2, 2 } +; + vector replies(replies_, replies_+sizeof(replies_)/sizeof(*replies_)); + int _ = 5; +END +CASE(1) + int replies_[] = { 0 } +; + vector replies(replies_, replies_+sizeof(replies_)/sizeof(*replies_)); + int _ = 1; +END +CASE(2) + int replies_[] = { 2, 2, 44, 2, 2, 2, 444, 2, 2 } +; + vector replies(replies_, replies_+sizeof(replies_)/sizeof(*replies_)); + int _ = 499; +END +CASE(3) + int replies_[] = {1}; + vector replies(replies_, replies_+sizeof(replies_)/sizeof(*replies_)); + int _ = 2; +END +CASE(4) + int replies_[] = {2}; + vector replies(replies_, replies_+sizeof(replies_)/sizeof(*replies_)); + int _ = 3; +END +CASE(5) + int replies_[] = {1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000}; + vector replies(replies_, replies_+sizeof(replies_)/sizeof(*replies_)); + int _ = -1; +END + +} +// END CUT HERE ADDED SRM/499-U/1B-U.cpp Index: SRM/499-U/1B-U.cpp ================================================================== --- SRM/499-U/1B-U.cpp +++ SRM/499-U/1B-U.cpp @@ -0,0 +1,113 @@ +#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 WhiteSpaceEditing { public: + int getMinimum(vector lines) + { + const int N = lines.size(); + const int V = *max_element(lines.begin(), lines.end()); + vector dp(V+1), dp_neo(V+1); + for(int v=0; v<=V; ++v) + dp[v] = abs(v - lines[N-1]); + for(int i=N-2; i>=0; --i) + { + int best = INT_MAX; + for(int v=lines[i]; v>=0; --v) { + best = min(best, dp[v]); + dp_neo[v] = abs(v - lines[i]) + best; + } + best = INT_MAX; + for(int v=lines[i]; v<=V; ++v) { + best = min(best, dp[v]); + dp_neo[v] = abs(v - lines[i]) + best; + } + dp.swap(dp_neo); + } + return dp[0] + N-1; + } +}; + +// 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(_, WhiteSpaceEditing().getMinimum(lines));} +int main(){ + +CASE(0) + int lines_[] = { 3, 2, 3 }; + vector lines(lines_, lines_+sizeof(lines_)/sizeof(*lines_)); + int _ = 6; +END +CASE(1) + int lines_[] = { 0 }; + vector lines(lines_, lines_+sizeof(lines_)/sizeof(*lines_)); + int _ = 0; +END +CASE(2) + int lines_[] = { 1, 2, 4 } +; + vector lines(lines_, lines_+sizeof(lines_)/sizeof(*lines_)); + int _ = 6; +END +CASE(3) + int lines_[] = { 250, 105, 155, 205, 350 } +; + vector lines(lines_, lines_+sizeof(lines_)/sizeof(*lines_)); + int _ = 499; +END +CASE(4) +int lines_[] = {0}; + vector lines(lines_, lines_+sizeof(lines_)/sizeof(*lines_)); + int _ = 0; +END +CASE(5) +int lines_[] = {1}; + vector lines(lines_, lines_+sizeof(lines_)/sizeof(*lines_)); + int _ = 1; +END +CASE(5) + int lines_[] = {10}; + vector lines(lines_, lines_+sizeof(lines_)/sizeof(*lines_)); + int _ = 10; +END +CASE(5) + int lines_[] = {10,10}; + vector lines(lines_, lines_+sizeof(lines_)/sizeof(*lines_)); + int _ = 11; +END +CASE(5) + int lines_[] = {1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000}; + vector lines(lines_, lines_+sizeof(lines_)/sizeof(*lines_)); + int _ = 1000049; +END + +} +// END CUT HERE ADDED SRM/499-U/1C-U.cpp Index: SRM/499-U/1C-U.cpp ================================================================== --- SRM/499-U/1C-U.cpp +++ SRM/499-U/1C-U.cpp @@ -0,0 +1,226 @@ +#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; + +template +class Graph +{ + map v2id_; + vector id2v_; +public: + vector< vector > G; + + int vert( const V& t ) + { + if( !v2id_.count(t) ) { v2id_[t] = G.size(); id2v_.push_back(t); G.resize(G.size()+1); } + return v2id_[t]; + } + void edge( const V& s_, const V& t_ ) + { + int s=vert(s_), t=vert(t_); + G[s].push_back(t); + } + const V& orig( int v ) + { + return id2v_[v]; + } +}; + +class StronglyConnectedComponent +{ +public: + StronglyConnectedComponent( const vector< vector >& G ) + : scc(), forest(), G(G), no(0), dfs_no(G.size()), dfs_lo(G.size()), scc_id(G.size()) + { + for(int v=0; v > scc; // scc[i] : the list of verts in the i-th component + vector< vector > forest; // the forest structure over sccs + +private: + const vector< vector >& G; + int no; + vector dfs_no; // Special: 0 : not visited yet + vector dfs_lo; // Special: INT_MAX : already classified into some scc !!!! not a good idea! + // rather use scc_id for that purpose (distinguishing assigned or not) + vector scc_id; + vector pending; + + void dfs(int v) + { + if( dfs_no[v] ) + return; + + dfs_no[v] = dfs_lo[v] = ++no; // visit v + for(int i=0; i dfs_lo:=INT_MAX + scc.push_back(pending), pending.clear(); + + // construct scc-forest (if needed) + scc_id[v] = scc.size()-1; + set children; + for(int i=0; i(children.begin(), children.end()) ); + } + } +}; + + +class ImpossibleGame { public: + static LL C(LL n, LL k) { + LL v = 1; + for(int i=1; i<=k; ++i) + v = v * (n+1-i) / i; + return v; + } + static LL weight(LL a, LL b, LL c, LL d) { + return C(a+b+c+d,a) * C(b+c+d,b) * C(c+d,c); + } + + long long getMinimum(int k, vector before, vector after) + { + vector< pair< vector, vector > > dif; + for(int i=0; i be(4), af(4); + for(int j=0; j > G; + + vector v(4); + for(v[0]=0; v[0]<=k; ++v[0]) + for(v[1]=0; v[0]+v[1]<=k; ++v[1]) + for(v[2]=0; v[0]+v[1]+v[2]<=k; ++v[2]) + for(v[3]=0; v[0]+v[1]+v[2]+v[3]<=k; ++v[3]) + { + G.vert(v); + for(int i=0; i u = v; + for(int k=0; k<4; ++k) + { + if( (u[k]-=dif[i].first[k]) < 0 ) + dame = true; + u[k] += dif[i].second[k]; + } + if( !dame ) + G.edge(v, u); + } + } + + StronglyConnectedComponent scc(G.G); + return 0; + } +}; + +// 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 long long& Expected, const long long& 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(_, ImpossibleGame().getMinimum(k, before, after));} +int main(){ + +CASE(0) + int k = 1; + string before_[] = { "A" } +; + vector before(before_, before_+sizeof(before_)/sizeof(*before_)); + string after_[] = { "B" } +; + vector after(after_, after_+sizeof(after_)/sizeof(*after_)); + long long _ = 2LL; +END +CASE(1) + int k = 2; + string before_[] = { "A", "A", "D" } +; + vector before(before_, before_+sizeof(before_)/sizeof(*before_)); + string after_[] = { "B", "C", "D" } +; + vector after(after_, after_+sizeof(after_)/sizeof(*after_)); + long long _ = 5LL; +END +CASE(2) + int k = 2; + string before_[] = { "B", "C", "D" } +; + vector before(before_, before_+sizeof(before_)/sizeof(*before_)); + string after_[] = { "C", "D", "B" } +; + vector after(after_, after_+sizeof(after_)/sizeof(*after_)); + long long _ = 9LL; +END +CASE(3) + int k = 6; + string before_[] = { "AABBC", "AAAADA", "AAACA", "CABAA", "AAAAAA", "BAAAA" } +; + vector before(before_, before_+sizeof(before_)/sizeof(*before_)); + string after_[] = { "AACCB", "DAAABC", "AAAAD", "ABCBA", "AABAAA", "AACAA" } +; + vector after(after_, after_+sizeof(after_)/sizeof(*after_)); + long long _ = 499LL; +END +/* +CASE(4) + int k = ; + string before_[] = ; + vector before(before_, before_+sizeof(before_)/sizeof(*before_)); + string after_[] = ; + vector after(after_, after_+sizeof(after_)/sizeof(*after_)); + long long _ = LL; +END +CASE(5) + int k = ; + string before_[] = ; + vector before(before_, before_+sizeof(before_)/sizeof(*before_)); + string after_[] = ; + vector after(after_, after_+sizeof(after_)/sizeof(*after_)); + long long _ = LL; +END +*/ +} +// END CUT HERE Index: lib/numeric/modArith.cpp ================================================================== --- lib/numeric/modArith.cpp +++ lib/numeric/modArith.cpp @@ -4,19 +4,18 @@ // // Verified by // - TCO10 R3 LV3 //------------------------------------------------------------- -static const int MODVAL = 1000000007; // op/ depends on primarity of the MODVAL +static const int MODVAL = 1000000007; // must be prime for op/ struct mint { int val; mint():val(0){} mint(int x):val(x%MODVAL) {} mint(LL x):val(x%MODVAL) {} }; - mint operator+(mint x, mint y) { return x.val+y.val; } mint operator-(mint x, mint y) { return x.val-y.val+MODVAL; } mint operator*(mint x, mint y) { return LL(x.val)*y.val; } mint POW(mint x, int e) { mint v = 1; @@ -26,11 +25,11 @@ return v; } mint operator/(mint x, mint y) { return x * POW(y, MODVAL-2); } vector FAC_(1,1); -void FAC_INIT(int n) { for(int i=1; i<=n; ++i) FAC_.push_back( FAC_.back()*i ); } +void FAC_INIT(int n) { while( FAC_.size()<=n ) FAC_.push_back( FAC_.back()*FAC_.size() ); } mint FAC(mint x) { return FAC_[x.val]; } mint C(mint n, mint k) { return k.val<0 || n.val>=1) - if(e&1) - v = MUL(v, x); - return v; -} - -// MODVAL must be a prime!! -LL DIV(LL x, LL y) { return MUL(x, POW(y, MODVAL-2)); } - -// MODVAL must be a prime!! -LL C(LL n, LL k) { - LL v = 1; - for(LL i=1; i<=k; ++i) - v = DIV(MUL(v, n-i+1), i); - return v; -} - -// MODVAL must be a prime!! -LL GSS(LL k, LL b, LL e) // k^b + k^b+1 + ... + k^e -{ - if( b > e ) return 0; - if( k <= 1 ) return k*(e-b+1); - return DIV(SUB(POW(k, e+1), POW(k,b)), k-1); -} - - - - -LL Cpascal(LL n, LL k) -{ - vector< vector > c(n+1, vector(k+1)); - for(LL nn=1; nn<=n; ++nn) - for(LL kk=0; kk<=min(nn,k); ++kk) - c[nn][kk] = kk==0 || kk==nn ? 1 : ADD(c[nn-1][kk-1], c[nn-1][kk]); - return c[n][k]; -} - -vector< vector > MATMUL(vector< vector >& a, vector< vector >& b) -{ - int N = a.size(); - vector< vector > c(N, vector(N)); - for(int i=0; i > v(2, vector(2)); - vector< vector > x(2, vector(2)); - v[0][0] = v[1][1] = 1; - x[0][0] = x_; x[0][1] = 0; - x[1][0] = 1 ; x[1][1] = 1; - for(;e;x=MATMUL(x,x),e>>=1) - if(e&1) - v = MATMUL(v, x); - return v[1][0]; -} - -// works for non-prime MODVAL -LL HYP(LL x_, LL e) // e x^0 + (e-1) x^1 + ... + 1 x^e-1 = GEO(x,1)+GEO(x,2)+...+GEO(x,e) -{ - vector< vector > v(3, vector(3)); - vector< vector > x(3, vector(3)); - v[0][0] = v[1][1] = v[2][2] = 1; - x[0][0] = x_; x[0][1] = 0; x[0][2] = 0; - x[1][0] = 1 ; x[1][1] = 1; x[1][2] = 0; - x[2][0] = 0 ; x[2][1] = 1; x[2][2] = 1; - e++; - for(;e;x=MATMUL(x,x),e>>=1) - if(e&1) - v = MATMUL(v, x); - return v[2][0]; -}