Artifact 5e98535c0578c879d5c5d8793fc6be1f3eda7050
#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 PartisanGame { public:
string getWinner(int n, vector <int> a, vector <int> b)
{
return firstPlayerWin(n, a, b) ? "Alice" : "Bob";
}
bool firstPlayerWin(int n, const vector<int>& a, const vector<int>& b) {
vector<int> aw_bw;
aw_bw.push_back(0*2 + 0);
for (int k = 1; k <= 2000; ++k) {
int aw = 0;
for (int ai : a)
if (k - ai >= 0 && (aw_bw[k - ai] & 1) == 0)
aw = 1;
int bw = 0;
for (int bi : b)
if (k - bi >= 0 && (aw_bw[k - bi] & 2) == 0)
bw = 1;
aw_bw.push_back(aw * 2 + bw);
}
if (n < aw_bw.size()) {
return (aw_bw[n] & 2) != 0;
}
int z = int(aw_bw.size()) - 5;
for (int t = z - 1;; --t) {
if (equal(aw_bw.begin() + t, aw_bw.begin() + t + 5, aw_bw.begin() + z)) {
n = (n - t) % (z - t) + t;
return (aw_bw[n] & 2) != 0;
}
}
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 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(_, PartisanGame().getWinner(n, a, b));}
int main(){
CASE(0)
int n = 7;
int a_[] = {3, 4};
vector <int> a(a_, a_+sizeof(a_)/sizeof(*a_));
int b_[] = {4};
vector <int> b(b_, b_+sizeof(b_)/sizeof(*b_));
string _ = "Alice";
END
CASE(1)
int n = 10;
int a_[] = {1};
vector <int> a(a_, a_+sizeof(a_)/sizeof(*a_));
int b_[] = {4, 3, 2};
vector <int> b(b_, b_+sizeof(b_)/sizeof(*b_));
string _ = "Bob";
END
CASE(2)
int n = 104982;
int a_[] = {2, 3, 4, 5};
vector <int> a(a_, a_+sizeof(a_)/sizeof(*a_));
int b_[] = {2, 5};
vector <int> b(b_, b_+sizeof(b_)/sizeof(*b_));
string _ = "Alice";
END
CASE(3)
int n = 999999999;
int a_[] = {4};
vector <int> a(a_, a_+sizeof(a_)/sizeof(*a_));
int b_[] = {5};
vector <int> b(b_, b_+sizeof(b_)/sizeof(*b_));
string _ = "Bob";
END
CASE(4)
int n = 1000000000;
int a_[] = {1,2,3,4,5};
vector <int> a(a_, a_+sizeof(a_)/sizeof(*a_));
int b_[] = {1,2,3,4,5};
vector <int> b(b_, b_+sizeof(b_)/sizeof(*b_));
string _ = "Alice";
END
CASE(5)
int n = 0;
int a_[] = { 1 };
vector <int> a(a_, a_+sizeof(a_)/sizeof(*a_));
int b_[] = { 1 };
vector <int> b(b_, b_+sizeof(b_)/sizeof(*b_));
string _ = "Bob";
END
CASE(6)
int n = 1;
int a_[] = { 2,3,4 };
vector <int> a(a_, a_+sizeof(a_)/sizeof(*a_));
int b_[] = { 2 };
vector <int> b(b_, b_+sizeof(b_)/sizeof(*b_));
string _ = "Bob";
END
}
// END CUT HERE