Artifact Content
Not logged in

Artifact 4fe2b90f4373a0794ecdd27b5d11c1f3f498a8b2


#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 Squares { public:
	int countSquares(vector <string> field) 
	{
		const int H = field.size();
		const int W = field[0].size();

		int cnt = 0;
		for(int y=0; y<H; ++y)
		for(int x=0; x<W; ++x)
			for(int y2=0; y2<H; ++y2)
			for(int x2=0; x2<W; ++x2) if( y!=y2 || x!=x2 )
			{
				char c = field[y][x];
				int x3 = x+(y2-y);
				int y3 = y-(x2-x);
				int x4 = x3+(x2-x);
				int y4 = y3+(y2-y);
				if( 0<=x3 && x3<W && 0<=y3 && y3<H )
				if( 0<=x4 && x4<W && 0<=y4 && y4<H )
				if( field[y2][x2]==c && field[y3][x3]==c && field[y4][x4]==c )
					++cnt;
			}
		return cnt/4;
	}
};

// 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 int& Expected, const 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(_, Squares().countSquares(field));}
int main(){

CASE(0)
	string field_[] = {"ABA", "BAB", "ABA"};
	  vector <string> field(field_, field_+sizeof(field_)/sizeof(*field_)); 
	int _ = 2; 
END
CASE(1)
	string field_[] = {"AA", "AA"};
	  vector <string> field(field_, field_+sizeof(field_)/sizeof(*field_)); 
	int _ = 1; 
END
CASE(2)
	string field_[] = {"ABC", "DEF", "GHI"};
	  vector <string> field(field_, field_+sizeof(field_)/sizeof(*field_)); 
	int _ = 0; 
END
CASE(3)
	string field_[] = {"AABCA", "AAAAA", "BAAAB", "AAAEA", "ADBFA"};
	  vector <string> field(field_, field_+sizeof(field_)/sizeof(*field_)); 
	int _ = 11; 
END
/*
CASE(4)
	string field_[] = ;
	  vector <string> field(field_, field_+sizeof(field_)/sizeof(*field_)); 
	int _ = ; 
END
CASE(5)
	string field_[] = ;
	  vector <string> field(field_, field_+sizeof(field_)/sizeof(*field_)); 
	int _ = ; 
END
*/
}
// END CUT HERE