Submission #546929

#TimeUsernameProblemLanguageResultExecution timeMemory
546929Ahmed57Collecting Mushrooms (NOI18_collectmushrooms)C++14
100 / 100
24 ms26736 KiB
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n,m,d,k; cin>>n>>m>>d>>k; char arr[n+5][m+5]; int pre[n+5][m+5]; int fores[n+5][m+5]; memset(pre,0,sizeof pre); memset(fores,0,sizeof fores); for(int i=1;i<=n;i++) { for(int j=1;j<=m;j++) { char a; cin>>a; arr[i][j] = a; if(a=='S'){ fores[i][j]++; } } } pre[1][1] = fores[1][1]; for(int i = 2;i<=m;i++) pre[1][i]=pre[1][i-1]+fores[1][i]; for(int i = 2;i<=n;i++) pre[i][1]=pre[i-1][1]+fores[i][1]; for(int i=2;i<=n;i++){ for(int j=2;j<=m;j++){ pre[i][j]=pre[i-1][j]+pre[i][j-1]-pre[i-1][j-1]+fores[i][j]; } } int ans=0; for(int i = 1;i<=n;i++){ for(int j = 1;j<=m;j++){ if(arr[i][j]=='M'){ long long x1 = max(i-d,1) , y1 = max(j-d,1) , x2 = min(i+d,n) , y2 = min(j+d,m); long long sum = pre[x2][y2]; if(x1>1)sum-=pre[x1-1][y2]; if(y1>1)sum-=pre[x2][y1-1]; if(x1>1&&y1>1)sum+=pre[x1-1][y1-1]; if(sum>=k)ans++; } } } cout<<ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...