// #define _GLIBCXX_DEBUG
// #pragma GCC optimize "trapv"
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
using namespace std;
using namespace __gnu_pbds;
#define pb push_back
#define f first
#define s second
#define min3(a, b, c) min(min(a, b), c)
#define max3(a, b, c) max(max(a, b), c)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef double ld;
typedef long double lld;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pii> vpi;
typedef vector<pll> vpl;
template <class T> using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;
const int INF = 1e9;
// const ll INF = 1e18;
const ll mod = 1000000007;
// const ll mod = 998244353;
vvi pref;
void update(int c1, int c2, int r1, int r2){
pref[r1][c1]++;
pref[r2+1][c2+1]++;
pref[r2+1][c1]--;
pref[r1][c2+1]--;
}
void solve(int tc){
int r, c, d, k;
cin >> r >> c >> d >> k;
pref.assign(r+2, vi(c+2, 0));
vvi mat(r, vi(c, 0));
for(int i = 0; i < r; i++){
string s;
cin >> s;
for(int j = 0; j < c; j++){
if(s[j] == 'M') mat[i][j] = 2;
else if(s[j] == 'S') mat[i][j] = 1;
}
}
for(int i = 1; i <= r; i++)
for(int j = 1; j <= c; j++)
if(mat[i-1][j-1] == 1)
update(max(1, j-d), min(c, j+d), max(1, i-d), min(r, i+d));
for(int i = 1; i <= r; i++)
for(int j = 1; j <= c; j++)
pref[i][j] += pref[i][j-1] + pref[i-1][j] - pref[i-1][j-1];
int ans = 0;
for(int i = 1; i <= r; i++){
for(int j = 1; j <= c; j++)
if(mat[i-1][j-1] == 2 && pref[i][j] >= k) ans++;
}
cout << ans << '\n';
}
int main(){
ios_base::sync_with_stdio(NULL);
cin.tie(NULL);
int tc = 1;
// cin >> tc;
for (int t = 0; t < tc; t++) solve(t);
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
492 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
0 ms |
364 KB |
Output is correct |
5 |
Correct |
0 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
492 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
0 ms |
364 KB |
Output is correct |
5 |
Correct |
0 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
0 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
512 KB |
Output is correct |
9 |
Correct |
0 ms |
364 KB |
Output is correct |
10 |
Correct |
0 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
1900 KB |
Output is correct |
2 |
Correct |
3 ms |
2028 KB |
Output is correct |
3 |
Correct |
3 ms |
2284 KB |
Output is correct |
4 |
Correct |
3 ms |
2028 KB |
Output is correct |
5 |
Correct |
3 ms |
2028 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
10184 KB |
Output is correct |
2 |
Correct |
12 ms |
10184 KB |
Output is correct |
3 |
Correct |
12 ms |
10184 KB |
Output is correct |
4 |
Correct |
16 ms |
10232 KB |
Output is correct |
5 |
Correct |
13 ms |
10184 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
492 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
0 ms |
364 KB |
Output is correct |
5 |
Correct |
0 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
0 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
512 KB |
Output is correct |
9 |
Correct |
0 ms |
364 KB |
Output is correct |
10 |
Correct |
0 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
4 ms |
1900 KB |
Output is correct |
17 |
Correct |
3 ms |
2028 KB |
Output is correct |
18 |
Correct |
3 ms |
2284 KB |
Output is correct |
19 |
Correct |
3 ms |
2028 KB |
Output is correct |
20 |
Correct |
3 ms |
2028 KB |
Output is correct |
21 |
Correct |
14 ms |
10184 KB |
Output is correct |
22 |
Correct |
12 ms |
10184 KB |
Output is correct |
23 |
Correct |
12 ms |
10184 KB |
Output is correct |
24 |
Correct |
16 ms |
10232 KB |
Output is correct |
25 |
Correct |
13 ms |
10184 KB |
Output is correct |
26 |
Correct |
15 ms |
5996 KB |
Output is correct |
27 |
Correct |
8 ms |
4332 KB |
Output is correct |
28 |
Correct |
10 ms |
4332 KB |
Output is correct |
29 |
Correct |
9 ms |
4332 KB |
Output is correct |
30 |
Correct |
13 ms |
5484 KB |
Output is correct |