-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprotectsheep.cpp
More file actions
49 lines (47 loc) · 1.32 KB
/
Copy pathprotectsheep.cpp
File metadata and controls
49 lines (47 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/*
Problem Name: Protect Sheep
Link to problem: https://codeforces.com/contest/948/problem/A
*/
#include <bits/stdc++.h>
using namespace std;
int main() {
int r, c; cin >> r >> c;
vector<vector<char>> meadow(r, vector<char>(c));
for (int i = 0; i < r; i++) {
for (int j = 0; j < c; j++) {
cin >> meadow[i][j];
}
}
for (int i = 0; i < r; i++) {
for (int j = 0; j < c; j++) {
if (meadow[i][j] == 'S') {
if (i > 0 && meadow[i - 1][j] == 'W') {
cout << "No" << endl;
return 0;
}
if (i < r - 1 && meadow[i + 1][j] == 'W') {
cout << "No" << endl;
return 0;
}
if (j > 0 && meadow[i][j - 1] == 'W') {
cout << "No" << endl;
return 0;
}
if (j < c - 1 && meadow[i][j + 1] == 'W') {
cout << "No" << endl;
return 0;
}
}
}
}
cout << "Yes" << endl;
for (int i = 0; i < r; i++) {
for (int j = 0; j < c; j++) {
if (meadow[i][j] == '.'){
meadow[i][j] = 'D';
}
cout << meadow[i][j];
}
cout << endl;
}
}