Artifact 0c0f6895050a398a7e0110d512053393673004c5
#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <iterator>
#include <functional>
#include <complex>
#include <queue>
#include <stack>
#include <cmath>
#include <cassert>
#include <tuple>
using namespace std;
typedef long long LL;
typedef complex<double> CMP;
LL C(LL n, LL k)
{
LL v = 1;
for(LL i=1; i<=k; ++i)
v = v*(n-i+1)/i;
return v;
}
class IntoTheMatrix { public:
int takePills(int turns, int N)
{
for(int F=0 ;; ++F)
if(best(F,turns)>=N)
return F;
}
map<pair<int,int>,LL> memo;
LL best(int F, int T)
{
if(T==0)
return 1;
pair<int,int> key(F,T);
if(memo.count(key))
return memo[key];
LL sum = 0;
for(int f=0; f<=F; ++f)
sum += best(f, T-1)*C(F,f);
return memo[key] = sum;
}
};
// BEGIN CUT HERE
#include <ctime>
double start_time; string timer()
{ ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); }
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v)
{ os << "{ ";
for(typename vector<T>::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(_, IntoTheMatrix().takePills(turns, N));}
int main(){
CASE(0)
int turns = 1;
int N = 1;
int _ = 0;
END
CASE(1)
int turns = 2;
int N = 10;
int _ = 3;
END
CASE(2)
int turns = 2;
int N = 1000;
int _ = 7;
END
CASE(3)
int turns = 10;
int N = 2;
int _ = 1;
END
CASE(4)
int turns = 4;
int N = 50;
int _ = 3;
END
CASE(5)
int turns = 1;
int N = 1000000;
int _ = -1;
END
CASE(6)
int turns = 10;
int N = 1000000;
int _ = -1;
END
}
// END CUT HERE