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 ll long long
#define db double
#define pairll pair<ll,ll>
#define lpairll pair<ll,pairll>
#define repp(i,a,b) for (ll i = a; i <= b; i++)
#define repz(i,a,b) for (ll i = a; i < b; i++)
#define repm(i,a,b) for (ll i = a; i >= b; i--)
#define fr first
#define sc second
#define x first
#define y second
#define mp make_pair
#define pb push_back
const ll N = 5e5+5, MOD = 1e9+7;
ll tc = 1, n, m, br[N], d, k;
string s, s1, s2, ye = "YA", no = "TIDAK";
void input(){
cin >> n >> m >> d >> k;
}
void solve(){
ll pr[n+5][m+5];
ll mush[n+5][m+5];
memset(pr,0,sizeof(pr));
memset(mush,0,sizeof(mush));
repp(i,1,n){
repp(j,1,m){
char bnk; cin >> bnk;
if (bnk == 'S'){
ll xa, ya, xb, yb;
xa = max(1LL,i-d);
ya = max(1LL,j-d);
xb = min(n,i+d);
yb = min(m,j+d);
pr[xa][ya]++;
pr[xa][yb+1]--;
pr[xb+1][ya]--;
pr[xb+1][yb+1]++;
}
else if (bnk == 'M'){
mush[i][j] = 1;
}
}
}
ll ans = 0;
repp(i,1,n){
repp(j,1,m){
pr[i][j] += pr[i-1][j]+pr[i][j-1]-pr[i-1][j-1];
if (mush[i][j] && pr[i][j] >= k) ans++;
cerr << pr[i][j] << " ";
}
cerr << endl;
}
cout << ans << endl;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
//cin >> tc;
while(tc--){
input();
solve();
}
}
# | 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... |