Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <queue>
- using namespace std;
- int main()
- {
- int n;
- int m;
- cin>>n>>m;
- char matrica[n][m];
- queue<int>q;
- int volci=0;
- int ovci=0;
- for(int x=0; x<n; x++){
- for(int x1=0; x1<m; x1++){
- cin>>matrica[x][x1];
- }
- }
- bool visited[n][m];
- for(int y=0; y<n; y++){
- for(int y1=0; y1<m; y1++){
- visited[y][y1]=false;
- }
- }
- for(int u=0; u<n; u++){
- for(int u1=0; u1<m; u1++){
- if((matrica[u][u1]!='#')and(visited[u][u1]==false)){
- q.push(u);
- q.push(u1);
- visited[u][u1]=true;
- int obr=0;
- int vbr=0;
- while(!q.empty()){
- int ci=q.front();
- q.pop();
- int cj=q.front();
- q.pop();
- if((ci+1<n)and(matrica[ci+1][cj]!='#')and(visited[ci+1][cj]!=true)){
- q.push(ci+1);
- q.push(cj);
- visited[ci+1][cj]=true;
- }
- if((ci-1>=0)and(matrica[ci-1][cj]!='#')and(visited[ci-1][cj]!=true)){
- q.push(ci-1);
- q.push(cj);
- visited[ci-1][cj]=true;
- }
- if((cj+1<m)and(matrica[ci][cj+1]!='#')and(visited[ci][cj+1]!=true)){
- q.push(ci);
- q.push(cj+1);
- visited[ci][cj+1]=true;
- }
- if((cj-1>=0)and(matrica[ci][cj-1]!='#')and(visited[ci][cj-1]!=true)){
- q.push(ci);
- q.push(cj-1);
- visited[ci][cj-1]=true;
- }
- if(matrica[ci][cj]=='v'){
- vbr+=1;
- }
- else if(matrica[ci][cj]=='o'){
- obr+=1;
- }
- }
- if(vbr>=obr){
- volci+=vbr;
- }
- else{
- ovci+=obr;
- }
- }
- }
- }
- cout<<ovci << " "<<volci;
- return 0;
- }
- /*
- 3 3
- vvv
- ooo
- ooo
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement