# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
95077 | ae04071 | Collecting Mushrooms (NOI18_collectmushrooms) | C++11 | 32 ms | 23244 KiB |
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>
#define fi first
#define se second
using namespace std;
using pii=pair<int,int>;
int n,m,k,d;
char str[500010];
vector<int> arr[500010];
vector<pii> ms;
inline int gy(int y){return min(max(1,y),n);}
inline int gx(int x){return min(max(1,x),m);}
int main() {
scanf("%d%d%d%d",&n,&m,&d,&k);
for(int i=0;i<=n+1;i++) arr[i].resize(m+2,0);
for(int i=1;i<=n;i++) {
scanf("%s",str+1);
for(int j=1;j<=m;j++) {
if(str[j]=='M') ms.push_back({i,j});
else if(str[j]=='S') {
arr[gy(i-d)][gx(j-d)]+=1;
arr[gy(i+d)+1][gx(j-d)]-=1;
arr[gy(i-d)][gx(j+d)+1]-=1;
arr[gy(i+d)+1][gx(j+d)+1]+=1;
}
}
}
for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) {
arr[i][j] += arr[i-1][j] + arr[i][j-1] - arr[i-1][j-1];
}
int ans=0;
for(auto &v:ms) if(arr[v.fi][v.se] >= k) ans++;
printf("%d\n",ans);
return 0;
}
Compilation message (stderr)
# | 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... |