Submission #546889

#TimeUsernameProblemLanguageResultExecution timeMemory
546889AbdelmagedNourCollecting Mushrooms (NOI18_collectmushrooms)C++17
100 / 100
10 ms5460 KiB
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") using namespace std; int n,m,d,k; vector<vector<int>>pre; void calc(){ for(int i=0;i<n;i++){ for(int j=0;j<m;j++){ pre[i][j]+=(j?pre[i][j-1]:0)+(i?pre[i-1][j]:0)-(i&&j?pre[i-1][j-1]:0); } } } int sum(int x1,int x2,int y1,int y2){ int res=pre[x2][y2]; if(y1)res-=pre[x2][y1-1]; if(x1)res-=pre[x1-1][y2]; if(x1&&y1)res+=pre[x1-1][y1-1]; return res; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin>>n>>m>>d>>k; vector<string>grid(n); pre.resize(n,vector<int>(m,0)); for(int i=0;i<n;i++){ cin>>grid[i]; for(int j=0;j<m;j++){ if(grid[i][j]=='S')pre[i][j]++; } } calc(); int res=0; for(int i=0;i<n;i++){ for(int j=0;j<m;j++){ if(grid[i][j]=='M'){ int x1=max(i-d,0),x2=min(i+d,n-1),y1=max(j-d,0),y2=min(j+d,m-1); if(sum(x1,x2,y1,y2)>=k)res++; } } } cout<<res; return 0; }
#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...