#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
typedef long long ll;
const ll INF = 1e9;
const ll MOD = 998244353;
const ll MAXN = 3e5 + 5;
const ll LOG = 30;
#define vll vector <ll>
#define pll pair <ll, ll>
#define fi first
#define se second
#define endl '\n'
#define lc (pos+1)
#define rc (pos+2*(mid-l+1))
#define mid ((l+r)/2)
ll n, m, d, s;
vector <string> a;
vector <vll> pf;
void solve(){
cin >> n >> m >> d >> s;
pf.resize(n+5);
for(ll i = 0; i < n+5; i++){
pf[i].resize(m+5);
}
a.resize(n+5);
for(ll i = 1; i <= n; i++){
string c; cin >> c;
a[i] = '.' + c;
for(ll j = 1; j <= m; j++){
if(a[i][j] == 'S'){
ll ai = max((ll)1, i-d), aj = max((ll)1, j-d), bi = min(n+1, i+d+1), bj = min(m+1, j+d+1);
pf[ai][aj]++, pf[bi][bj]++;
pf[ai][bj]--, pf[bi][aj]--;
}
}
}
ll ans = 0;
for(ll i = 1; i <= n; i++){
for(ll j = 1; j <= m; j++){
pf[i][j] += pf[i-1][j] + pf[i][j-1] - pf[i-1][j-1];
// cout << pf[i][j] << " ";
if(a[i][j] == 'M'){
ans += pf[i][j] >= s;
}
}
// cout << endl;
}
cout << ans << endl;
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
// ll t; cin >> t;
// while(t--){
solve();
// }
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2140 KB |
Output is correct |
2 |
Correct |
1 ms |
2140 KB |
Output is correct |
3 |
Correct |
2 ms |
2652 KB |
Output is correct |
4 |
Correct |
1 ms |
2140 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
24812 KB |
Output is correct |
2 |
Correct |
8 ms |
24816 KB |
Output is correct |
3 |
Correct |
12 ms |
25328 KB |
Output is correct |
4 |
Correct |
9 ms |
24816 KB |
Output is correct |
5 |
Correct |
10 ms |
25068 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
2140 KB |
Output is correct |
17 |
Correct |
1 ms |
2140 KB |
Output is correct |
18 |
Correct |
2 ms |
2652 KB |
Output is correct |
19 |
Correct |
1 ms |
2140 KB |
Output is correct |
20 |
Correct |
1 ms |
2396 KB |
Output is correct |
21 |
Correct |
9 ms |
24812 KB |
Output is correct |
22 |
Correct |
8 ms |
24816 KB |
Output is correct |
23 |
Correct |
12 ms |
25328 KB |
Output is correct |
24 |
Correct |
9 ms |
24816 KB |
Output is correct |
25 |
Correct |
10 ms |
25068 KB |
Output is correct |
26 |
Correct |
9 ms |
7516 KB |
Output is correct |
27 |
Correct |
4 ms |
4956 KB |
Output is correct |
28 |
Correct |
5 ms |
5208 KB |
Output is correct |
29 |
Correct |
6 ms |
5212 KB |
Output is correct |
30 |
Correct |
7 ms |
6748 KB |
Output is correct |