Artifact Content
Not logged in

Artifact c3946bd33dff056f52c38e3df61529b33378bbdd


#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 <cstring>
using namespace std;
typedef long long LL;
typedef complex<double> CMP;

class PlanarGraphShop { public:
	int bestCount(int N) 
	{
		set<int> possible;
		possible.insert(1*1*1 + 0*0);
		possible.insert(2*2*2 + 0*0);
		possible.insert(2*2*2 + 1*1);
		for(int V=3,EMax=3; V*V*V<=N; ++V,EMax+=3)
			for(int E=0; V*V*V+E*E<=N && E<=EMax; ++E)
				possible.insert(V*V*V + E*E);
		vector<int> p(possible.rbegin(), possible.rend());

		vector<int> q(1, 0);
		vector<bool> visited(N+1);
		for(int step=0 ;; ++step)
		{
			vector<int> q2;
			for(int i=0; i!=q.size(); ++i)
			{
				if( q[i] == N ) 
					return step;

				for(int j=0; j<p.size(); ++j)
				{
					int next = q[i] + p[j];
					if( next>N || visited[next] )
						continue;
					visited[next] = true;
					q2.push_back(next);
				}
			}
			q.swap(q2);
		}
		assert(false);
	}
};

// 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(_, PlanarGraphShop().bestCount(N));}
int main(){

CASE(0)
	int N = 36; 
	int _ = 1; 
END
CASE(1)
	int N = 7; 
	int _ = 7; 
END
CASE(2)
	int N = 72; 
	int _ = 2; 
END
CASE(3)
	int N = 46; 
	int _ = 3; 
END
CASE(4)
	int N = 50000; 
	int _ = -1; 
END
CASE(5)
	int N = 1; 
	int _ = 1; 
END
}
// END CUT HERE