Submission #1309537

#TimeUsernameProblemLanguageResultExecution timeMemory
1309537arafatisticCollecting Mushrooms (NOI18_collectmushrooms)C++20
100 / 100
10 ms9236 KiB
#include <bits/stdc++.h>
// #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
// #pragma GCC optimize("Ofast")
// #pragma GCC target("avx,avx2,fma")
// #pragma GCC optimization("unroll-loops")
// #pragma ("reroll")
#define all(v) v.begin(), v.end()
#define skip continue;
#define gold ios_base::sync_with_stdio(false);cin.tie(NULL);
#define xa "\n"
#define int long long
#define pb push_back
#define S second
#define F first

using namespace std;

const int mod = 1e9 + 7;
const int N = 1e5 + 7;
const int MAX = 1e9;
const int inf = 1e18;

int gcd(int a, int b) { if (b == 0) return a; else if(a == 0) return b; else return gcd(b, a % b); }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

void solve() {
    int n, m, d, k;
    cin >> n >> m >> d >> k;
    char c[n + 1][m + 1];
    int pref[n + 1][m + 1];
    for(int i = 0; i <= n; i++){
        for(int j = 0; j <= m; j++){
            pref[i][j] = 0;
        }
    }
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= m; j++){
            cin >> c[i][j];
            pref[i][j] = pref[i - 1][j] + pref[i][j - 1] - pref[i - 1][j - 1] + (c[i][j] == 'S');
        }
    }
    int ans = 0;
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= m; j++){
            if(c[i][j] == 'M'){
                int x1 = max(1ll, i - d);
                int y1 = max(1ll, j - d);
                int x2 = min(n, i + d);
                int y2 = min(m, j + d);
                int sum = pref[x2][y2] - pref[x1 - 1][y2] - pref[x2][y1 - 1] + pref[x1 - 1][y1 - 1];
                if(sum >= k) ans++; 
            }
        }
    }
    cout << ans;
}   

signed main() {
    gold;
    //freopen("knight.in", "r", stdin);
    //freopen("knight.out", "w", stdout);
    int t = 1;
    int tt = 0;
    //cin >> t;
    while (t--) {
        tt++;
        //cout << "Case " << tt << ":" << xa;
        solve();
    }
}


    
#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...