This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
int main(void)
{
int r, c, d, k; cin >> r >> c >> d >> k;
vector<pair<int, int>> v;
vector<pair<int, int>> s;
char x;
for(int i = 1; i <= r; i++)
{
for(int j = 1; j <= c; j++)
{
cin >> x;
if(x == 'M') v.push_back(make_pair(i, j));
if(x == 'S') s.push_back(make_pair(i, j));
}
}
int a[r + 2][c + 2] = {};
for(auto u : s)
{
// cout << u.fi << " " << u.se << endl;
int f = u.se - d;
// cout << max(1, u.fi - d) << " " << min(r, u.fi + d) << endl;
for(int i = max(1, u.fi - d); i <= min(r, u.fi + d); i++)
{
a[i][max(1, u.se - d)]++;
a[i][min(c + 1, u.se + d + 1)]--;
}
}
for(int i = 1; i <= r; i++)
for(int j = 1; j <= c; j++)
a[i][j] += a[i][j - 1];
// for(int i = 1; i <= r + 1; i++) { for(int j = 1; j <= c + 1; j++) cout << a[i][j] << " "; cout << endl; }
int ans = 0;
for(auto u : v) if(a[u.fi][u.se] >= k) ans++;
cout << ans << endl;
}
Compilation message (stderr)
mushrooms.cpp: In function 'int main()':
mushrooms.cpp:31:13: warning: unused variable 'f' [-Wunused-variable]
int f = u.se - d;
^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |