Submission #624785

#TimeUsernameProblemLanguageResultExecution timeMemory
624785rm1729Collecting Mushrooms (NOI18_collectmushrooms)C++14
0 / 100
381 ms262144 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 <int,int> maxpos =make_pair(min(R,x.first+D), min(C,x.second+D)); pair <int,int> 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; cin >>t; 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...