Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <vector>
- #include <queue>
- #include <algorithm>
- using namespace std;
- int main()
- {
- int n, m;
- cin >> n >> m;
- char mat[n][m];
- for(int i = 0; i < n; i++) {
- for(int j = 0; j < m; j++) {
- cin >> mat[i][j];
- }
- }
- bool visited[n][m];
- for(int i = 0; i < n; i++) {
- for(int j = 0; j < m; j++) {
- visited[i][j] = false;
- }
- }
- int di[] = {-1, 1, 0, 0};
- int dj[] = {0, 0, -1, 1};
- int preziveani_ovci = 0;
- int preziveani_volci = 0;
- for(int i = 0; i < n; i++) {
- for(int j = 0; j < m; j++) {
- if(mat[i][j] != '#' and !visited[i][j]) {
- queue<int> q;
- q.push(i); // indeks na redicata
- q.push(j); // indeks na kolonata
- visited[i][j] = true;
- int volci = 0;
- int ovci = 0;
- while(!q.empty()) {
- int ci = q.front();
- q.pop();
- int cj = q.front();
- q.pop();
- if(mat[ci][cj] == 'v') {
- volci += 1;
- }
- if(mat[ci][cj] == 'o') {
- ovci += 1;
- }
- for(int k = 0; k < 4; k++) {
- int ti = ci + di[k];
- int tj = cj + dj[k];
- if(ti >= 0 and ti < n and tj >= 0 and tj < m and mat[ti][tj] != '#' and !visited[ti][tj]) {
- visited[ti][tj] = true;
- q.push(ti);
- q.push(tj);
- }
- }
- }
- if(ovci > volci) {
- preziveani_ovci += ovci;
- }
- else {
- preziveani_volci += volci;
- }
- }
- }
- }
- cout << preziveani_ovci << " " << preziveani_volci << endl;
- return 0;
- }
- /*
- ###
- voo
- ###
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement