Artifact cd08fa40861c2ec8bb428a49360d76ce7fd48556
#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 RepresentableNumbers { public:
int getNext(int X)
{
for(;; ++X) {
string s;
{stringstream sio; sio<<X; sio>>s;}
memo.clear();
memo.resize(200, -1);
if( rec(s, 0, false, false) )
return X;
if( s[0]=='1' ) {
if( rec(s, 1, false, true) )
return X;
}
}
assert(false);
}
vector<int> memo;
bool rec(const string& s, int i, bool mustUseBoth, bool needCarry)
{
if( i == (int)s.size() )
return !needCarry;
if( i+1 == (int)s.size() )
mustUseBoth = true;
int key = (i*2+mustUseBoth)*2+needCarry;
if( memo[key]>=0 )
return memo[key];
int t = (s[i]-'0') + (needCarry ? 10 : 0);
if( !mustUseBoth && (t==1 || t==3 || t==5 || t==7 || t==9) )
if( rec(s, i+1, false, false) )
return memo[key]=true;
if( !mustUseBoth && (t==2 || t==4 || t==6 || t==8 || t==10) )
if( rec(s, i+1, false, true) )
return memo[key]=true;
if( t<=1 )
return memo[key]=false;
if( t%2==0 )
return memo[key]=rec(s, i+1, true, false);
else
return memo[key]=rec(s, i+1, true, true);
}
};
// 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(_, RepresentableNumbers().getNext(X));}
int main(){
CASE(0)
int X = 1;
int _ = 2;
END
CASE(1)
int X = 999;
int _ = 1000;
END
CASE(2)
int X = 2000;
int _ = 2000;
END
CASE(3)
int X = 4201234;
int _ = 4222222;
END
CASE(4)
int X = 10101010;
int _ = 10102222;
END
CASE(5)
int X = 2;
int _ = 2;
END
CASE(5)
int X = 3;
int _ = 4;
END
CASE(5)
int X = 4;
int _ = 4;
END
CASE(5)
int X = 5;
int _ = 6;
END
CASE(5)
int X = 6;
int _ = 6;
END
CASE(5)
int X = 20;
int _ = 20;
END
CASE(6)
int X = 100000000;
int _ = -1;
END
CASE(6)
int X = 42012345;
int _ = -1;
END
CASE(6)
int X = 21999999;
int _ = -1;
END
}
// END CUT HERE