#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
int r, c, d, k, count = 0;
int x1, x2, x3, x4, y1, y2, y3, y4, xs, ys;
string s;
vector<string> grid;
vector<vector<int>> sumgrid;
vector<int> temp;
vector<pair<int,int>> mushroom, sprinkler;
cin >> r >> c >> d >> k;
for(int i = 0; i <= r+4; i++){
temp.clear();
for(int j = 0; j <= c+4; j++){
temp.push_back(0);
}
sumgrid.push_back(temp);
}
for(int i = 0; i < r; i++){
cin >> s;
grid.push_back(s);
for(int j = 0; j < c; j++){
if(s[j] == 'M'){
mushroom.push_back({i+1, j+1});
}
else if(s[j] == 'S'){
sprinkler.push_back({i+1, j+1});
}
}
}
for(auto coor : sprinkler){
xs = coor.first;
ys = coor.second;
x1 = xs-d;
y1 = ys-d;
x2 = xs+d+1;
y2 = ys-d;
x3 = xs-d;
y3 = ys+d+1;
x4 = xs+d+1;
y4 = ys+d+1;
if(x1 < 1) x1 = 1;
if(y1 < 1) y1 = 1;
if(x2 > r+1) x2 = r+1;
if(y2 < 1) y2 = 1;
if(x3 < 1) x3 = 1;
if(y3 > c+1) y3 = c+1;
if(x4 > r+1) x4 = r+1;
if(y4 > c+1) y4 = c+1;
sumgrid[x1][y1] += 1;
sumgrid[x2][y2] -= 1;
sumgrid[x3][y3] -= 1;
sumgrid[x4][y4] += 1;
}
// for(int i = 0; i <= r+1; i++){
// for(int j = 0; j <= c+1; j++){
// cout << sumgrid[i][j];
// }
// cout << endl;
// }
for(int i = 0; i<= r+1; i++){
for(int j = 1; j <= c+1; j++){
sumgrid[i][j] += sumgrid[i][j-1];
}
}
for(int i = 1; i<= r+1; i++){
for(int j = 0; j <= c+1; j++){
sumgrid[i][j] += sumgrid[i-1][j];
}
}
for(auto coor : mushroom){
xs = coor.first;
ys = coor.second;
if(sumgrid[xs][ys] >= k){
count++;
}
}
// cout << endl;
// for(int i = 0; i <= r+1; i++){
// for(int j = 0; j <= c+1; j++){
// cout << sumgrid[i][j];
// }
// cout << endl;
// }
cout << count;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
304 KB |
Output is correct |
2 |
Correct |
1 ms |
436 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
304 KB |
Output is correct |
2 |
Correct |
1 ms |
436 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
1492 KB |
Output is correct |
2 |
Correct |
4 ms |
1492 KB |
Output is correct |
3 |
Correct |
5 ms |
1728 KB |
Output is correct |
4 |
Correct |
5 ms |
1492 KB |
Output is correct |
5 |
Correct |
5 ms |
1620 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
24 ms |
19012 KB |
Output is correct |
2 |
Correct |
26 ms |
21796 KB |
Output is correct |
3 |
Correct |
26 ms |
21776 KB |
Output is correct |
4 |
Correct |
26 ms |
21180 KB |
Output is correct |
5 |
Correct |
27 ms |
21824 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
304 KB |
Output is correct |
2 |
Correct |
1 ms |
436 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
468 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
5 ms |
1492 KB |
Output is correct |
17 |
Correct |
4 ms |
1492 KB |
Output is correct |
18 |
Correct |
5 ms |
1728 KB |
Output is correct |
19 |
Correct |
5 ms |
1492 KB |
Output is correct |
20 |
Correct |
5 ms |
1620 KB |
Output is correct |
21 |
Correct |
24 ms |
19012 KB |
Output is correct |
22 |
Correct |
26 ms |
21796 KB |
Output is correct |
23 |
Correct |
26 ms |
21776 KB |
Output is correct |
24 |
Correct |
26 ms |
21180 KB |
Output is correct |
25 |
Correct |
27 ms |
21824 KB |
Output is correct |
26 |
Correct |
18 ms |
8000 KB |
Output is correct |
27 |
Correct |
14 ms |
5604 KB |
Output is correct |
28 |
Correct |
15 ms |
6924 KB |
Output is correct |
29 |
Correct |
13 ms |
5324 KB |
Output is correct |
30 |
Correct |
16 ms |
7404 KB |
Output is correct |