Submission #379906

#TimeUsernameProblemLanguageResultExecution timeMemory
379906rocks03Collecting Mushrooms (NOI18_collectmushrooms)C++14
100 / 100
12 ms9088 KiB
//#pragma GCC target("avx2")
//#pragma GCC optimization("O3")
//#pragma GCC optimization("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define ff first
#define ss second
#define pb push_back
#define SZ(x) ((int)(x).size())
#define all(x) x.begin(), x.end()
#define debug(x) cout << #x << ": " << x << " "
#define nl cout << "\n"
#define rep(i, a, b) for(int i = (a); i < (b); i++)
#define per(i, a, b) for(int i = (a); i >= (b); i--)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

void solve(){
    int R, C, D, K;
    cin >> R >> C >> D >> K;
    int a[R + 1][C + 1]; memset(a, 0, sizeof(a));
    queue<pii> q;
    rep(i, 0, R){
        string s; cin >> s;
        rep(j, 0, C){
            if(s[j] == 'M'){
                q.push({i, j});
            } else if(s[j] == 'S'){
                int mnx = max(0, i - D), mxx = min(R, i + D + 1);
                int mny = max(0, j - D), mxy = min(C, j + D + 1);
                a[mnx][mny]++;
                a[mnx][mxy]--;
                a[mxx][mny]--;
                a[mxx][mxy]++;
            }
        }
    }
    rep(i, 0, R){
        rep(j, 0, C){
            a[i][j + 1] += a[i][j];
        }
    }
    rep(i, 0, R){
        rep(j, 0, C){
            a[i + 1][j] += a[i][j];
        }
    }
    int ans = 0;
    while(!q.empty()){
        auto [x, y] = q.front();
        q.pop();
        if(a[x][y] >= K)
            ans++;
    }
    cout << ans;
}

int main(){
    ios_base::sync_with_stdio(false), cin.tie(nullptr);
    solve();
    return 0;
}

Compilation message (stderr)

mushrooms.cpp: In function 'void solve()':
mushrooms.cpp:52:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   52 |         auto [x, y] = q.front();
      |              ^
#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...