| # | Time | Username | Problem | Language | Result | Execution time | Memory | 
|---|---|---|---|---|---|---|---|
| 1168002 | zh_h | Collecting Mushrooms (NOI18_collectmushrooms) | C++20 | 0 ms | 0 KiB | 
#include <bits/stdc++.h>
#define pb push_back
using namespace std;
int main() {
    int R, C, D, K;
    cin >> R >> C >> D >> K;
    vector<vector<char>> grid(R, vector<char>(C))
    vector<pair<int, int>> splinter;
    for (int i = 0; i < R; i ++) {
        for (int j = 0; j < C; j ++) {
            char temp;
            cin >> temp;
            grid[R][C] = temp;
            if (temp == 'S') {
                splinter.pb({i, j});
            }
        }
    }
    vector<vector<int>> mushroom(R, vector<int>(C));
    int harvestable_mushroom = 0;
    for (int z = 0; z < splinter.size(); z ++) {
        int x = splinter[z].first, y = splinter[z].second;
        int first_row = min(0, x-D), last_row = max(R-1, x+D);
        int first_col = min(0, y-D), last_col = max(C-1, y+D);
        for (int i = first_row; i <= last_row; i ++) {
            for (int j = firt_col; j <= lasr_col; j ++) {
                if (grid[i][j] == 'M') {
                    mushroom[i][j]++;
                }
                if (mushroom[i][j] >= K) {
                    grid[i][j] == '.';
                    harvestable_mushroom ++;
                }
            }
        }
    }
    cout << harvestable_mushroom << endl;
}
