Artifact 2d1a81027397e941d6d4a39d3925a734ae3f7e49
#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;
class BallsInBoxes { public:
long long maxTurns(long long N, long long K)
{
if(N < 2*K)
return shortCase(N, K);
if(N < 3*K)
return 1 + shortCase((N+K)/2, K);
if(N < 10*K)
return 1 + maxTurns(N-K, K);
return (N/K-4) + maxTurns(N - (N/K-4)*K, K);
}
LL shortCase(LL N, LL K) {
// The case where N is small enough and all positions are possoible.
return solve(N-K);
}
LL solve(LL N) {
// Determine what number in [0,N] out of N boxes are filled.
return N ? solve(N/2)+1 : 0;
}
};
// 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 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(_, BallsInBoxes().maxTurns(N, K));}
int main(){
CASE(0)
long long N = 10LL;
long long K = 10LL;
long long _ = 0LL;
END
CASE(1)
long long N = 100LL;
long long K = 1LL;
long long _ = 99LL;
END
CASE(2)
long long N = 1000LL;
long long K = 999LL;
long long _ = 1LL;
END
CASE(3)
long long N = 10LL;
long long K = 5LL;
long long _ = 3LL;
END
CASE(4)
long long N = 1234567898765LL;
long long K = 658167578LL;
long long _ = -1LL;
END
/*
CASE(5)
long long N = LL;
long long K = LL;
long long _ = LL;
END
*/
}
// END CUT HERE