Artifact Content
Not logged in

Artifact a62787f87989e0f0859b48cff263b8eba687c313


#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 OneRegister { public:
	string getProgram(int s, int t) 
	{
		string x = run("",s,t);
		string y = run("/",1, t);
		string z = takeMin(x,y);
		return z=="NO" ? ":-(" : z;
	}

	string takeMin(const string& x, const string& y)
	{
		if( x == "NO" )
			return y;
		else if( y == "NO" )
			return x;
		else
			return (x.size()<y.size() ? x : (x.size()==y.size() ? min(x,y) : y));
	}

	// by using only '*' and '+'
	string run(const string& buf, LL s, LL t)
	{
		if( s == t )
			return buf;
		if( s > t )
			return "NO";
		string x = run(buf+"+", s+s, t);
		string y = (s==1 ? "NO" : run(buf+"*", s*s, t));
		return takeMin(x,y);
	}
};

// 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 string& Expected, const string& 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(_, OneRegister().getProgram(s, t));}
int main(){

CASE(0)
	int s = 7; 
	int t = 392; 
	string _ = "+*+"; 
END
CASE(1)
	int s = 7; 
	int t = 256; 
	string _ = "/+***"; 
END
CASE(2)
	int s = 4; 
	int t = 256; 
	string _ = "**"; 
END
CASE(3)
	int s = 7; 
	int t = 7; 
	string _ = ""; 
END
CASE(4)
	int s = 7; 
	int t = 9; 
	string _ = ":-("; 
END
CASE(5)
	int s = 10; 
	int t = 1; 
	string _ = "/"; 
END
CASE(6)
	int s = 1; 
	int t = 1000000000; 
	string _ = "dummy"; 
END
CASE(6)
	int s = 2; 
	int t = 1<<30; 
	string _ = "dummy"; 
END
CASE(7)
	int s = 1000000000; 
	int t = 1; 
	string _ = "dummy"; 
END
CASE(8)
	int s = 1; 
	int t = 1; 
	string _ = ""; 
END
CASE(9)
	int s = 2; 
	int t = 2; 
	string _ = ""; 
END
CASE(10)
	int s = 1; 
	int t = 2; 
	string _ = "+"; 
END
CASE(11)
	int s = 512; 
	int t = 65536; 
	string _ = "*"; 
END

}
// END CUT HERE