#include <bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vi vector<int>
#define vl vector<ll>
#define mp make_pair
#define pb push_back
using namespace std;
int r, c, d, k;
bool check(int x1, int y1, int x2, int y2){
int dist = max(abs(x1 - x2), abs(y1 - y2));
if(d >= dist)
return 1;
return 0;
}
int main(){
cin>>r>>c>>d>>k;
char mat[r][c];
vector<pii> s,m;
for(int i = 0; i < r; i++){
for(int j = 0; j < c; j++)
{
cin>>mat[i][j];
if(mat[i][j]=='S')
s.pb(mp(i,j));
if(mat[i][j]=='M')
m.pb(mp(i,j));
}
}
ll rez= 0;
for(int i = 0; i < m.size(); i++){
int cnt = 0;
for(int j = 0; j < s.size(); j++){
if(cnt >= k)
break;
cnt += check(m[i].first, m[i].second, s[j].first, s[j].second);
}
if(cnt >= k)
rez++;
}
cout<<rez<<endl;
}
Compilation message
mushrooms.cpp: In function 'int main()':
mushrooms.cpp:32:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
32 | for(int i = 0; i < m.size(); i++){
| ~~^~~~~~~~~~
mushrooms.cpp:34:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
34 | for(int j = 0; j < s.size(); j++){
| ~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
224 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
308 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
224 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
308 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
19 ms |
432 KB |
Output is correct |
9 |
Correct |
3 ms |
216 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
304 KB |
Output is correct |
2 |
Correct |
4 ms |
340 KB |
Output is correct |
3 |
Correct |
9 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
288 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
596 KB |
Output is correct |
2 |
Correct |
13 ms |
696 KB |
Output is correct |
3 |
Correct |
16 ms |
724 KB |
Output is correct |
4 |
Correct |
13 ms |
724 KB |
Output is correct |
5 |
Correct |
12 ms |
596 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2082 ms |
4184 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
224 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
308 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
19 ms |
432 KB |
Output is correct |
9 |
Correct |
3 ms |
216 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
304 KB |
Output is correct |
12 |
Correct |
4 ms |
340 KB |
Output is correct |
13 |
Correct |
9 ms |
468 KB |
Output is correct |
14 |
Correct |
1 ms |
288 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
12 ms |
596 KB |
Output is correct |
17 |
Correct |
13 ms |
696 KB |
Output is correct |
18 |
Correct |
16 ms |
724 KB |
Output is correct |
19 |
Correct |
13 ms |
724 KB |
Output is correct |
20 |
Correct |
12 ms |
596 KB |
Output is correct |
21 |
Execution timed out |
2082 ms |
4184 KB |
Time limit exceeded |
22 |
Halted |
0 ms |
0 KB |
- |