Submission #154604

# Submission time Handle Problem Language Result Execution time Memory
154604 2019-09-23T09:51:24 Z dolphingarlic Collecting Mushrooms (NOI18_collectmushrooms) C++14
19 / 100
33 ms 7020 KB
#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 time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 3 ms 508 KB Output is correct
3 Incorrect 3 ms 376 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 3 ms 508 KB Output is correct
3 Incorrect 3 ms 376 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 1280 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 23 ms 4848 KB Output is correct
2 Correct 33 ms 7020 KB Output is correct
3 Correct 27 ms 7020 KB Output is correct
4 Correct 33 ms 4976 KB Output is correct
5 Correct 30 ms 7020 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 3 ms 508 KB Output is correct
3 Incorrect 3 ms 376 KB Output isn't correct
4 Halted 0 ms 0 KB -