47a150c34b 2015-10-14 kinaba: #include <iostream> 47a150c34b 2015-10-14 kinaba: #include <sstream> 47a150c34b 2015-10-14 kinaba: #include <iomanip> 47a150c34b 2015-10-14 kinaba: #include <vector> 47a150c34b 2015-10-14 kinaba: #include <string> 47a150c34b 2015-10-14 kinaba: #include <map> 47a150c34b 2015-10-14 kinaba: #include <set> 47a150c34b 2015-10-14 kinaba: #include <algorithm> 47a150c34b 2015-10-14 kinaba: #include <numeric> 47a150c34b 2015-10-14 kinaba: #include <iterator> 47a150c34b 2015-10-14 kinaba: #include <functional> 47a150c34b 2015-10-14 kinaba: #include <complex> 47a150c34b 2015-10-14 kinaba: #include <queue> 47a150c34b 2015-10-14 kinaba: #include <stack> 47a150c34b 2015-10-14 kinaba: #include <cmath> 47a150c34b 2015-10-14 kinaba: #include <cassert> 47a150c34b 2015-10-14 kinaba: #include <tuple> 47a150c34b 2015-10-14 kinaba: using namespace std; 47a150c34b 2015-10-14 kinaba: typedef long long LL; 47a150c34b 2015-10-14 kinaba: typedef complex<double> CMP; 47a150c34b 2015-10-14 kinaba: 47a150c34b 2015-10-14 kinaba: class SubdividedSlimes { public: 47a150c34b 2015-10-14 kinaba: int needCut(int S, int M) 47a150c34b 2015-10-14 kinaba: { 47a150c34b 2015-10-14 kinaba: int L=0, R=S; 47a150c34b 2015-10-14 kinaba: while(R-L>1) { 47a150c34b 2015-10-14 kinaba: int C = (L+R)/2; 47a150c34b 2015-10-14 kinaba: (maxScore(S, C) >= M ? R : L) = C; 47a150c34b 2015-10-14 kinaba: } 47a150c34b 2015-10-14 kinaba: return R==S ? -1 : R; 47a150c34b 2015-10-14 kinaba: } 47a150c34b 2015-10-14 kinaba: 47a150c34b 2015-10-14 kinaba: LL maxScore(int S, int Turn) { 47a150c34b 2015-10-14 kinaba: LL score = 0; 47a150c34b 2015-10-14 kinaba: 47a150c34b 2015-10-14 kinaba: multiset<int, greater<int>> X; 47a150c34b 2015-10-14 kinaba: X.insert(S); 47a150c34b 2015-10-14 kinaba: for(int t=0; t<Turn && *X.begin()>1; ++t) { 47a150c34b 2015-10-14 kinaba: int V = *X.begin(), U = V/2; 47a150c34b 2015-10-14 kinaba: X.erase(X.begin()); 47a150c34b 2015-10-14 kinaba: score += U*(V-U); 47a150c34b 2015-10-14 kinaba: X.insert(U); 47a150c34b 2015-10-14 kinaba: X.insert(V-U); 47a150c34b 2015-10-14 kinaba: } 47a150c34b 2015-10-14 kinaba: return score; 47a150c34b 2015-10-14 kinaba: } 47a150c34b 2015-10-14 kinaba: }; 47a150c34b 2015-10-14 kinaba: 47a150c34b 2015-10-14 kinaba: // BEGIN CUT HERE 47a150c34b 2015-10-14 kinaba: #include <ctime> 47a150c34b 2015-10-14 kinaba: double start_time; string timer() 47a150c34b 2015-10-14 kinaba: { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); } 47a150c34b 2015-10-14 kinaba: template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) 47a150c34b 2015-10-14 kinaba: { os << "{ "; 47a150c34b 2015-10-14 kinaba: for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it) 47a150c34b 2015-10-14 kinaba: os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; } 47a150c34b 2015-10-14 kinaba: void verify_case(const int& Expected, const int& Received) { 47a150c34b 2015-10-14 kinaba: bool ok = (Expected == Received); 47a150c34b 2015-10-14 kinaba: if(ok) cerr << "PASSED" << timer() << endl; else { cerr << "FAILED" << timer() << endl; 47a150c34b 2015-10-14 kinaba: cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } } 47a150c34b 2015-10-14 kinaba: #define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock(); 47a150c34b 2015-10-14 kinaba: #define END verify_case(_, SubdividedSlimes().needCut(S, M));} 47a150c34b 2015-10-14 kinaba: int main(){ 47a150c34b 2015-10-14 kinaba: 47a150c34b 2015-10-14 kinaba: CASE(0) 47a150c34b 2015-10-14 kinaba: int S = 3; 47a150c34b 2015-10-14 kinaba: int M = 2; 47a150c34b 2015-10-14 kinaba: int _ = 1; 47a150c34b 2015-10-14 kinaba: END 47a150c34b 2015-10-14 kinaba: CASE(1) 47a150c34b 2015-10-14 kinaba: int S = 3; 47a150c34b 2015-10-14 kinaba: int M = 3; 47a150c34b 2015-10-14 kinaba: int _ = 2; 47a150c34b 2015-10-14 kinaba: END 47a150c34b 2015-10-14 kinaba: CASE(2) 47a150c34b 2015-10-14 kinaba: int S = 3; 47a150c34b 2015-10-14 kinaba: int M = 4; 47a150c34b 2015-10-14 kinaba: int _ = -1; 47a150c34b 2015-10-14 kinaba: END 47a150c34b 2015-10-14 kinaba: CASE(3) 47a150c34b 2015-10-14 kinaba: int S = 765; 47a150c34b 2015-10-14 kinaba: int M = 271828; 47a150c34b 2015-10-14 kinaba: int _ = 14; 47a150c34b 2015-10-14 kinaba: END 47a150c34b 2015-10-14 kinaba: /* 47a150c34b 2015-10-14 kinaba: CASE(4) 47a150c34b 2015-10-14 kinaba: int S = ; 47a150c34b 2015-10-14 kinaba: int M = ; 47a150c34b 2015-10-14 kinaba: int _ = ; 47a150c34b 2015-10-14 kinaba: END 47a150c34b 2015-10-14 kinaba: CASE(5) 47a150c34b 2015-10-14 kinaba: int S = ; 47a150c34b 2015-10-14 kinaba: int M = ; 47a150c34b 2015-10-14 kinaba: int _ = ; 47a150c34b 2015-10-14 kinaba: END 47a150c34b 2015-10-14 kinaba: */ 47a150c34b 2015-10-14 kinaba: } 47a150c34b 2015-10-14 kinaba: // END CUT HERE