Artifact Content
Not logged in

Artifact d330555d42831ae2ad2840ffb2ca90284cbe96c1


#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 SubdividedSlimes { public:
	int needCut(int S, int M)
	{
		int L=0, R=S;
		while(R-L>1) {
			int C = (L+R)/2;
			(maxScore(S, C) >= M ? R : L) = C;
		}
		return R==S ? -1 : R;
	}

	LL maxScore(int S, int Turn) {
		LL score = 0;

		multiset<int, greater<int>> X;
		X.insert(S);
		for(int t=0; t<Turn && *X.begin()>1; ++t) {
			int V = *X.begin(), U = V/2;
			X.erase(X.begin());
			score += U*(V-U);
			X.insert(U);
			X.insert(V-U);
		}
		return score;
	}
};

// 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(_, SubdividedSlimes().needCut(S, M));}
int main(){

CASE(0)
	int S = 3; 
	int M = 2; 
	int _ = 1; 
END
CASE(1)
	int S = 3; 
	int M = 3; 
	int _ = 2; 
END
CASE(2)
	int S = 3; 
	int M = 4; 
	int _ = -1; 
END
CASE(3)
	int S = 765; 
	int M = 271828; 
	int _ = 14; 
END
/*
CASE(4)
	int S = ; 
	int M = ; 
	int _ = ; 
END
CASE(5)
	int S = ; 
	int M = ; 
	int _ = ; 
END
*/
}
// END CUT HERE