Artifact Content
Not logged in

Artifact 12cbf48a8719e3170b2429dbc09b4430e2c5a5af


#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<LD> CMP;

class StringGame { public:
	vector <int> getWinningStrings(vector <string> S)
	{
		vector< vector<int> > cb;
		for(int i=0; i<S.size(); ++i)
			cb.push_back(as_cb(S[i]));

		vector<int> result;
		for(int i=0; i<cb.size(); ++i)
			if( can_win(cb, i) )
				result.push_back(i);
		return result;
	}

	vector<int> as_cb(const string& s)
	{
		vector<int> cb(26);
		for(int i=0; i<s.size(); ++i)
			cb[s[i]-'a']++;
		return cb;
	}

	bool can_win(const vector< vector<int> >& cb, int I)
	{
		vector<int> enemy;
		for(int i=0; i<cb.size(); ++i)
			if(i != I)
				enemy.push_back(i);

		while(!enemy.empty())
		{
			bool update = false;
			for(int c=0; c<26; ++c)
			{
				vector<int> win, draw;
				for(int i=0; i<enemy.size(); ++i)
				{
					int e = enemy[i];
					if(cb[e][c] < cb[I][c])
						win.push_back(e);
					else if(cb[e][c] == cb[I][c])
						draw.push_back(e);
				}
				if(!win.empty() && win.size() + draw.size() == enemy.size()) {
					enemy = draw;
					update = true;
				}
			}
			if(!update)
				return false;
		}

		return true;
	}
};

// 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 vector <int>& Expected, const vector <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(_, StringGame().getWinningStrings(S));}
int main(){

CASE(0)
	string S_[] = {"a", "b", "c", "d"};
	  vector <string> S(S_, S_+sizeof(S_)/sizeof(*S_)); 
	int __[] = {0, 1, 2, 3 };
	  vector <int> _(__, __+sizeof(__)/sizeof(*__)); 
END
CASE(1)
	string S_[] = {"aabbcc", "aaabbb", "aaaccc"};
	  vector <string> S(S_, S_+sizeof(S_)/sizeof(*S_)); 
	int __[] = {1, 2 };
	  vector <int> _(__, __+sizeof(__)/sizeof(*__)); 
END
CASE(2)
	string S_[] = {"ab", "ba"};
	  vector <string> S(S_, S_+sizeof(S_)/sizeof(*S_)); 
	vector <int> _; 
END
CASE(3)
	string S_[] = {"xaocxsss", "oooxsoas", "xaooosss", "xaocssss", "coxaosxx"};
	  vector <string> S(S_, S_+sizeof(S_)/sizeof(*S_)); 
	int __[] = {1, 3, 4 };
	  vector <int> _(__, __+sizeof(__)/sizeof(*__)); 
END
CASE(4)
string S_[] = {"aaabbc", "aabbcc", "aaaabc"};
	  vector <string> S(S_, S_+sizeof(S_)/sizeof(*S_)); 
	  int __[] = {0, 1, 2};
	  vector <int> _(__, __+sizeof(__)/sizeof(*__)); 
END
/*
CASE(5)
	string S_[] = ;
	  vector <string> S(S_, S_+sizeof(S_)/sizeof(*S_)); 
	int __[] = ;
	  vector <int> _(__, __+sizeof(__)/sizeof(*__)); 
END
*/
}
// END CUT HERE