제출 #154604

#제출 시각아이디문제언어결과실행 시간메모리
154604dolphingarlicCollecting Mushrooms (NOI18_collectmushrooms)C++14
19 / 100
33 ms7020 KiB
#include <bits/stdc++.h>
#define FOR(i, x, y) for (int i = x; i < y; i++)
typedef long long ll;
using namespace std;

int r, c;
vector<vector<int>> bit;
vector<pair<int, int>> shrooms;

void update(int x, int y) {
    for (; x <= r; x += (x & (-x))) for (; y <= c; y += (y & (-y))) bit[x][y]++;
}
int query(int x, int y) {
    int ans = 0;
    for (; x; x -= (x & (-x))) for (; y; y -= (y & (-y))) ans += bit[x][y];
    return ans;
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int d, k;
    cin >> r >> c >> d >> k;
    bit.resize(r + 1);
    FOR(i, 1, r + 1) bit[i].resize(c + 1);

    FOR(i, 1, r + 1) {
        FOR(j, 1, c + 1) {
            char c;
            cin >> c;
            if (c == 'S') update(i, j);
            else if (c == 'M') shrooms.push_back({i, j});
        }
    }

    int ans = 0;
    for (pair<int, int> i : shrooms) {
        int x1 = min(r, i.first + d), x2 = max(0, i.first - d - 1), y1 = min(c, i.second + d), y2 = max(0, i.second - d - 1);
        int cnt = query(x1, y1) - query(x2, y1) - query(x1, y2) + query(x2, y2);
        if (cnt >= k) ans++;
    }
    cout << ans;
    return 0;
}
#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...