Submission #534654

#TimeUsernameProblemLanguageResultExecution timeMemory
534654bonkCollecting Mushrooms (NOI18_collectmushrooms)C++14
100 / 100
17 ms10436 KiB
#include <bits/stdc++.h>

using namespace std;

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

    int r, c, d, k;
    cin >> r >> c >> d >> k;

    int ans = 0;
    int prefix[r + 2][c + 2];
    vector<pair<int, int>>v;
    memset(prefix, 0, sizeof(prefix));

    for(int i = 1; i <= r; i++){
        for(int j = 1; j <= c; j++){
            char x; cin >> x;
            prefix[i][j] = prefix[i - 1][j] + prefix[i][j - 1] - prefix[i - 1][j - 1] + (x == 'S');
            if(x == 'M') v.emplace_back(i, j);
        }
    }

    for(auto &[x, y]: v){
        int TLX = max(1, (x - d));
        int TLY = max(1, (y - d));
        int BRX = min(r, (x + d));
        int BRY = min(c, (y + d));

        int tmp = prefix[BRX][BRY] - prefix[BRX][TLY - 1] - prefix[TLX - 1][BRY] + prefix[TLX - 1][TLY - 1];

        ans += (tmp >= k);
    }

    cout << ans << "\n";

    return 0;
}

Compilation message (stderr)

mushrooms.cpp: In function 'int main()':
mushrooms.cpp:24:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   24 |     for(auto &[x, y]: v){
      |               ^
#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...