Submission #1173845

#TimeUsernameProblemLanguageResultExecution timeMemory
1173845khangrlCollecting Mushrooms (NOI18_collectmushrooms)C++20
100 / 100
398 ms67440 KiB
#include<bits/stdc++.h> #define ff first #define ss second #define pb push_back #define ll long long using namespace std; int main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); vector <pair <int, int> > mush, sprink; int n, m, d, k, ans=0; cin>>n>>m>>d>>k; char c[n+5][m+5]; for(int i=1; i<=n; i++){ for(int j=1; j<=m; j++){ cin>>c[i][j]; if(c[i][j]=='S'){ sprink.pb({i, j}); } } } map <int, map <int, int> > mp; for(auto spn : sprink){ int x=spn.ff, y=spn.ss; int first_x=max(1, x-d), last_x=min(n, x+d), first_y=max(1, y-d), last_y=min(m, y+d); mp[first_x][first_y]++; mp[last_x+1][last_y+1]++; mp[first_x][last_y+1]--; mp[last_x+1][first_y]--; } for(int i=1; i<=n; i++){ for(int j=1; j<=m; j++){ mp[i][j]+=mp[i][j-1]; } } for(int i=1; i<=m; i++){ for(int j=1; j<=n; j++){ mp[j][i]+=mp[j-1][i]; } } for(int i=1; i<=n; i++){ for(int j=1; j<=m; j++){ if(c[i][j]=='M' and mp[i][j]>=k){ ans++; } } } cout<<ans; } /* 5 5 2 2 ....M .M... ..S.. .S... ...M. */
#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...