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;
- const int di[] = {-1, 1, 0, 0};
- const int dj[] = {0, 0, -1, 1};
- void dfs(int i, int j) {
- visited[i][j] = true;
- if(mat[i][j] == 'o') {
- ovci++;
- }
- if(mat[i][j] == 'v') {
- volci++;
- }
- for(int k = 0; k < 4; k++) {
- int ti = i + di[k];
- int tj = j + dj[k];
- if(ti >= 0 and ti < n and tj >= 0 and tj < m and !visited[ti][tj] and mat[ti][tj] != '#') {
- dfs(ti, tj);
- }
- }
- }
- 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