Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <queue>
- using namespace std;
- typedef long long ll;
- 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 ovci = 0, 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);
- Q.push(j);
- visited[i][j] = true;
- int kolku_ovci = 0;
- int kolku_volci = 0;
- while(!Q.empty()) {
- int ci = Q.front();
- Q.pop();
- int cj = Q.front();
- Q.pop();
- if(mat[ci][cj] == 'o') {
- kolku_ovci++;
- }
- if(mat[ci][cj] == 'v') {
- kolku_volci++;
- }
- 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(kolku_ovci > kolku_volci) {
- ovci += kolku_ovci;
- }
- else {
- volci += kolku_volci;
- }
- }
- }
- }
- cout << ovci << " " << volci << endl;
- return 0;
- }
- /*
- 8 8
- .######.
- #..o...#
- #.####.#
- #.#v.#.#
- #.#.o#o#
- #o.##..#
- #.v..v.#
- .######.
- **/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement