Submission #1151466

#TimeUsernameProblemLanguageResultExecution timeMemory
1151466Robert_juniorCollecting Mushrooms (NOI18_collectmushrooms)C++20
0 / 100
7 ms2516 KiB
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) x.begin(), x.end()
#define ins insert
#define pb push_back
#define F first
#define S second
const int N = 2e5+100, M = 5e5 + 7;
const int mod = 1e9 + 7;
void solve(){
    int n, m, d, k;
    cin>>n>>m>>d>>k;
    char a[n + 1][m + 1], p[n + 1][m + 1];
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= m; j++){
            cin>>a[i][j];
        }
    }
    for(int i = 0; i <= n; i++){
        for(int j = 0; j <= m; j++){
            p[i][j] = 0;
        }
    }
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= m; j++){
            p[i][j] = p[i - 1][j] + p[i][j - 1] - p[i - 1][j - 1];
            if(a[i][j] == 'S') p[i][j]++;
        }
    }
    int ans = 0;
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= m; j++){
            if(a[i][j] != 'M') continue;
            int x = max(1ll, i - d), y = max(1ll, j - d);
            int xx = min(n, i + d), yy = min(m, j + d);
            int sum = p[xx][yy] - p[xx][y - 1] - p[x - 1][yy] + p[x - 1][y - 1];
            if(sum >= k) ans++;
        }
    }
    cout<<ans<<'\n';
}
main(){
    ios_base :: sync_with_stdio(false);
    cin.tie(nullptr);
    int t = 1;
    //cin>>t; 
    for(int i = 1; i <= t; i++){
        //cout<<"Case "<<i<<": ";
        solve();
    }
}

Compilation message (stderr)

mushrooms.cpp:43:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   43 | main(){
      | ^~~~
#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...