#include <bits/stdc++.h>
#define sts stable_sort
#define B begin()
#define rB rbegin()
#define E end()
#define rE rend()
#define F first
#define S second
#define pb push_back
#define ppb pop_back()
#define pf push_front
#define ppf pop_front()
#define eb emplace_back
#define ll long long
#define ui unsigned int
#define ull unsigned long long
using namespace std;
const int MAXN = 500004;
const int MOD = 1e9 + 7;
const ll INF = 9223372036854775807LL;
const ll inf = 2147483647;
map<pair<int, int>, int> ma;
void bfs(pair<int, int> z, int r, int c, int d){
queue<pair<pair<int, int>, int> > q;
bool comp[r + 1][c + 1];
q.push({z, 0});
while(!q.empty()){
pair<pair<int, int>, int> x = q.front();
q.pop();
if( x.F.F <= 0 || x.F.F > r || x.F.S <= 0 || x.F.S > c || x.S > d)continue;
if(comp[x.F.F][x.F.S])continue;
comp[x.F.F][x.F.S] = 1;
ma[x.F]++;
q.push({{x.F.F + 1, x.F.S}, x.S + 1});
q.push({{x.F.F - 1, x.F.S}, x.S + 1});
q.push({{x.F.F, x.F.S + 1},x.S + 1});
q.push({{x.F.F, x.F.S - 1},x.S + 1});
q.push({{x.F.F + 1, x.F.S - 1},x.S + 1});
q.push({{x.F.F + 1, x.F.S + 1},x.S + 1});
q.push({{x.F.F - 1, x.F.S - 1},x.S + 1});
q.push({{x.F.F - 1, x.F.S + 1},x.S + 1});
}
}
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0);
int r, c, d, k; cin >> r >> c >> d >> k;
vector<pair<int, int> > s;
vector<pair<int, int> > m;
for(int i = 1; i <= r; i++){
for(int j = 1; j <= c; j++){
char ch; cin >> ch;
if(ch == 'S'){
s.pb({i, j});
}else if(ch == 'M'){
m.pb({i, j});
}
}
}
for(int i = 0; i < s.size(); i++){
bfs(s[i], r, c, d);
}
int cnt = 0;
for(int i = 0; i < m.size(); i++){
if(ma[m[i]] >= k)cnt++;
}cout << cnt << "\n";
return 0;
}
/**
**/
Compilation message
mushrooms.cpp: In function 'int main()':
mushrooms.cpp:72:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
72 | for(int i = 0; i < s.size(); i++){
| ~~^~~~~~~~~~
mushrooms.cpp:76:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
76 | for(int i = 0; i < m.size(); i++){
| ~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
75 ms |
12956 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
651 ms |
35152 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |