Submission #785510

#TimeUsernameProblemLanguageResultExecution timeMemory
78551012345678Collecting Mushrooms (NOI18_collectmushrooms)C++17
100 / 100
21 ms18736 KiB
#include <bits/stdc++.h>

using namespace std;

int r, c, d, k, ans;
char ch;

int main()
{
    cin.tie(NULL)->sync_with_stdio(false);
    cin>>r>>c>>d>>k;
    vector<pair<int, int>> s, m;
    vector<vector<int>> dp(r+5, vector<int> (c+5));
    for (int i=1; i<=r; i++)
    {
        for (int j=1; j<=c; j++)
        {
            cin>>ch;
            if (ch=='M') m.push_back({i, j});
            if (ch=='S')
            {
                dp[max(i-d, 1)][max(j-d, 1)]++;
                dp[max(i-d, 1)][min(j+d+1, c+1)]--;
                dp[min(i+d+1, r+1)][max(j-d, 1)]--;
                dp[min(i+d+1, r+1)][min(j+d+1, c+1)]++;
            }
        }
    }
    for (int i=1; i<=r; i++) for (int j=1; j<=c; j++) dp[i][j]+=dp[i-1][j];
    for (int i=1; i<=r; i++) for (int j=1; j<=c; j++) dp[i][j]+=dp[i][j-1];
    for (auto [x, y]:m) if (dp[x][y]>=k) ans++;
    cout<<ans;
}
#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...