Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- 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 res_volci = 0, res_ovci = 0;
- for(int i = 0; i < n; i++) {
- for(int j = 0; j < m; j++) {
- if(mat[i][j] != '#' and !visited[i][j]) {
- visited[i][j] = true;
- queue<int> q;
- q.push(i);
- q.push(j);
- int ovci = 0, volci = 0;
- while(!q.empty()) {
- int ci = q.front();
- q.pop();
- int cj = q.front();
- q.pop();
- if(mat[ci][cj] == 'v') {
- volci++;
- }
- if(mat[ci][cj] == 'o') {
- ovci++;
- }
- if(ci + 1 < n and mat[ci + 1][cj] != '#' and !visited[ci + 1][cj]) {
- q.push(ci + 1);
- q.push(cj);
- visited[ci + 1][cj] = true;
- }
- if(ci - 1 >= 0 and mat[ci - 1][cj] != '#' and !visited[ci - 1][cj]) {
- q.push(ci - 1);
- q.push(cj);
- visited[ci - 1][cj] = true;
- }
- if(cj + 1 < m and mat[ci][cj + 1] != '#' and !visited[ci][cj + 1]) {
- q.push(ci);
- q.push(cj + 1);
- visited[ci][cj + 1] = true;
- }
- if(cj - 1 >= 0 and mat[ci][cj - 1] != '#' and !visited[ci][cj - 1]) {
- q.push(ci);
- q.push(cj - 1);
- visited[ci][cj - 1] = true;
- }
- }
- if(ovci > volci) {
- res_ovci += ovci;
- }
- else {
- res_volci += volci;
- }
- }
- }
- }
- cout << res_ovci << " " << res_volci << endl;
- return 0;
- }
- /*
- .######.
- #..o...#
- #.####.#
- #.#v.#.#
- #.#.o#o#
- #o.##..#
- #.v..v.#
- .######.
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement