Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <queue>
- #include <cstring>
- using namespace std;
- typedef long long ll;
- int n, m;
- char mat[303][303];
- bool visited[303][303];
- int ovci, volci;
- void dfs(int i, int j) {
- visited[i][j] = true;
- if(mat[i][j] == 'o') {
- ovci++;
- }
- if(mat[i][j] == 'v') {
- volci++;
- }
- if(i + 1 < n and mat[i + 1][j] != '#' and !visited[i + 1][j]) {
- dfs(i + 1, j);
- }
- if(i - 1 >= 0 and mat[i - 1][j] != '#' and !visited[i - 1][j]) {
- dfs(i - 1, j);
- }
- if(j + 1 < m and mat[i][j + 1] != '#' and !visited[i][j + 1]) {
- dfs(i, j + 1);
- }
- if(j - 1 >= 0 and mat[i][j - 1] != '#' and !visited[i][j - 1]) {
- dfs(i, j - 1);
- }
- }
- int main() {
- ios_base::sync_with_stdio(false);
- cin >> n >> m;
- for(int i = 0; i < n; i++) {
- for(int j = 0; j < m; j++) {
- cin >> mat[i][j];
- visited[i][j] = false;
- }
- }
- int v = 0, o = 0;
- for(int i = 0; i < n; i++) {
- for(int j = 0; j < m; j++) {
- if(!visited[i][j] and mat[i][j] != '#') {
- volci = 0;
- ovci = 0;
- dfs(i, j);
- if(ovci > volci) {
- o += ovci;
- }
- else {
- v += volci;
- }
- }
- }
- }
- cout << o << " " << v << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement