Submission #1063807

#TimeUsernameProblemLanguageResultExecution timeMemory
1063807LuvidiCollecting Mushrooms (NOI18_collectmushrooms)C++17
38 / 100
14 ms8768 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define pll pair<ll, ll> #define pii pair<int, int> #define fs first #define sc second #define pb push_back void solve() { int n,m,d,k; cin>>n>>m>>d>>k; int a[n+1][m+1]; for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++){ char c; cin>>c; if(c=='.')a[i][j]=0; else if(c=='M')a[i][j]=1; else a[i][j]=2; } } int pre[n+1][m+1]; memset(pre,0,sizeof(pre)); for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++){ if(a[i][j]==2){ pre[max(1,i-d)][max(1,j-d)]++; if(i+d+1<=n)pre[i+d+1][max(1,j-d)]--; if(j+d+1<=m)pre[max(1,i-d)][j+d+1]--; } } } int ans=0; for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++){ pre[i][j]+=pre[i-1][j]+pre[i][j-1]-pre[i-1][j-1]; ans+=a[i][j]==1&&pre[i][j]>=k; } } cout<<ans; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); solve(); }
#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...