ADDED SRM/TCO19-4-U/1A-U.cpp Index: SRM/TCO19-4-U/1A-U.cpp ================================================================== --- SRM/TCO19-4-U/1A-U.cpp +++ SRM/TCO19-4-U/1A-U.cpp @@ -0,0 +1,161 @@ +#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 ReProduct { public: + long long minimize(vector base, int goal) + { + vector> cand(1, make_tuple(0LL,-1,-1,-1,-1)); + for (LL a = 1,ai=0; a <= 1000000000000000000LL; a *= 2,++ai) + for (LL b = a,bi=0; b <= 1000000000000000000LL; b *= 3,++bi) + for (LL c = b,ci=0; c <= 1000000000000000000LL; c *= 5,++ci) + for (LL d = c,di=0; d <= 1000000000000000000LL; d *= 7,++di) + cand.emplace_back(d, ai,bi,ci,di); + + vector vs; + for (auto cc : cand) { + LL c = get<0>(cc); + LL v = value(c, base); + if (v == goal) + vs.push_back(c); + if (v + 1 == goal) + if (c == 0) + vs.push_back(10); + else if (c==1) + vs.push_back(11); + else { + int p2 = get<1>(cc); + int p3 = get<2>(cc); + int p5 = get<3>(cc); + int p7 = get<4>(cc); + if (p2 + p3 + p5 + p7 >= 2) { + vector ds; + for (int _ = 0; _ < p5; ++_) ds.push_back(5); + for (int _ = 0; _ < p7; ++_) ds.push_back(7); + if (ds.empty() && p2 + p3 == 2) { + for (int _ = 0; _ < p2; ++_) ds.push_back(2); + for (int _ = 0; _ < p3; ++_) ds.push_back(3); + } + else if (ds.empty() && p2 == 3 && p3 == 0) { + ds.push_back(2); + ds.push_back(4); + } + else { + for (; p2 >= 3; p2 -= 3) ds.push_back(8); + for (; p3 >= 2; p3 -= 2) ds.push_back(9); + if (p2 == 0) { + if (p3 == 0) {} + else if (p3 == 1) { ds.push_back(3); } + } + else if (p2 == 1) { + if (p3 == 0) { ds.push_back(2); } + else if (p3 == 1) { ds.push_back(6); } + } + else if (p2 == 2) { + if (p3 == 0) { ds.push_back(4); } + else if (p3 == 1) { ds.push_back(2); ds.push_back(6); } + } + } + + sort(ds.begin(), ds.end()); + if (ds.size() <= 18) { + LL u = 0; + for (int d : ds) + u = u * 10 + d; + vs.push_back(u); + } + } + } + } + return *min_element(vs.begin(), vs.end()); + } + + int value(LL x, const vector& base) { + if (x <= 9) + return base[int(x)]; + + LL p = 1; + for (; x; x /= 10) + p = p * (x % 10); + return value(p, base) + 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 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(_, ReProduct().minimize(base, goal));} +int main(){ +CASE(0) + int base_[] = {0,1,1,1,1,1,1,1,1,1}; + vector base(base_, base_+sizeof(base_)/sizeof(*base_)); + int goal = 2; + long long _ = 11LL; +END +CASE(1) + int base_[] = {0,0,0,0,0,0,0,0,0,0}; + vector base(base_, base_+sizeof(base_)/sizeof(*base_)); + int goal = 3; + long long _ = 39LL; +END +CASE(2) + int base_[] = {2,0,0,0,0,0,0,0,0,0}; + vector base(base_, base_+sizeof(base_)/sizeof(*base_)); + int goal = 2; + long long _ = 0LL; +END +CASE(3) + int base_[] = {2,2,2,2,2,2,2,2,0,2}; + vector base(base_, base_+sizeof(base_)/sizeof(*base_)); + int goal = 1; + long long _ = 18LL; +END +CASE(4) + int base_[] = {2,1,2,2,1,1,1,0,1,0}; + vector base(base_, base_+sizeof(base_)/sizeof(*base_)); + int goal = 6; + long long _ = 268LL; +END +CASE(5) + int base_[] = { 2,1,2,2,1,1,1,0,1,0 }; + vector base(base_, base_+sizeof(base_)/sizeof(*base_)); + int goal = 11; + long long _ = -1LL; +END +/* +CASE(6) + int base_[] = ; + vector base(base_, base_+sizeof(base_)/sizeof(*base_)); + int goal = ; + long long _ = LL; +END +*/ +} +// END CUT HERE ADDED SRM/TCO19-4-U/1B-U.cpp Index: SRM/TCO19-4-U/1B-U.cpp ================================================================== --- SRM/TCO19-4-U/1B-U.cpp +++ SRM/TCO19-4-U/1B-U.cpp @@ -0,0 +1,152 @@ +#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 InsidePoints { public: + vector construct(vector x, vector y) + { + map> x2y; + for (int i = 0; i < x.size(); ++i) + x2y[x[i]].insert(y[i]); + + vector> left; + vector> upper; + vector> lower; + vector> right; + + int prevx = -99999999; + int prevy = -99999999; + for (auto it : x2y) { + int x = it.first; + set ys = it.second; + + if (prevx == -99999999) { + upper.emplace_back(x, *ys.rbegin() + 1); + lower.emplace_back(x, *ys.begin() - 1); + + for (int yy = *ys.rbegin(); yy >= *ys.begin(); --yy) + left.emplace_back(ys.count(yy) ? x - 1 : x, yy); + } + else { + for (int xt = prevx + 1; xt < x; ++xt) { + upper.emplace_back(xt, prevy+1); + lower.emplace_back(xt, prevy); + } + upper.emplace_back(x, *ys.rbegin() + 1); + int id = -1; + for (int yy = *ys.rbegin(); yy >= *ys.begin(); --yy) + if (ys.count(yy) == 0) { + lower.emplace_back(x, yy); + lower.emplace_back(x-1, id--); + } + lower.emplace_back(x, *ys.begin() - 1); + } + + if (x2y.rbegin()->first == x) { + for (int yy = *ys.rbegin(); yy >= *ys.begin(); --yy) + right.emplace_back(ys.count(yy) ? x + 1 : x, yy); + } + + prevx = x; + prevy = *ys.rbegin(); + } + + vector> ans; + ans.insert(ans.end(), left.begin(), left.end()); + ans.insert(ans.end(), lower.begin(), lower.end()); + ans.insert(ans.end(), right.rbegin(), right.rend()); + ans.insert(ans.end(), upper.rbegin(), upper.rend()); + vector flat_ans; + for (auto xy : ans) { + flat_ans.push_back(xy.first); + flat_ans.push_back(xy.second); + } + return flat_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 vector & Expected, const vector & 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(_, InsidePoints().construct(x, y));} +int main(){ + +CASE(0) + int x_[] = {4}; + vector x(x_, x_+sizeof(x_)/sizeof(*x_)); + int y_[] = {7}; + vector y(y_, y_+sizeof(y_)/sizeof(*y_)); + int __[] = {3, 7, 4, 8, 5, 6 }; + vector _(__, __+sizeof(__)/sizeof(*__)); +END +CASE(1) + int x_[] = {4, 6}; + vector x(x_, x_+sizeof(x_)/sizeof(*x_)); + int y_[] = {7, 7}; + vector y(y_, y_+sizeof(y_)/sizeof(*y_)); + int __[] = {3, 6, 7, 6, 7, 8, 5, 7, 3, 8 }; + vector _(__, __+sizeof(__)/sizeof(*__)); +END +CASE(2) + int x_[] = {1, 1, 2, 2}; + vector x(x_, x_+sizeof(x_)/sizeof(*x_)); + int y_[] = {1, 2, 1, 2}; + vector y(y_, y_+sizeof(y_)/sizeof(*y_)); + int __[] = {0, 0, 3, 0, 3, 3, 0, 3 }; + vector _(__, __+sizeof(__)/sizeof(*__)); +END +CASE(3) + int x_[] = {1, 2, 3, 3, 3, 3, 5, 4}; + vector x(x_, x_+sizeof(x_)/sizeof(*x_)); + int y_[] = {3, 3, 1, 5, 2, 4, 3, 3}; + vector y(y_, y_+sizeof(y_)/sizeof(*y_)); + int __[] = {0, 2, 2, 2, 2, 0, 4, 0, 4, 2, 6, 2, 6, 4, 4, 4, 4, 6, 2, 6, 2, 4, 3, 3, 1, 4, 0, 4 }; + vector _(__, __+sizeof(__)/sizeof(*__)); +END +/* +CASE(4) + int x_[] = ; + vector x(x_, x_+sizeof(x_)/sizeof(*x_)); + int y_[] = ; + vector y(y_, y_+sizeof(y_)/sizeof(*y_)); + int __[] = ; + vector _(__, __+sizeof(__)/sizeof(*__)); +END +CASE(5) + int x_[] = ; + vector x(x_, x_+sizeof(x_)/sizeof(*x_)); + int y_[] = ; + vector y(y_, y_+sizeof(y_)/sizeof(*y_)); + int __[] = ; + vector _(__, __+sizeof(__)/sizeof(*__)); +END +*/ +} +// END CUT HERE