#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 = 1e9 + 48;
const int MOD = 1e9 + 7;
const ll INF = 9223372036854775807LL;
const ll inf = 2147483647;
void bfs(int nod, int y, int d, map<int, int> &m){
queue<pair<int, int> > q;
vector<bool> comp(y + 1);
q.push({nod, 0});
while(!q.empty()){
pair<int, int> x = q.front();
q.pop();
if(x.F <= 0 || x.F > y || comp[x.F] || x.S > d)continue;
comp[x.F] = 1;
m[x.F]++;
q.push({x.F + 1, x.S + 1});
q.push({x.F - 1, x.S + 1});
}
}
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0);
int x, y, d, k; cin >> x >> y >> d >> k;
vector<pair<int, int> > m, s;
vector<char> v(y + 1);
for(int i = 1; i <= x; i++){
for(int j = 1; j <= y; j++){
char c; cin >> c;
if(x == 1){
v[j] = c;
}
if(c == 'M'){
m.pb({i, j});
}else if(c == 'S'){
s.pb({i, j});
}
}
}
if(x == 1){
int cnt = 0, ans = 0;
map<int, int> ma;
for(int i = 0; i < s.size(); i++){
bfs(s[i].S, y, d, ma);
}
for(int i = 0; i < m.size(); i++){
if(ma[m[i].S] >= k){
ans++;
}
}cout << ans << "\n";
return 0;
}
map<pair<int, int>, int> ma;
int ans = 0;
for(int i = 0; i < m.size(); i++){
for(int j = 0; j < s.size(); j++){
int a = abs(m[i].F - s[j].F), b = abs(m[i].S - s[j].S);
if(a <= d && b <= d){
ma[m[i]]++;
}
if(ma[m[i]] >= k){
ans++;
break;
}
}
}
cout << ans << "\n";
return 0;
}
/**
**/
Compilation message
mushrooms.cpp: In function 'int main()':
mushrooms.cpp:68:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
68 | for(int i = 0; i < s.size(); i++){
| ~~^~~~~~~~~~
mushrooms.cpp:71:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
71 | for(int i = 0; i < m.size(); i++){
| ~~^~~~~~~~~~
mushrooms.cpp:66:13: warning: unused variable 'cnt' [-Wunused-variable]
66 | int cnt = 0, ans = 0;
| ^~~
mushrooms.cpp:81: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]
81 | for(int i = 0; i < m.size(); i++){
| ~~^~~~~~~~~~
mushrooms.cpp:82:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
82 | for(int j = 0; j < s.size(); j++){
| ~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
2 ms |
640 KB |
Output is correct |
3 |
Correct |
2 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
316 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
2 ms |
640 KB |
Output is correct |
3 |
Correct |
2 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
316 KB |
Output is correct |
6 |
Correct |
1 ms |
316 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
283 ms |
340 KB |
Output is correct |
9 |
Correct |
56 ms |
436 KB |
Output is correct |
10 |
Correct |
3 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
340 KB |
Output is correct |
2 |
Correct |
39 ms |
400 KB |
Output is correct |
3 |
Correct |
216 ms |
1044 KB |
Output is correct |
4 |
Correct |
2 ms |
340 KB |
Output is correct |
5 |
Correct |
4 ms |
596 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
468 KB |
Output is correct |
2 |
Correct |
5 ms |
468 KB |
Output is correct |
3 |
Correct |
5 ms |
584 KB |
Output is correct |
4 |
Correct |
9 ms |
568 KB |
Output is correct |
5 |
Correct |
4 ms |
468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2063 ms |
13624 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
2 ms |
640 KB |
Output is correct |
3 |
Correct |
2 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
316 KB |
Output is correct |
6 |
Correct |
1 ms |
316 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
283 ms |
340 KB |
Output is correct |
9 |
Correct |
56 ms |
436 KB |
Output is correct |
10 |
Correct |
3 ms |
340 KB |
Output is correct |
11 |
Correct |
2 ms |
340 KB |
Output is correct |
12 |
Correct |
39 ms |
400 KB |
Output is correct |
13 |
Correct |
216 ms |
1044 KB |
Output is correct |
14 |
Correct |
2 ms |
340 KB |
Output is correct |
15 |
Correct |
4 ms |
596 KB |
Output is correct |
16 |
Correct |
4 ms |
468 KB |
Output is correct |
17 |
Correct |
5 ms |
468 KB |
Output is correct |
18 |
Correct |
5 ms |
584 KB |
Output is correct |
19 |
Correct |
9 ms |
568 KB |
Output is correct |
20 |
Correct |
4 ms |
468 KB |
Output is correct |
21 |
Execution timed out |
2063 ms |
13624 KB |
Time limit exceeded |
22 |
Halted |
0 ms |
0 KB |
- |