Artifact Content
Not logged in

Artifact 2d20777071dc89c6347a11f59cd486a95774cc9f


#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>
using namespace std;
typedef long long LL;
typedef long double LD;
typedef complex<double> CMP;

int bitcnt(int x)
{
	int c = 0;
	for(; x; x>>=1)
		c += x&1;
	return c;
}

class YetAnotherANDProblem { public:
	string test(vector <int> X, int K, vector <int> queries)
	{
		string s;
		for(int i=0; i<queries.size(); ++i)
			s += (can(X, K, queries[i]) ? "+" : "-");
		return s;
	}

	bool can(const vector<int>& X, int K, int q)
	{
		int N = X.size();
		for(int mask=0; mask<(1<<N); ++mask)
		{
			int bc = bitcnt(mask);
			if(K==1 && bc==2 || K>=2 && 3<=bc && bc<=1LL<<K)
			{
				int num = 0x7fffffff;
				for(int i=0; i<N; ++i)
					if(mask & (1<<i))
						num &= X[i];
				if(num==q)
					return true;
			}
		}
		return 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(_, YetAnotherANDProblem().test(X, K, queries));}
int main(){

CASE(0)
	int X_[] = {10, 14, 7};
	  vector <int> X(X_, X_+sizeof(X_)/sizeof(*X_)); 
	int K = 1; 
	int queries_[] = {10, 14, 2, 4};
	  vector <int> queries(queries_, queries_+sizeof(queries_)/sizeof(*queries_)); 
	string _ = "+-+-"; 
END
CASE(1)
	int X_[] = {30, 29, 27, 23, 15};
	  vector <int> X(X_, X_+sizeof(X_)/sizeof(*X_)); 
	int K = 2; 
	int queries_[] = {28, 9, 16, 0, 12};
	  vector <int> queries(queries_, queries_+sizeof(queries_)/sizeof(*queries_)); 
	string _ = "-++-+"; 
END
CASE(2)
	int X_[] = {5, 5, 5, 5, 5};
	  vector <int> X(X_, X_+sizeof(X_)/sizeof(*X_)); 
	int K = 50; 
	int queries_[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
	  vector <int> queries(queries_, queries_+sizeof(queries_)/sizeof(*queries_)); 
	string _ = "-----+----"; 
END
CASE(3)
	int X_[] = {71258, 1257, 2592588, 2885851, 999928, 123456, 59881, 99999};
	  vector <int> X(X_, X_+sizeof(X_)/sizeof(*X_)); 
	int K = 4; 
	int queries_[] = {72, 91, 10, 0, 27, 64, 8};
	  vector <int> queries(queries_, queries_+sizeof(queries_)/sizeof(*queries_)); 
	string _ = "+--+-++"; 
END
/*
CASE(4)
	int X_[] = ;
	  vector <int> X(X_, X_+sizeof(X_)/sizeof(*X_)); 
	int K = ; 
	int queries_[] = ;
	  vector <int> queries(queries_, queries_+sizeof(queries_)/sizeof(*queries_)); 
	string _ = ; 
END
CASE(5)
	int X_[] = ;
	  vector <int> X(X_, X_+sizeof(X_)/sizeof(*X_)); 
	int K = ; 
	int queries_[] = ;
	  vector <int> queries(queries_, queries_+sizeof(queries_)/sizeof(*queries_)); 
	string _ = ; 
END
*/
}
// END CUT HERE