Artifact b77551cfbb4fa077d6d8b494ad109b14e641ca37
#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 LotteryCheating { public:
int minimalChange(string ID)
{
int minMod = ID.size();
for(LL x=0;; ++x)
{
string s;
{stringstream ss; ss << x*x; ss >> s;}
if( s.size() > ID.size() )
break;
s = string(ID.size()-s.size(),'0')+s;
int c = 0;
for(int i=0; i<ID.size(); ++i)
if( s[i] != ID[i] )
++c;
minMod = min(minMod, c);
}
return minMod;
}
};
// 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(_, LotteryCheating().minimalChange(ID));}
int main(){
CASE(0)
string ID = "1";
int _ = 0;
END
CASE(1)
string ID = "1234";
int _ = 2;
END
CASE(2)
string ID = "9000000000";
int _ = 1;
END
CASE(3)
string ID = "4294967296";
int _ = 0;
END
CASE(4)
string ID = "7654321";
int _ = 3;
END
CASE(5)
string ID = "2";
int _ = 1;
END
CASE(6)
string ID = "4";
int _ = 0;
END
CASE(7)
string ID = "8";
int _ = 1;
END
CASE(8)
string ID = "1111111111";
int _ = -1;
END
CASE(9)
string ID = "00201";
int _ = 1;
END
}
// END CUT HERE