Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <queue>
- using namespace std;
- int main() {
- int redovi, koloni;
- cin >> redovi >> koloni;
- char lavirint[redovi][koloni];
- int poseteno[redovi][koloni];
- for(int i = 0; i < redovi; i++) {
- for(int j = 0; j < koloni; j++) {
- cin >> lavirint[i][j];
- poseteno[i][j] = 0;
- }
- }
- int ovci_pobedeno = 0, volci_pobedeno = 0;
- for(int i = 0; i < redovi; i++) {
- for(int j = 0; j < koloni; j++) {
- if(lavirint[i][j] != '#' and poseteno[i][j] == 0) {
- queue<int> Q;
- Q.push(i);
- Q.push(j);
- poseteno[i][j] = 1;
- int ovci = 0, volci = 0;
- while(Q.size() > 0) {
- int ci = Q.front();
- Q.pop();
- int cj = Q.front();
- Q.pop();
- if(lavirint[ci][cj] == 'o') {
- ovci++;
- }
- if(lavirint[ci][cj] == 'v') {
- volci++;
- }
- if(ci + 1 < redovi and lavirint[ci + 1][cj] != '#' and poseteno[ci + 1][cj] == 0) {
- Q.push(ci + 1);
- Q.push(cj);
- poseteno[ci + 1][cj] = 1;
- }
- if(ci - 1 >= 0 and lavirint[ci - 1][cj] != '#' and poseteno[ci - 1][cj] == 0) {
- Q.push(ci - 1);
- Q.push(cj);
- poseteno[ci - 1][cj] = 1;
- }
- if(cj + 1 < koloni and lavirint[ci][cj + 1] != '#' and poseteno[ci][cj + 1] == 0) {
- Q.push(ci);
- Q.push(cj + 1);
- poseteno[ci][cj + 1] = 1;
- }
- if(cj - 1 >= 0 and lavirint[ci][cj - 1] != '#' and poseteno[ci][cj - 1] == 0) {
- Q.push(ci);
- Q.push(cj - 1);
- poseteno[ci][cj - 1] = 1;
- }
- }
- if(ovci > volci) {
- ovci_pobedeno += ovci;
- }
- else {
- volci_pobedeno += volci;
- }
- }
- }
- }
- cout << ovci_pobedeno << " " << volci_pobedeno << endl;
- return 0;
- }
- /*
- 8 8
- .######.
- #..o...#
- #.####.#
- #.#v.#.#
- #.#.o#o#
- #o.##..#
- #.v..v.#
- .######.
- **/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement