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