이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define F first
#define S second
#define mp make_pair
const int mod = 1e9+7;
#define deb(x) cout<<#x<<": "<<x<<endl
int iceil(int a, int b) {
return (a + b - 1) / b;
}
int mul(int a, int b) {
return a * 1ll * b % mod;
}
int binpow(int a, int b) {
int res = 1;
while (b) {
if (b & 1) res = mul(res, a);
a = mul(a, a);
b >>= 1;
}
return res;
}
int ar[1001][1001];
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.precision(20);
#ifdef strawberryshaker2005
freopen("input.txt", "r", stdin);
#endif
int r,c,d,k;
cin>>r>>c>>d>>k;
char grid[r+1][c+1];
for(int i=1;i<=r;i++) for(int j=1;j<=c;j++) cin>>grid[i][j];
int diff[r+2][c+2];
memset(diff,0,sizeof(diff));
for(int i=1;i<=r;i++){
for(int j=1;j<=c;j++){
if(grid[i][j]=='S'){
diff[max(1LL,i-d)][max(1LL,j-d)]++;
diff[min(r,i+d)+1][min(c,j+d)+1]++;
diff[min(r,i+d)+1][max(1LL,j-d)]--;
diff[max(1LL,i-d)][min(c,j+d)+1]--;
}
}
}
for(int i=1;i<=r;i++){
for(int j=1;j<=c;j++){
diff[i][j]+=diff[i-1][j]+diff[i][j-1]-diff[i-1][j-1];
}
}
int ans=0;
for(int i=1;i<=r;i++){
for(int j=1;j<=c;j++){
if(diff[i][j]>=k&&grid[i][j]=='M') ans++;
}
}
cout<<ans<<endl;
return(0);
}
# | 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... |