Submission #624787

#TimeUsernameProblemLanguageResultExecution timeMemory
624787rm1729Collecting Mushrooms (NOI18_collectmushrooms)C++17
100 / 100
28 ms21904 KiB
#include <bits/stdc++.h> using namespace std; #define int long long void solve(){ int R, C; cin >>R>>C; int D, K; cin >>D >>K; vector <vector <int>> pref(R+1, vector <int> (C+1,0)); vector <pair<int,int>> loc; for(int i=1; i<=R; i++){ string a; cin >>a; for(int j=1; j<=C; j++){ char x = a[j-1]; pref[i][j]=pref[i][j-1]+pref[i-1][j]-pref[i-1][j-1]; if(x=='M') loc.push_back(make_pair(i,j)); if(x=='S'){ pref[i][j]++; } } } int ans = 0; for(auto x: loc){ pair maxpos =make_pair(min(R,x.first+D), min(C,x.second+D)); pair minpos =make_pair(max(1ll,x.first-D), max(1ll,x.second-D)); int n = pref[maxpos.first][maxpos.second]-pref[minpos.first-1][maxpos.second]-pref[maxpos.first][minpos.second-1]+pref[minpos.first-1][minpos.second-1]; if(K<=n) ans++; } cout <<ans<<endl; } signed main(){ int t=1; while(t--){ solve(); } 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...