Artifact b81d85fd8b288dc7db108139bb24c0fa4eaf0ae5
#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 <tuple>
using namespace std;
typedef long long LL;
typedef complex<double> CMP;
class PowerOfThree { public:
string ableToGet(int x_, int y_)
{
LL x=x_, y=y_;
for(LL tk=1;; tk*=3)
{
if(x==0 && y==0)
break;
LL xr = ((x/tk)%3+3)%3;
LL yr = ((y/tk)%3+3)%3;
if(xr==1 && yr==0) x-=tk;
else if(xr==2 && yr==0) x+=tk;
else if(xr==0 && yr==1) y-=tk;
else if(xr==0 && yr==2) y+=tk;
else return "Impossible";
}
return "Possible";
}
};
// 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(_, PowerOfThree().ableToGet(x, y));}
int main(){
CASE(0)
int x = 1;
int y = 3;
string _ = "Possible";
END
CASE(1)
int x = 0;
int y = 2;
string _ = "Possible";
END
CASE(2)
int x = 1;
int y = 9;
string _ = "Impossible";
END
CASE(3)
int x = 3;
int y = 0;
string _ = "Impossible";
END
CASE(4)
int x = 1;
int y = 1;
string _ = "Impossible";
END
CASE(5)
int x = -6890;
int y = 18252;
string _ = "Possible";
END
CASE(6)
int x = 1000000000;
int y = -1000000000;
string _ = "Impossible";
END
CASE(7)
int x = 0;
int y = 0;
string _ = "Possible";
END
CASE(8)
int x = 8;
int y = 3;
string _ = "P";
END
CASE(9)
// -3^0 - 3^1 - ... - 3^18 + 3^19
// NOTE: 3^19 = 1162261467 > 10^9
int x = 581130734;
int y = 0;
string _ = "P";
END
}
// END CUT HERE