#include <bits/stdc++.h>
using namespace std;
int main()
{
#ifdef ONPC
freopen ("input.txt", "r", stdin);
#endif // ONPC
#ifndef ONPC
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#endif // ONPC
int n, m, r, need;
cin >> n >> m >> r >> need;
vector<pair<int, int>> mus, spr;
for (int i = 0; i < n; i++)
{
string s;
cin >> s;
assert((int) s.size() == m);
for (int j = 0; j < m; j++)
{
char ch = s[j];
if (ch == '.')
{
continue;
}
if (ch == 'S')
{
spr.push_back({i, j});
continue;
}
if (ch == 'M')
{
mus.push_back({i, j});
continue;
}
assert(0);
}
}
int sol = 0;
sort(mus.begin(), mus.end());
sort(spr.begin(), spr.end());
int p1 = 0, p2 = 0;
int dim = m + 7;
vector<int> t(dim, 0);
auto add = [&] (int pos, int x)
{
pos++;
for (int i = pos; i < dim; i += i & (-i))
{
t[i] += x;
}
};
auto get = [&] (int pos)
{
pos++;
int sol = 0;
for (int i = pos; i >= 1; i -= i & (-i))
{
sol += t[i];
}
return sol;
};
for (auto &it : mus)
{
while (p1 < (int) spr.size() && spr[p1].first <= it.first + r)
{
add(spr[p1++].second, +1);
}
while (p2 < (int) spr.size() && spr[p2].first < it.first - r)
{
add(spr[p2++].second, -1);
}
int cnt = 0;
for (int j = p2; j < p1; j++)
{
if (it.second - r <= spr[j].second && spr[j].second <= it.second + r)
{
cnt++;
}
}
///assert(cnt == get(it.second + r) - get(it.second - r - 1));
sol += (get(it.second + r) - get(it.second - r - 1) >= need);
}
cout << sol << "\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 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 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
22 ms |
10452 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |