Rezultati

Up. imeNalogaJezikRezultatČas oddaje
attempterji-2019 Gozdovi C++ 100/100OK 24. apr '19 @ 19:09

Test Točke Porabljen spomin Porabljen čas Status
#1 [več] 10/10 18,457 MiB 0,000 s OK
#2 [več] 10/10 18,766 MiB 0,016 s OK
#3 [več] 10/10 18,395 MiB 0,070 s OK
#4 [več] 10/10 18,582 MiB 0,022 s OK
#5 [več] 10/10 18,305 MiB 0,000 s OK
#6 [več] 10/10 19,527 MiB 0,034 s OK
#7 [več] 10/10 18,508 MiB 0,026 s OK
#8 [več] 10/10 18,496 MiB 0,027 s OK
#9 [več] 10/10 18,504 MiB 0,021 s OK
#10 [več] 10/10 18,367 MiB 0,026 s OK

Ocenjevani program (upm_2019_1_gozd.cpp):
#include <iostream>
#include <vector>
#include <cstring>
#include <sstream>
#include <algorithm>

using namespace std;

int m1, n1;




void preveri(int i, int j, string *gozd, string *prebrano, int m, int n) {
	/*
	cout << "V preveri\n";
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < m; ++j) {
			cout << gozd[i][j];
		}
		cout << "\n";
	}
	cout << "\n";
	*/
	prebrano[i][j] = '1';
	char x = gozd[i][j];
	if (i + 1 >= 0 && j >= 0 && j < m && i + 1 < n && gozd[i + 1][j] == x && prebrano[i + 1][j] == '0')
		preveri(i + 1, j, gozd, prebrano, m, n);
	if (i >= 0 && j + 1 >= 0 && j + 1 < m && i < n && gozd[i][j + 1] == x && prebrano[i][j + 1] == '0')
		preveri(i, j + 1, gozd, prebrano, m, n);
	if (i + 1 >= 0 && j + 1 >= 0 && j + 1 < m && i + 1 < n && gozd[i + 1][j + 1] == x && prebrano[i + 1][j + 1] == '0')
		preveri(i + 1, j + 1, gozd, prebrano, m, n);
	if (i - 1 >= 0 && j >= 0 && j < m && i - 1 < n && gozd[i - 1][j] == x && prebrano[i - 1][j] == '0')
		preveri(i - 1, j, gozd, prebrano, m, n);
	if (i >= 0 && j - 1 >= 0 && j - 1 < m && i < n && gozd[i][j - 1] == x && prebrano[i][j - 1] == '0')
		preveri(i, j - 1, gozd, prebrano, m, n);
	if (i - 1 >= 0 && j - 1 >= 0 && j - 1 < m && i - 1 < n && gozd[i - 1][j - 1] == x && prebrano[i - 1][j - 1] == '0')
		preveri(i - 1, j - 1, gozd, prebrano, m, n);
	if (i + 1 >= 0 && j - 1 >= 0 && j - 1 < m && i + 1 < n && gozd[i + 1][j - 1] == x && prebrano[i + 1][j - 1] == '0')
		preveri(i + 1, j - 1, gozd, prebrano, m, n);
	if (i - 1 >= 0 && j + 1 >= 0 && j + 1 < m && i - 1 < n && gozd[i - 1][j + 1] == x && prebrano[i - 1][j + 1] == '0')
		preveri(i - 1, j + 1, gozd, prebrano, m, n);
}

int st_gozd(string *gozd, string *prebrano, int vsota, int m, int n) {
	int st = 0;
	/*
	cout << "v gozd\n";
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < m; ++j) {
			cout << gozd[i][j];
		}
		cout << "\n";
	}
	cout << "\n";
	*/
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < m; ++j) {
			if (prebrano[i][j] == '0') {
				preveri(i, j, gozd, prebrano, m, n);
				//cout << gozd[i][j] << i << " " << j << "\n";
				++st;
			}
		}
	}
	return st;
}

int main() {
	string *gozd = new string[250000];
	string *prebrano = new string[250000];

	int m = 1, n = 1;
	string abc;
	while (m != 0 && n != 0) {
		cin >> n >> m;
		if (n == 0 && m == 0)
			break;

		for (int i = 0; i < n; ++i) {
			prebrano[i] = "";
			for (int j = 0; j < m; ++j) {
				prebrano[i] += '0';
			}
		}
		for (int i = 0; i < n; ++i) {
			cin >> abc;
			gozd[i] = abc;
		}

		cout << st_gozd(gozd, prebrano, 0, m, n) << "\n";
	}

	return 0;
}