File Annotation
Not logged in
d948683958 2012-10-10        kinaba: #include <iostream>
d948683958 2012-10-10        kinaba: #include <sstream>
d948683958 2012-10-10        kinaba: #include <iomanip>
d948683958 2012-10-10        kinaba: #include <vector>
d948683958 2012-10-10        kinaba: #include <string>
d948683958 2012-10-10        kinaba: #include <map>
d948683958 2012-10-10        kinaba: #include <set>
d948683958 2012-10-10        kinaba: #include <algorithm>
d948683958 2012-10-10        kinaba: #include <numeric>
d948683958 2012-10-10        kinaba: #include <iterator>
d948683958 2012-10-10        kinaba: #include <functional>
d948683958 2012-10-10        kinaba: #include <complex>
d948683958 2012-10-10        kinaba: #include <queue>
d948683958 2012-10-10        kinaba: #include <stack>
d948683958 2012-10-10        kinaba: #include <cmath>
d948683958 2012-10-10        kinaba: #include <cassert>
d948683958 2012-10-10        kinaba: using namespace std;
d948683958 2012-10-10        kinaba: typedef long long LL;
d948683958 2012-10-10        kinaba: typedef long double LD;
d948683958 2012-10-10        kinaba: typedef complex<LD> CMP;
d948683958 2012-10-10        kinaba: 
efcf46f57b 2012-10-10        kinaba: class XorTravelingSalesman { public:
efcf46f57b 2012-10-10        kinaba: 	int maxProfit(vector <int> cityValues, vector <string> roads)
d948683958 2012-10-10        kinaba: 	{
efcf46f57b 2012-10-10        kinaba: 		vector< vector<bool> > vis(cityValues.size(), vector<bool>(1024, false));
efcf46f57b 2012-10-10        kinaba: 		rec(0, cityValues[0], cityValues, roads, vis);
efcf46f57b 2012-10-10        kinaba: 		int best = 0;
efcf46f57b 2012-10-10        kinaba: 		for(int p=0; p<cityValues.size(); ++p)
efcf46f57b 2012-10-10        kinaba: 			for(int v=0; v<1024; ++v)
efcf46f57b 2012-10-10        kinaba: 				if( vis[p][v] )
efcf46f57b 2012-10-10        kinaba: 					best = max(best, v);
efcf46f57b 2012-10-10        kinaba: 		return best;
d948683958 2012-10-10        kinaba: 	}
d948683958 2012-10-10        kinaba: 
efcf46f57b 2012-10-10        kinaba: 	void rec(int p, int value, const vector <int>& cityValues, const vector <string>& roads,
efcf46f57b 2012-10-10        kinaba: 		vector< vector<bool> >& vis)
d948683958 2012-10-10        kinaba: 	{
efcf46f57b 2012-10-10        kinaba: 		if(vis[p][value])
efcf46f57b 2012-10-10        kinaba: 			return;
efcf46f57b 2012-10-10        kinaba: 		vis[p][value] = true;
efcf46f57b 2012-10-10        kinaba: 		for(int q=0; q<cityValues.size(); ++q)
efcf46f57b 2012-10-10        kinaba: 			if(roads[p][q] == 'Y')
efcf46f57b 2012-10-10        kinaba: 				rec(q, value^cityValues[q], cityValues, roads, vis);
d948683958 2012-10-10        kinaba: 	}
d948683958 2012-10-10        kinaba: };
d948683958 2012-10-10        kinaba: 
d948683958 2012-10-10        kinaba: // BEGIN CUT HERE
d948683958 2012-10-10        kinaba: #include <ctime>
d948683958 2012-10-10        kinaba: double start_time; string timer()
d948683958 2012-10-10        kinaba:  { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); }
d948683958 2012-10-10        kinaba: template<typename T> ostream& operator<<(ostream& os, const vector<T>& v)
d948683958 2012-10-10        kinaba:  { os << "{ ";
d948683958 2012-10-10        kinaba:    for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it)
d948683958 2012-10-10        kinaba:    os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; }
efcf46f57b 2012-10-10        kinaba: void verify_case(const int& Expected, const int& Received) {
d948683958 2012-10-10        kinaba:  bool ok = (Expected == Received);
d948683958 2012-10-10        kinaba:  if(ok) cerr << "PASSED" << timer() << endl;  else { cerr << "FAILED" << timer() << endl;
d948683958 2012-10-10        kinaba:  cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } }
d948683958 2012-10-10        kinaba: #define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock();
efcf46f57b 2012-10-10        kinaba: #define END	 verify_case(_, XorTravelingSalesman().maxProfit(cityValues, roads));}
d948683958 2012-10-10        kinaba: int main(){
d948683958 2012-10-10        kinaba: 
d948683958 2012-10-10        kinaba: CASE(0)
efcf46f57b 2012-10-10        kinaba: 	int cityValues_[] = {0, 7, 11, 5, 2};
efcf46f57b 2012-10-10        kinaba: 	  vector <int> cityValues(cityValues_, cityValues_+sizeof(cityValues_)/sizeof(*cityValues_));
efcf46f57b 2012-10-10        kinaba: 	string roads_[] = {"NYNYY",
efcf46f57b 2012-10-10        kinaba:  "YNYNN",
efcf46f57b 2012-10-10        kinaba:  "NYNNN",
efcf46f57b 2012-10-10        kinaba:  "YNNNN",
efcf46f57b 2012-10-10        kinaba:  "YNNNN"};
efcf46f57b 2012-10-10        kinaba: 	  vector <string> roads(roads_, roads_+sizeof(roads_)/sizeof(*roads_));
efcf46f57b 2012-10-10        kinaba: 	int _ = 14;
d948683958 2012-10-10        kinaba: END
d948683958 2012-10-10        kinaba: CASE(1)
efcf46f57b 2012-10-10        kinaba: 	int cityValues_[] = {556};
efcf46f57b 2012-10-10        kinaba: 	  vector <int> cityValues(cityValues_, cityValues_+sizeof(cityValues_)/sizeof(*cityValues_));
efcf46f57b 2012-10-10        kinaba: 	string roads_[] = {"N"};
efcf46f57b 2012-10-10        kinaba: 	  vector <string> roads(roads_, roads_+sizeof(roads_)/sizeof(*roads_));
efcf46f57b 2012-10-10        kinaba: 	int _ = 556;
d948683958 2012-10-10        kinaba: END
d948683958 2012-10-10        kinaba: CASE(2)
efcf46f57b 2012-10-10        kinaba: 	int cityValues_[] = {0, 4, 8, 32, 512};
efcf46f57b 2012-10-10        kinaba: 	  vector <int> cityValues(cityValues_, cityValues_+sizeof(cityValues_)/sizeof(*cityValues_));
efcf46f57b 2012-10-10        kinaba: 	string roads_[] = {"NYYYY",
efcf46f57b 2012-10-10        kinaba:  "YNNNN",
efcf46f57b 2012-10-10        kinaba:  "YNNNN",
efcf46f57b 2012-10-10        kinaba:  "YNNNN",
efcf46f57b 2012-10-10        kinaba:  "YNNNN"};
efcf46f57b 2012-10-10        kinaba: 	  vector <string> roads(roads_, roads_+sizeof(roads_)/sizeof(*roads_));
efcf46f57b 2012-10-10        kinaba: 	int _ = 556;
d948683958 2012-10-10        kinaba: END
d948683958 2012-10-10        kinaba: CASE(3)
efcf46f57b 2012-10-10        kinaba: 	int cityValues_[] = {37, 1, 19, 64, 42, 41, 64, 64, 54, 16, 256, 36, 64, 2, 4, 2, 62, 29, 58, 64, 1, 32, 16,
efcf46f57b 2012-10-10        kinaba:  256, 17, 2, 17, 4, 1, 64, 21, 8, 256, 63, 3, 1, 43, 15, 8, 39, 41, 8, 16, 8, 16, 256, 64, 512, 45, 64};
efcf46f57b 2012-10-10        kinaba: 	  vector <int> cityValues(cityValues_, cityValues_+sizeof(cityValues_)/sizeof(*cityValues_));
efcf46f57b 2012-10-10        kinaba: 	string roads_[] = {"NNNNNNYYYYNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNN",
efcf46f57b 2012-10-10        kinaba:  "NNNNNNNNNNNNNNNNYNNNNNNNYNNNNNNNNNNNNNNNNYYNNNYYNN",
efcf46f57b 2012-10-10        kinaba:  "NNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN",
efcf46f57b 2012-10-10        kinaba:  "NNNNNNNYNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN",
efcf46f57b 2012-10-10        kinaba:  "NNNNNNNNNNNNNNNYNNYNYNNNNNNYNNNNNNNNNNYNNNNNNNNNNN",
efcf46f57b 2012-10-10        kinaba:  "NNYNNNYNNNNNNNNYNNYNNNYYNNNYNYNNNNYNNNNNNNNYNNNNNN",
efcf46f57b 2012-10-10        kinaba:  "YNYNNYNYNNNNNNNYNNNNNNNNNNNNNNNNNNNYNNNNNNNNYNNYNN",
efcf46f57b 2012-10-10        kinaba:  "YNNYNNYNYNYYNNNNNNNNNNNNNNNNNNNNNNYNNYNNNNNNNNNNNN",
efcf46f57b 2012-10-10        kinaba:  "YNNNNNNYNNNNNNNNNNNNNNYNYNNNNNNNNNNYYYNNNNNNNYNNNY",
efcf46f57b 2012-10-10        kinaba:  "YNNNNNNNNNNNNNNNNYNYNYNYYNNNYNNNNYNNNNNNNNNNNNNNNY",
efcf46f57b 2012-10-10        kinaba:  "NNNNNNNYNNNNYNNNNNNNNYYNNNYYNNNNYNYYNNNNNNNNNNNNNN",
efcf46f57b 2012-10-10        kinaba:  "NNNNNNNYNNNNNNYNNNNYYNNNYNNYYNNNNNNNNNNNNNYNYNNNNN",
efcf46f57b 2012-10-10        kinaba:  "NNNNNNNNNNYNNNNNYNNNNYNNNNNNNNNNYNYNNYNYNNNYNYNNNN",
efcf46f57b 2012-10-10        kinaba:  "NNNNNNNNNNNNNNNYNNNNNNNNNYNNNNNNNNNNNNYNNNNNNNNYNN",
efcf46f57b 2012-10-10        kinaba:  "NNNNNNNNNNNYNNNNNYNYNNYYNNNNNYNNNNNNNNNYNNYNNYNNNN",
efcf46f57b 2012-10-10        kinaba:  "NNNNYYYNNNNNNYNNNYYNNYNNNYNYYNNNNNNNNNYYYNNYNNYNYN",
efcf46f57b 2012-10-10        kinaba:  "NYNNNNNNNNNNYNNNNNNNYNNNYYNNNYNNNNYNNNNNNNNNNNNNNN",
efcf46f57b 2012-10-10        kinaba:  "NNNNNNNNNYNNNNYYNNNNNNYNNNYNNNNNYNNYNYYNNNNYNNNYNN",
efcf46f57b 2012-10-10        kinaba:  "NNNYYYNNNNNNNNNYNNNNNYNYNYNNNNNNNNYNNNNNNNNNNNNNNN",
efcf46f57b 2012-10-10        kinaba:  "NNNNNNNNNYNYNNYNNNNNNYNYYYNNNNNNNNNNNYNNYNNNNNYNNN",
efcf46f57b 2012-10-10        kinaba:  "NNNNYNNNNNNYNNNNYNNNNYNNNYYNNNYNNNYNNNNNNNNNNYNYNY",
efcf46f57b 2012-10-10        kinaba:  "NNNNNNNNNYYNYNNYNNYYYNYNNNNNNNNYNYNNNNNNNNNNYNNNNN",
efcf46f57b 2012-10-10        kinaba:  "NNNNNYNNYNYNNNYNNYNNNYNNNNNNNNNNNYNNYNYNNYNNNNNNNN",
efcf46f57b 2012-10-10        kinaba:  "NNNNNYNNNYNNNNYNNNYYNNNNNNNNNNNNNNNNNNNNNNYNNNYNNN",
efcf46f57b 2012-10-10        kinaba:  "NYNNNNNNYYNYNNNNYNNYNNNNNNNNNNYNNNNNNYNNNYNNYNNNNN",
efcf46f57b 2012-10-10        kinaba:  "NNNNNNNNNNNNNYNYYNYYYNNNNNNYNNNNNNNNNNNYYNNNNNNNYN",
efcf46f57b 2012-10-10        kinaba:  "NNNNNNNNNNYNNNNNNYNNYNNNNNNNNYNNNNYNNNNNNYYNNNNYNN",
efcf46f57b 2012-10-10        kinaba:  "NNNNYYNNNNYYNNNYNNNNNNNNNYNNNYYNYNNNNNNNNNNNNNNNNN",
efcf46f57b 2012-10-10        kinaba:  "NNNNNNNNNYNYNNNYNNNNNNNNNNNNNYNNNNYNNNNNNNNYNNYNYN",
efcf46f57b 2012-10-10        kinaba:  "NNNNNYNNNNNNNNYNYNNNNNNNNNYYYNNNNNNNNYNNNNYNNNNNNN",
efcf46f57b 2012-10-10        kinaba:  "NNNNNNNNNNNNNNNNNNNNYNNNYNNYNNNNNYNNNNNNNNNNNNNNNY",
efcf46f57b 2012-10-10        kinaba:  "NNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNYNNNNNNNNNYNNNNNNN",
efcf46f57b 2012-10-10        kinaba:  "NNNNNNNNNNYNYNNNNYNNNNNNNNNYNNNYNNNYYNNNNNYNNNYNNN",
efcf46f57b 2012-10-10        kinaba:  "NNNNNNNNNYNNNNNNNNNNNYYNNNNNNNYNNNNNNNYNNYNNNNNNNN",
efcf46f57b 2012-10-10        kinaba:  "NNNNNYNYNNYNYNNNYNYNYNNNNNYNYNNNNNNYYNYNYNYNNNNNYN",
efcf46f57b 2012-10-10        kinaba:  "YNNNNNYNYNYNNNNNNYNNNNNNNNNNNNNNYNYNNNNNYNNYNNNYNN",
efcf46f57b 2012-10-10        kinaba:  "NNNNNNNNYNNNNNNNNNNNNNYNNNNNNNNNYNYNNNNNNYNNNNNNYN",
efcf46f57b 2012-10-10        kinaba:  "NNNNNNNYYNNNYNNNNYNYNNNNYNNNNYNNNNNNNNNNNYNNNNYNNN",
efcf46f57b 2012-10-10        kinaba:  "NNNNYNNNNNNNNYNYNYNNNNYNNNNNNNNNNYYNNNNYNNNNNNNNNY",
efcf46f57b 2012-10-10        kinaba:  "NNNNNNNNNNNNYNYYNNNNNNNNNYNNNNNNNNNNNNYNNNNNYNYYNN",
efcf46f57b 2012-10-10        kinaba:  "NNNNNNNNNNNNNNNYNNNYNNNNNYNNNNNNNNYYNNNNNNNNNNNNNN",
efcf46f57b 2012-10-10        kinaba:  "NYNNNNNNNNNNNNNNNNNNNNYNYNYNNNNNNYNNYYNNNNNNNNNNNN",
efcf46f57b 2012-10-10        kinaba:  "NYNNNNNNNNNYNNYNNNNNNNNYNNYNNYNYYNYNNNNNNNNNYNNNNN",
efcf46f57b 2012-10-10        kinaba:  "NNNNNYNNNNNNYNNYNYNNNNNNNNNNYNNNNNNYNNNNNNNNNNNNNY",
efcf46f57b 2012-10-10        kinaba:  "NNNNNNYNNNNYNNNNNNNNNYNNYNNNNNNNNNNNNNNYNNYNNYNNNY",
efcf46f57b 2012-10-10        kinaba:  "NNNNNNNNYNNNYNYNNNNNYNNNNNNNNNNNNNNNNNNNNNNNYNNNNN",
efcf46f57b 2012-10-10        kinaba:  "NYNNNNNNNNNNNNNYNNNYNNNYNNNNYNNNYNNNNYNYNNNNNNNNNN",
efcf46f57b 2012-10-10        kinaba:  "NYNNNNYNNNNNNYNNNYNNYNNNNNYNNNNNNNNYNNNYNNNNNNNNNN",
efcf46f57b 2012-10-10        kinaba:  "NNNNNNNNNNNNNNNYNNNNNNNNNYNNYNNNNNYNYNNNNNNNNNNNNN",
efcf46f57b 2012-10-10        kinaba:  "NNNNNNNNYYNNNNNNNNNNYNNNNNNNNNYNNNNNNNYNNNNYYNNNNN"};
efcf46f57b 2012-10-10        kinaba: 	  vector <string> roads(roads_, roads_+sizeof(roads_)/sizeof(*roads_));
efcf46f57b 2012-10-10        kinaba: 	int _ = 895;
d948683958 2012-10-10        kinaba: END
efcf46f57b 2012-10-10        kinaba: /*
d948683958 2012-10-10        kinaba: CASE(4)
efcf46f57b 2012-10-10        kinaba: 	int cityValues_[] = ;
efcf46f57b 2012-10-10        kinaba: 	  vector <int> cityValues(cityValues_, cityValues_+sizeof(cityValues_)/sizeof(*cityValues_));
efcf46f57b 2012-10-10        kinaba: 	string roads_[] = ;
efcf46f57b 2012-10-10        kinaba: 	  vector <string> roads(roads_, roads_+sizeof(roads_)/sizeof(*roads_));
efcf46f57b 2012-10-10        kinaba: 	int _ = ;
d948683958 2012-10-10        kinaba: END
d948683958 2012-10-10        kinaba: CASE(5)
efcf46f57b 2012-10-10        kinaba: 	int cityValues_[] = ;
efcf46f57b 2012-10-10        kinaba: 	  vector <int> cityValues(cityValues_, cityValues_+sizeof(cityValues_)/sizeof(*cityValues_));
efcf46f57b 2012-10-10        kinaba: 	string roads_[] = ;
efcf46f57b 2012-10-10        kinaba: 	  vector <string> roads(roads_, roads_+sizeof(roads_)/sizeof(*roads_));
efcf46f57b 2012-10-10        kinaba: 	int _ = ;
d948683958 2012-10-10        kinaba: END
efcf46f57b 2012-10-10        kinaba: */
d948683958 2012-10-10        kinaba: }
d948683958 2012-10-10        kinaba: // END CUT HERE