Submission #743626

#TimeUsernameProblemLanguageResultExecution timeMemory
743626FnzxCollecting Mushrooms (NOI18_collectmushrooms)C++17
100 / 100
30 ms32540 KiB
#include<bits/stdc++.h>

using namespace std;

using ll = long long ;
using pii = pair<ll , ll> ;
using i3 = tuple<ll , ll , ll> ;

const int N = 5e4+5;
const int MOD = 1e9+7 ;

int n , m , d , k , ans;

vector<pii> mushroom ;

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


    cin >> n >> m >> d >> k ;

    ll G[n+5][m+5] ;
    memset(G , 0 , sizeof(G));


    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            char x ; cin >> x ;
            if(x == 'S'){
                G[i][j]++ ;
            }
            else if(x == 'M'){
                mushroom.push_back({i , j});
            }
        }
    }

    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            G[i][j] += G[i-1][j] + G[i][j-1] - G[i-1][j-1] ;
        }
    }

    for(int i=0;i<mushroom.size();i++){
        int uy = mushroom[i].first , ux = mushroom[i].second ;

        int x1 = max(1 , ux - d) , y1 = max(1 , uy - d) ;
        int x2 = min(m , ux + d) , y2 = min(n , uy + d) ;

        ll sum = G[y2][x2] - G[y1 - 1][x2] - G[y2][x1 - 1] + G[y1 - 1][x1 - 1] ;

        if(sum >= k){
            ans++;
        }
    }

    cout << ans ;
}

Compilation message (stderr)

mushrooms.cpp: In function 'int main()':
mushrooms.cpp:44:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |     for(int i=0;i<mushroom.size();i++){
      |                 ~^~~~~~~~~~~~~~~~
#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...