Rezultati

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

Test Točke Porabljen spomin Porabljen čas Status
#1 [več] 10/10 3,039 MiB 0,000 s OK
#2 [več] 10/10 3,254 MiB 0,009 s OK
#3 [več] 10/10 14,074 MiB 0,117 s OK
#4 [več] 10/10 3,176 MiB 0,040 s OK
#5 [več] 10/10 3,039 MiB 0,000 s OK
#6 [več] 10/10 3,938 MiB 0,034 s OK
#7 [več] 10/10 3,074 MiB 0,020 s OK
#8 [več] 10/10 3,285 MiB 0,021 s OK
#9 [več] 10/10 3,289 MiB 0,028 s OK
#10 [več] 10/10 3,242 MiB 0,038 s OK

Ocenjevani program (main.cpp):
#include <bits/stdc++.h>

#define f first
#define s second
#define mp make_pair
#define pb push_back

using namespace std;

typedef long long ll;

const int comi[] = {0, 0, -1, 1, 1, 1, -1, -1};
const int comj[] = {-1, 1, 0, 0, 1, -1, 1, -1};

int N, M;

void DFS(vector<string> &v, vector<vector<bool> > &vis, int i, int j)
{
    if (vis[i][j]) return;
    vis[i][j] = true;

    for (int k = 0; k < 8; k++)
        if (i + comi[k] >= 0 && i + comi[k] < N && j + comj[k] >= 0 && j + comj[k] < M && v[i][j] == v[i + comi[k]][j + comj[k]])
            DFS(v, vis, i + comi[k], j + comj[k]);
}

int main()
{
    while (true) {
        cin >> N >> M;
        if (N == 0 && M == 0) break;

        vector<string> v;
        vector<vector<bool> > vis;
        for (int i = 0; i < N; i++) {
            string x; cin >> x;
            v.push_back(x);

            vector<bool> _v(M, 0);
            vis.push_back(_v);
        }

        ll ans = 0;
        for (int i = 0; i < N; i++)
            for (int j = 0; j < M; j++)
                if (!vis[i][j]) ++ans, DFS(v, vis, i, j);
        cout << ans << endl;
    }
    return 0;
}