File Annotation
Not logged in
b4af6486f6 2011-05-19        kinaba: #include <iostream>
b4af6486f6 2011-05-19        kinaba: #include <sstream>
b4af6486f6 2011-05-19        kinaba: #include <iomanip>
b4af6486f6 2011-05-19        kinaba: #include <vector>
b4af6486f6 2011-05-19        kinaba: #include <string>
b4af6486f6 2011-05-19        kinaba: #include <map>
b4af6486f6 2011-05-19        kinaba: #include <set>
b4af6486f6 2011-05-19        kinaba: #include <algorithm>
b4af6486f6 2011-05-19        kinaba: #include <numeric>
b4af6486f6 2011-05-19        kinaba: #include <iterator>
b4af6486f6 2011-05-19        kinaba: #include <functional>
b4af6486f6 2011-05-19        kinaba: #include <complex>
b4af6486f6 2011-05-19        kinaba: #include <queue>
b4af6486f6 2011-05-19        kinaba: #include <stack>
b4af6486f6 2011-05-19        kinaba: #include <cmath>
b4af6486f6 2011-05-19        kinaba: #include <cassert>
b4af6486f6 2011-05-19        kinaba: #include <cstring>
b4af6486f6 2011-05-19        kinaba: using namespace std;
b4af6486f6 2011-05-19        kinaba: typedef long long LL;
b4af6486f6 2011-05-19        kinaba: typedef complex<double> CMP;
b4af6486f6 2011-05-19        kinaba: 
b4af6486f6 2011-05-19        kinaba: class RectangleArea { public:
b4af6486f6 2011-05-19        kinaba: 	int minimumQueries(vector <string> known)
b4af6486f6 2011-05-19        kinaba: 	{
b4af6486f6 2011-05-19        kinaba: 		const int H = known.size();
b4af6486f6 2011-05-19        kinaba: 		const int W = known[0].size();
b4af6486f6 2011-05-19        kinaba: 		for(int y=0; y<H; ++y)
b4af6486f6 2011-05-19        kinaba: 		for(int x=0; x<W; ++x)
b4af6486f6 2011-05-19        kinaba: 		for(int Y=0; Y<H; ++Y)
b4af6486f6 2011-05-19        kinaba: 		for(int X=0; X<W; ++X)
b4af6486f6 2011-05-19        kinaba: 		if( make_pair(y,x) < make_pair(Y,X) && y!=Y && x!=X )
b4af6486f6 2011-05-19        kinaba: 		if( known[y][x]=='Y' && known[Y][X]=='Y' )
b4af6486f6 2011-05-19        kinaba: 		{
b4af6486f6 2011-05-19        kinaba: 			if( known[y][X]=='Y' )
b4af6486f6 2011-05-19        kinaba: 				known[Y][x] = 'Y';
b4af6486f6 2011-05-19        kinaba: 			if( known[Y][x]=='Y' )
b4af6486f6 2011-05-19        kinaba: 				known[y][X] = 'Y';
b4af6486f6 2011-05-19        kinaba: 		}
b4af6486f6 2011-05-19        kinaba: 
b4af6486f6 2011-05-19        kinaba: 		int tt = 0;
b4af6486f6 2011-05-19        kinaba: 		for(int i=0; i<W; ++i)
b4af6486f6 2011-05-19        kinaba: 			if( known[0][i]=='N' )
b4af6486f6 2011-05-19        kinaba: 				++tt;
b4af6486f6 2011-05-19        kinaba: 		int yy = 0;
b4af6486f6 2011-05-19        kinaba: 		for(int i=0; i<H; ++i)
b4af6486f6 2011-05-19        kinaba: 			if( known[i][0]=='N' )
b4af6486f6 2011-05-19        kinaba: 				++yy;
b4af6486f6 2011-05-19        kinaba: 		if( tt == 0 )
b4af6486f6 2011-05-19        kinaba: 			return yy;
b4af6486f6 2011-05-19        kinaba: 		if( yy == 0 )
b4af6486f6 2011-05-19        kinaba: 			return tt;
b4af6486f6 2011-05-19        kinaba: 		return -1;
b4af6486f6 2011-05-19        kinaba: 	}
b4af6486f6 2011-05-19        kinaba: };
b4af6486f6 2011-05-19        kinaba: 
b4af6486f6 2011-05-19        kinaba: // BEGIN CUT HERE
b4af6486f6 2011-05-19        kinaba: #include <ctime>
b4af6486f6 2011-05-19        kinaba: double start_time; string timer()
b4af6486f6 2011-05-19        kinaba:  { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); }
b4af6486f6 2011-05-19        kinaba: template<typename T> ostream& operator<<(ostream& os, const vector<T>& v)
b4af6486f6 2011-05-19        kinaba:  { os << "{ ";
b4af6486f6 2011-05-19        kinaba:    for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it)
b4af6486f6 2011-05-19        kinaba:    os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; }
b4af6486f6 2011-05-19        kinaba: void verify_case(const int& Expected, const int& Received) {
b4af6486f6 2011-05-19        kinaba:  bool ok = (Expected == Received);
b4af6486f6 2011-05-19        kinaba:  if(ok) cerr << "PASSED" << timer() << endl;  else { cerr << "FAILED" << timer() << endl;
b4af6486f6 2011-05-19        kinaba:  cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } }
b4af6486f6 2011-05-19        kinaba: #define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock();
b4af6486f6 2011-05-19        kinaba: #define END	 verify_case(_, RectangleArea().minimumQueries(known));}
b4af6486f6 2011-05-19        kinaba: int main(){
b4af6486f6 2011-05-19        kinaba: 
b4af6486f6 2011-05-19        kinaba: CASE(0)
b4af6486f6 2011-05-19        kinaba: 	string known_[] = {"NN",
b4af6486f6 2011-05-19        kinaba:  "NN"};
b4af6486f6 2011-05-19        kinaba: 	  vector <string> known(known_, known_+sizeof(known_)/sizeof(*known_));
b4af6486f6 2011-05-19        kinaba: 	int _ = 3;
b4af6486f6 2011-05-19        kinaba: END
b4af6486f6 2011-05-19        kinaba: CASE(1)
b4af6486f6 2011-05-19        kinaba: 	string known_[] = {"YNY",
b4af6486f6 2011-05-19        kinaba:  "NYN",
b4af6486f6 2011-05-19        kinaba:  "YNY"};
b4af6486f6 2011-05-19        kinaba: 	  vector <string> known(known_, known_+sizeof(known_)/sizeof(*known_));
b4af6486f6 2011-05-19        kinaba: 	int _ = 1;
b4af6486f6 2011-05-19        kinaba: END
b4af6486f6 2011-05-19        kinaba: CASE(2)
b4af6486f6 2011-05-19        kinaba: 	string known_[] = {"YY",
b4af6486f6 2011-05-19        kinaba:  "YY",
b4af6486f6 2011-05-19        kinaba:  "YY",
b4af6486f6 2011-05-19        kinaba:  "YY"};
b4af6486f6 2011-05-19        kinaba: 	  vector <string> known(known_, known_+sizeof(known_)/sizeof(*known_));
b4af6486f6 2011-05-19        kinaba: 	int _ = 0;
b4af6486f6 2011-05-19        kinaba: END
b4af6486f6 2011-05-19        kinaba: CASE(3)
b4af6486f6 2011-05-19        kinaba: 	string known_[] = {"NNNNNNNNNN"};
b4af6486f6 2011-05-19        kinaba: 	  vector <string> known(known_, known_+sizeof(known_)/sizeof(*known_));
b4af6486f6 2011-05-19        kinaba: 	int _ = 10;
b4af6486f6 2011-05-19        kinaba: END
b4af6486f6 2011-05-19        kinaba: CASE(4)
b4af6486f6 2011-05-19        kinaba: 	string known_[] = {"NNYYYNN",
b4af6486f6 2011-05-19        kinaba:  "NNNNNYN",
b4af6486f6 2011-05-19        kinaba:  "YYNNNNY",
b4af6486f6 2011-05-19        kinaba:  "NNNYNNN",
b4af6486f6 2011-05-19        kinaba:  "YYNNNNY"};
b4af6486f6 2011-05-19        kinaba: 	  vector <string> known(known_, known_+sizeof(known_)/sizeof(*known_));
b4af6486f6 2011-05-19        kinaba: 	int _ = 2;
b4af6486f6 2011-05-19        kinaba: END
b4af6486f6 2011-05-19        kinaba: CASE(5)
b4af6486f6 2011-05-19        kinaba: 	string known_[] = {
b4af6486f6 2011-05-19        kinaba: 		"NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN",
b4af6486f6 2011-05-19        kinaba: 		"NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN",
b4af6486f6 2011-05-19        kinaba: 		"NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN",
b4af6486f6 2011-05-19        kinaba: 		"NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN",
b4af6486f6 2011-05-19        kinaba: 		"NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN",
b4af6486f6 2011-05-19        kinaba: 		"NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN",
b4af6486f6 2011-05-19        kinaba: 		"NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN",
b4af6486f6 2011-05-19        kinaba: 		"NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN",
b4af6486f6 2011-05-19        kinaba: 		"NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN",
b4af6486f6 2011-05-19        kinaba: 		"NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN",
b4af6486f6 2011-05-19        kinaba: 		"NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN",
b4af6486f6 2011-05-19        kinaba: 		"NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN",
b4af6486f6 2011-05-19        kinaba: 		"NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN",
b4af6486f6 2011-05-19        kinaba: 		"NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN",
b4af6486f6 2011-05-19        kinaba: 		"NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN",
b4af6486f6 2011-05-19        kinaba: 		"NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN",
b4af6486f6 2011-05-19        kinaba: 		"NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN",
b4af6486f6 2011-05-19        kinaba: 		"NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN",
b4af6486f6 2011-05-19        kinaba: 		"NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN",
b4af6486f6 2011-05-19        kinaba: 		"NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN",
b4af6486f6 2011-05-19        kinaba: 		"NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN",
b4af6486f6 2011-05-19        kinaba: 		"NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN",
b4af6486f6 2011-05-19        kinaba: 		"NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN",
b4af6486f6 2011-05-19        kinaba: 		"NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN",
b4af6486f6 2011-05-19        kinaba: 		"NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN",
b4af6486f6 2011-05-19        kinaba: 		"NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN",
b4af6486f6 2011-05-19        kinaba: 		"NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN",
b4af6486f6 2011-05-19        kinaba: 		"NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN",
b4af6486f6 2011-05-19        kinaba: 		"NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN",
b4af6486f6 2011-05-19        kinaba: 		"NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN",
b4af6486f6 2011-05-19        kinaba: 		"NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN",
b4af6486f6 2011-05-19        kinaba: 		"NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN",
b4af6486f6 2011-05-19        kinaba: 		"NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN",
b4af6486f6 2011-05-19        kinaba: 		"NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN",
b4af6486f6 2011-05-19        kinaba: 		"NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN",
b4af6486f6 2011-05-19        kinaba: 		"NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN",
b4af6486f6 2011-05-19        kinaba: 		"NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN",
b4af6486f6 2011-05-19        kinaba: 		"NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN",
b4af6486f6 2011-05-19        kinaba: 		"NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN",
b4af6486f6 2011-05-19        kinaba: 		"NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN",
b4af6486f6 2011-05-19        kinaba: 		"NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN",
b4af6486f6 2011-05-19        kinaba: 		"NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN",
b4af6486f6 2011-05-19        kinaba: 		"NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN",
b4af6486f6 2011-05-19        kinaba: 		"NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN",
b4af6486f6 2011-05-19        kinaba: 		"NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN",
b4af6486f6 2011-05-19        kinaba: 		"NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN",
b4af6486f6 2011-05-19        kinaba: 		"NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN",
b4af6486f6 2011-05-19        kinaba: 		"NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN",
b4af6486f6 2011-05-19        kinaba: 		"NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN",
b4af6486f6 2011-05-19        kinaba: 		"NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN",
b4af6486f6 2011-05-19        kinaba: 	};
b4af6486f6 2011-05-19        kinaba: 	  vector <string> known(known_, known_+sizeof(known_)/sizeof(*known_));
b4af6486f6 2011-05-19        kinaba: 	int _ = -1;
b4af6486f6 2011-05-19        kinaba: END
b4af6486f6 2011-05-19        kinaba: CASE(6)
b4af6486f6 2011-05-19        kinaba: 	string known_[] = {"N"};
b4af6486f6 2011-05-19        kinaba: 	  vector <string> known(known_, known_+sizeof(known_)/sizeof(*known_));
b4af6486f6 2011-05-19        kinaba: 	int _ = 1;
b4af6486f6 2011-05-19        kinaba: END
b4af6486f6 2011-05-19        kinaba: 
b4af6486f6 2011-05-19        kinaba: }
b4af6486f6 2011-05-19        kinaba: // END CUT HERE