Artifact Content
Not logged in

Artifact f62c58c81f050ba2afa6170531576fb68b86fa22


#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 CarolsSinging {
public:
	int choose(vector <string> lyrics) 
	{
		int nP = lyrics.size();
		int nS = lyrics[0].size();
		vector<int> people_who_know_the_song(nS);
		for(int s=0; s<nS; ++s)
			for(int p=0; p<nP; ++p)
				people_who_know_the_song[s] |= (lyrics[p][s]=='Y')<<p;

		int minPop = nS;
		for(int m=1; m<(1<<nS); ++m)
		{
			int canSing = 0;
			for(int s=0; (1<<s)<=m; ++s)
				if( (1<<s) & m )
					canSing |= people_who_know_the_song[s];
			if( canSing == (1<<nP)-1 )
				minPop = min(minPop, __builtin_popcount(m));
		}
		return minPop;
	}
};

// 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> string print_array(const vector<T> &V) { ostringstream os; os << "{ "; for (typename vector<T>::const_iterator iter = V.begin(); iter != V.end(); ++iter) os << '\"' << *iter << "\","; os << " }"; return os.str(); }
int verify_case(const int &Expected, const int &Received) { if (Expected == Received) cerr << "PASSED" << timer() << endl; else { cerr << "FAILED" << timer() << endl; cerr << "\tExpected: \"" << Expected << '\"' << endl; cerr << "\tReceived: \"" << Received << '\"' << endl; } return 0;}

template<int N> struct Case_ { Case_(){start_time=clock();} };
char Test_(...);
int Test_(Case_<0>) {
	string lyrics_[] = {"YN","NY"};
	  vector <string> lyrics(lyrics_, lyrics_+sizeof(lyrics_)/sizeof(*lyrics_)); 
	int RetVal = 2; 
	return verify_case(RetVal, CarolsSinging().choose(lyrics)); }
int Test_(Case_<1>) {
	string lyrics_[] = {"YN","YY","YN"};
	  vector <string> lyrics(lyrics_, lyrics_+sizeof(lyrics_)/sizeof(*lyrics_)); 
	int RetVal = 1; 
	return verify_case(RetVal, CarolsSinging().choose(lyrics)); }
int Test_(Case_<2>) {
	string lyrics_[] = {"YNN","YNY","YNY","NYY","NYY","NYN"};
	  vector <string> lyrics(lyrics_, lyrics_+sizeof(lyrics_)/sizeof(*lyrics_)); 
	int RetVal = 2; 
	return verify_case(RetVal, CarolsSinging().choose(lyrics)); }
int Test_(Case_<3>) {
	string lyrics_[] = {"YNNYYY","YYNYYY","YNNYYN","NYYNNN","YYYNNN","YYYNNY","NYYYYY","NYNYYY","NNNNYY",
 "YYYYYY","YNNNNN","YYYYNY","YYNNNN","NNYYYN","NNNNYY","YYYNNN","NYNNYN","YNNYYN",
 "YYNNNY","NYYNNY","NNYYYN","YNYYYN","NNNYNY","YYYYNN","YYNYNN","NYYNYY","YYNYYN"};
	  vector <string> lyrics(lyrics_, lyrics_+sizeof(lyrics_)/sizeof(*lyrics_)); 
	int RetVal = 4; 
	return verify_case(RetVal, CarolsSinging().choose(lyrics)); }

template<int N> void Run_() { cerr << "Test Case #" << N << "..." << flush; Test_(Case_<N>()); Run_<sizeof(Test_(Case_<N+1>()))==1 ? -1 : N+1>(); }
template<>      void Run_<-1>() {}
int main() { Run_<0>(); }
// END CUT HERE