Artifact Content
Not logged in

Artifact f6f063e1572c0239f78f31d25025c9ae1f13ebab


#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 HyperKnight { public:
	long long countCells(int a_, int b_, int numRows, int numColumns, int K)
	{
		if(a_>b_) swap(a_,b_);
		const LL A=a_, B=b_, W=numRows, H=numColumns;

		LL xx[] = {0, A, B, W-B, W-A, W};
		LL yy[] = {0, A, B, H-B, H-A, H};
		LL dx[] = {+A, +A, -A, -A, +B, +B, -B, -B};
		LL dy[] = {+B, -B, +B, -B, +A, -A, +A, -A};

		LL cnt = 0;
		for(int i=0; i+1<sizeof(xx)/sizeof(*xx); ++i)
		for(int k=0; k+1<sizeof(yy)/sizeof(*yy); ++k) {
			LL w = xx[i+1]-xx[i], x = xx[i];
			LL h = yy[k+1]-yy[k], y = yy[k];
			int av = 0;
			for(int j=0; j<8; ++j) {
				LL x2 = x + dx[j];
				LL y2 = y + dy[j];
				if(0<=x2 && x2<W && 0<=y2&&y2<H)
					++av;
			}
			if(av==K)
				cnt += w*h;
		}
		return cnt;
	}
};

// 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 long long& Expected, const long long& 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(_, HyperKnight().countCells(a, b, numRows, numColumns, k));}
int main(){

CASE(0)
	int a = 2; 
	int b = 1; 
	int numRows = 8; 
	int numColumns = 8; 
	int k = 4; 
	long long _ = 20LL; 
END
CASE(1)
	int a = 3; 
	int b = 2; 
	int numRows = 8; 
	int numColumns = 8; 
	int k = 2; 
	long long _ = 16LL; 
END
CASE(2)
	int a = 1; 
	int b = 3; 
	int numRows = 7; 
	int numColumns = 11; 
	int k = 0; 
	long long _ = 0LL; 
END
CASE(3)
	int a = 3; 
	int b = 2; 
	int numRows = 10; 
	int numColumns = 20; 
	int k = 8; 
	long long _ = 56LL; 
END
CASE(4)
	int a = 1; 
	int b = 4; 
	int numRows = 100; 
	int numColumns = 10; 
	int k = 6; 
	long long _ = 564LL; 
END
CASE(5)
	int a = 2; 
	int b = 3; 
	int numRows = 1000000000; 
	int numColumns = 1000000000; 
	int k = 8; 
	long long _ = 999999988000000036LL; 
END
/*
CASE(6)
	int a = ; 
	int b = ; 
	int numRows = ; 
	int numColumns = ; 
	int k = ; 
	long long _ = LL; 
END
CASE(7)
	int a = ; 
	int b = ; 
	int numRows = ; 
	int numColumns = ; 
	int k = ; 
	long long _ = LL; 
END
*/
}
// END CUT HERE