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;
int n,m,d,k,ans;
string s[500001];
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
cin>>n>>m>>d>>k;
for (int i=1; i<=n; ++i) {
cin>>s[i];
s[i]=" "+s[i];
}
int dp[n][m];
memset(dp,0,sizeof(dp));
for (int i=1; i<=n; ++i) {
for (int j=1; j<=m; ++j) {
dp[i][j]=dp[i-1][j]+dp[i][j-1]-dp[i-1][j-1];
if (s[i][j]=='S') ++dp[i][j];
}
}
for (int i=1; i<=n; ++i) {
for (int j=1; j<=m; ++j) {
if (s[i][j]=='M') {
if (dp[min(i+d,n)][min(j+d,m)]-dp[min(i+d,n)][max(0,j-d-1)]-dp[max(0,i-d-1)][min(j+d,m)]+dp[max(0,i-d-1)][max(0,j-d-1)]>=k) ++ans;
}
}
}
cout<<ans;
}
# | 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... |