CSES - Datatähti 2016 alku - Results
Submission details
Task:Tontti
Sender:BigKappa
Submission time:2015-10-11 18:34:21 +0300
Language:C++
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:19:70: error: 'memset' was not declared in this scope
  memset(memeArray, false, (height+1)*(width+1)*(maxS+2)*sizeof(bool*));
                                                                      ^

Code

#include <iostream>
#include <string>
#include <algorithm>

int** sumArray;
bool* memeArray;
int height;
int width;
int treesWanted;
int out = 0;
int countTrees(int x, int y, int s);
int maxS;
void search(int roiX1, int roiY1, int roiX2, int roiY2, int s);

int main() {
	std::cin >> height >> width >> treesWanted >> std::ws;
	maxS = std::min(width - 1, height - 1);
	memeArray = new bool[(height+1)*(width+1)*(maxS+2)];
	memset(memeArray, false, (height+1)*(width+1)*(maxS+2)*sizeof(bool*));
	sumArray = new int*[height];
	{
		std::string line;
		int currentRowSum = 0;
		for (int y = 0; y < height; y++) {
			sumArray[y] = new int[width];
			memset(sumArray[y], 0, width*sizeof(sumArray[y]));
			std::getline(std::cin, line);
			currentRowSum = 0;
			for (int x = 0; x < width; x++) {
				if (line[x] == '*') {
					currentRowSum++;
				}
				sumArray[y][x] = sumArray[std::max(0, y - 1)][x] + currentRowSum;
			}
		}
	}
	search(0, 0, width - 1, height - 1, maxS);
	std::cout << out;
	//getchar();
	return 0;
}

void search(int roiX1, int roiY1, int roiX2, int roiY2, int s) {
	int c;
	for (int y = roiY1; y <= roiY2 - s; y++) {
		for (int x = roiX1; x <= roiX2 - s; x++) {
			c = countTrees(x, y, s);
			//std::cout << c << std::endl;
			if (c > treesWanted && s > 0) search(x, y, x + s, y + s, s - 1);
			else if (c == treesWanted && !memeArray[(y+1)*width*height+(x+1)*height+maxS]) {
				//std::cout << "x: " << x << "  y: " << y << "  s: " << s << std::endl;
				memeArray[(y + 1)*width*height + (x + 1)*height + maxS] = true;
				out++;
				if (s > 0) {
					search(x, y, x + s, y + s, s - 1);
				}
			}
		}
	}
}

int countTrees(int x, int y, int s) {
	int trees = sumArray[y + s][x + s];
	if (x != 0) trees -= sumArray[y + s][x - 1];
	if (y != 0) trees -= sumArray[y - 1][x + s];
	if (x != 0 && y != 0) trees += sumArray[y-1][x-1];
	return trees;
}