Artifact Content
Not logged in

Artifact e2301b523ba75830ec01c901132163a79b739a0d


#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 NowhereLand { public:
	int placeGuards(vector <string> cities, int k, vector <string> guards, vector <string> agencies) 
	{
		int mc = 0;
		for(int gid=0; gid<k; ++gid)
			mc += minimizeConflict(cities, guards, agencies, gid);
		return mc;
	}

	int minimizeConflict(vector<string>& C, vector<string>& G_, vector<string>& A_, int gid)
	{
		vector<bool> G(C.size());
		vector<bool> A(C.size());
		for(int i=0; i<C.size(); ++i)
		{
			{ stringstream sin(G_[i]);
			  for(int g; sin>>g; ) if(g==gid) G[i] = true; }
			{ stringstream sin(A_[i]);
			  for(int g; sin>>g; ) if(g==gid) A[i] = true; }
		}
		return -1;
	}
};

// 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(_, NowhereLand().placeGuards(cities, k, guards, agencies));}
int main(){

CASE(0)
	string cities_[] = { "0111",
  "1000",
  "1000",
  "1000" };
	  vector <string> cities(cities_, cities_+sizeof(cities_)/sizeof(*cities_)); 
	int k = 1; 
	string guards_[] = { "0", "", "", "" };
	  vector <string> guards(guards_, guards_+sizeof(guards_)/sizeof(*guards_)); 
	string agencies_[] = { "0", "0", "", "0" };
	  vector <string> agencies(agencies_, agencies_+sizeof(agencies_)/sizeof(*agencies_)); 
	int _ = 1; 
END
CASE(1)
	string cities_[] = { "011",
  "101",
  "110"  };
	  vector <string> cities(cities_, cities_+sizeof(cities_)/sizeof(*cities_)); 
	int k = 1; 
	string guards_[] = { "0", "", "" };
	  vector <string> guards(guards_, guards_+sizeof(guards_)/sizeof(*guards_)); 
	string agencies_[] = { "0", "", "" };
	  vector <string> agencies(agencies_, agencies_+sizeof(agencies_)/sizeof(*agencies_)); 
	int _ = 2; 
END
CASE(2)
	string cities_[] = { "011",
  "101",
  "110"  };
	  vector <string> cities(cities_, cities_+sizeof(cities_)/sizeof(*cities_)); 
	int k = 1; 
	string guards_[] = { "", "", "" }	;
	  vector <string> guards(guards_, guards_+sizeof(guards_)/sizeof(*guards_)); 
	string agencies_[] = { "0", "0", "0" };
	  vector <string> agencies(agencies_, agencies_+sizeof(agencies_)/sizeof(*agencies_)); 
	int _ = 0; 
END
CASE(3)
	string cities_[] = { "010100",
  "101100",
  "010011",
  "110010",
  "001100",
  "001000" };
	  vector <string> cities(cities_, cities_+sizeof(cities_)/sizeof(*cities_)); 
	int k = 3; 
	string guards_[] = { "1 2", "", "1", "", "0", "0" };
	  vector <string> guards(guards_, guards_+sizeof(guards_)/sizeof(*guards_)); 
	string agencies_[] = { "0 1 2", "0 1", "0 1 2", "1 2", "0", "0" };
	  vector <string> agencies(agencies_, agencies_+sizeof(agencies_)/sizeof(*agencies_)); 
	int _ = 7; 
END

}
// END CUT HERE