Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stack>
- using namespace std;
- int ovci=0, volci=0, x, y;
- char mat[251][251];
- void DFS(int m, int n)
- {
- stack<int> stx, sty;
- stx.push(m);
- sty.push(n);
- while(!stx.empty())
- {
- int a = stx.top();
- int b = sty.top();
- stx.pop();
- sty.pop();
- if(mat[a][b]=='o')ovci++;
- if(mat[a][b]=='v')volci++;
- mat[a][b] = '#';
- if(b+1<y and mat[a][b+1]!='#') { stx.push(a); sty.push(b+1); }
- if(a+1<x and mat[a+1][b]!='#') { stx.push(a+1); sty.push(b); }
- if(b-1>=0 and mat[a][b-1]!='#') { stx.push(a); sty.push(b-1); }
- if(a-1>=0 and mat[a-1][b]!='#') { stx.push(a-1); sty.push(b); }
- }
- }
- int main()
- {
- int i, j, finalOvci=0, finalVolci=0;
- cin >> x >> y;
- for(i=0; i<x; i++)
- for(j=0; j<y; j++)
- cin >> mat[i][j];
- for(i=0; i<x; i++)
- for(j=0; j<y; j++)
- {
- if(mat[i][j]!='#')DFS(i, j);
- if(ovci>volci)finalOvci+=ovci;
- else finalVolci+=volci;
- ovci = 0; volci = 0;
- }
- cout << finalOvci << " " << finalVolci;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment