Submission #1328272

#TimeUsernameProblemLanguageResultExecution timeMemory
1328272jokukCollecting Mushrooms (NOI18_collectmushrooms)C++20
100 / 100
10 ms9120 KiB
#include<bits/stdc++.h>
using namespace std;

using i64 = long long;


int main(){
        
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n,m,d,k;
    cin >> n >> m >> d >> k; 

    vector<string> gr(n);
    vector<vector<int>> ar(n,vector<int>(m,0));
    for(int i = 0;i < n;i++){
        cin >> gr[i];
        for(int j = 0;j < m;j++){
            if(gr[i][j] == 'S'){
                ar[i][j] = 1;
            }
        }
    }

    vector<vector<int>> pref(n + 1,vector<int>(m + 1));
    for(int i = 1;i <= n;i++){
        for(int j = 1;j <= m;j++){
            int a = pref[i - 1][j - 1];
            int b = pref[i][j - 1];
            pref[i][j] = b - a + pref[i - 1][j] + ar[i - 1][j - 1];
        }
    }

    int ans = 0;
    for(int i = 1;i <= n;i++){
        for(int j = 1;j <= m;j++){
            if(gr[i - 1][j - 1] == 'M'){
                int x1 = max(1,i - d);
                int x2 = min(n,i + d);

                int y1 = max(1,j - d);
                int y2 = min(m,j + d);
                
                int tot = pref[x2][y2] - pref[x1 - 1][y2] - pref[x2][y1 - 1] + pref[x1 - 1][y1 - 1];
                if(tot >= k){
                    ans ++;
                }
            }
        }
    }
    cout << ans << '\n';
   
    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...