Submission #1309511

#TimeUsernameProblemLanguageResultExecution timeMemory
1309511arafatisticCollecting Mushrooms (NOI18_collectmushrooms)C++20
79 / 100
2096 ms13156 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 sl[n + 2][m + 2];
    for(int i = 0; i <= n + 1; i++){
        for(int j = 0; j <= m + 1; j++){
            sl[i][j] = 0;
        }
    }
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= m; j++){
            cin >> c[i][j];
            if(c[i][j] == 'S'){
                for(int l = max(1ll, i - d); l <= min(n, i + d); l++){
                    int k1 = max(1ll, j - d);
                    int k2 = min(m, j + d) + 1;
                    sl[l][k1]++;
                    sl[l][k2]--;
                }
            }
        }
    }
    int cur = 0;
    int ans = 0;
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= m; j++){
            cur += sl[i][j];
            if(c[i][j] == 'M' && cur >= k) {
                ans++;
            }
        }
        cur += sl[i][m + 1];
    }
    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...