Rezultati

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

Test Točke Porabljen spomin Porabljen čas Status
#1 [več] 10/10 3,207 MiB 0,004 s OK
#2 [več] 10/10 3,609 MiB 0,004 s OK
#3 [več] 10/10 6,684 MiB 0,033 s OK
#4 [več] 10/10 3,164 MiB 0,010 s OK
#5 [več] 10/10 6,273 MiB 0,057 s OK
#6 [več] 10/10 4,273 MiB 0,010 s OK
#7 [več] 10/10 3,602 MiB 0,016 s OK
#8 [več] 10/10 3,191 MiB 0,004 s OK
#9 [več] 10/10 3,160 MiB 0,004 s OK
#10 [več] 10/10 3,254 MiB 0,016 s OK

Ocenjevani program (gozd.cpp):
#include <algorithm>
#include <array>
#include <complex>
#include <cmath>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <map>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <stack>
#include <tuple>
#include <utility>
#include <vector>
#include <stdio.h>


using namespace std;

void floodfill(char **tab, int n, int m, int i, int j) {
    if(tab[i][j]) {
        char thisCell = tab[i][j];
        tab[i][j] = 0;
        if(thisCell == tab[i+1][j]) floodfill(tab, n, m, i+1, j);
        if(thisCell == tab[i][j+1]) floodfill(tab, n, m, i, j+1);
        if(thisCell == tab[i-1][j]) floodfill(tab, n, m, i-1, j);
        if(thisCell == tab[i][j-1]) floodfill(tab, n, m, i, j-1);
        if(thisCell == tab[i+1][j+1]) floodfill(tab, n, m, i+1, j+1);
        if(thisCell == tab[i+1][j-1]) floodfill(tab, n, m, i+1, j-1);
        if(thisCell == tab[i-1][j+1]) floodfill(tab, n, m, i-1, j+1);
        if(thisCell == tab[i-1][j-1]) floodfill(tab, n, m, i-1, j-1);
    }
}

int main() {
    cin.sync_with_stdio(false);
    cin.tie(nullptr);

    int n, m;
    cin >> n >> m;

    // for(int t =0 ; t < 5 && (n != 0 || m != 0); t++) {
    while(n != 0 || m != 0) {

        char **tab = new char*[n + 2];
        for (int i = 0; i < n + 2; i++) {
            tab[i] = new char[m + 2];
        }
        
        for (int i = 0; i < n; i++) {
            string line;
            if(m > 0)
                cin >> line;

            tab[i+1][0] = 0;
            tab[i+1][m+1] = 0;
            for (int j = 0; j < m; j++)
                tab[i+1][j+1] = line[j];
            
        }

        for (int i = 0; i < m + 2; i++) {
            tab[0][i] = 0;
            tab[n+1][i] = 0;
        }

        // for (int i = 0; i < n + 2; i++) {
        //     for (int j = 0; j < m + 2; j++) {
        //         cout << (int)tab[i][j] << " ";
        //     }
            
        //     cout << "\n";
        // }

        int r = 0;
        for (int i = 0; i < n + 2; i++) {
            for (int j = 0; j < m + 2; j++) {
                if(tab[i][j] != 0) {
                    r++;
                    floodfill(tab, n, m, i, j);
                }
            }
        }
        cout << r << "\n";

        // for (int i = 0; i < n ; i++) {
            // delete [] (tab[i]);
        // }
        delete [] tab;

        cin >> n >> m;
        // cout << n << " " << m << "\n";
    }
    
    return 0;
}