Submission #586315

# Submission time Handle Problem Language Result Execution time Memory
586315 2022-06-30T06:42:20 Z Jomnoi Collecting Mushrooms (NOI18_collectmushrooms) C++17
100 / 100
40 ms 29728 KB
#include <bits/stdc++.h>
using namespace std;

int R, C;
vector <vector <char>> s;
vector <vector <int>> fenwick;

void update(int x, int y, int v) {
    for(int i = x; i <= R; i += (i & -i)) {
        for(int j = y; j <= C; j += (j & -j)) {
            fenwick[i][j] += v;
        }
    }
}

int query(int x, int y) {
    int res = 0;
    for(int i = x; i >= 1; i -= (i & -i)) {
        for(int j = y; j >= 1; j -= (j & -j)) {
            res += fenwick[i][j];
        }
    }
    return res;
}

int main() {
    cin.tie(nullptr)->sync_with_stdio(false);

    int D, K;
    cin >> R >> C >> D >> K;

    s.resize(R + 10, vector <char> (C + 10));
    for(int i = 1; i <= R; i++) {
        for(int j = 1; j <= C; j++) {
            cin >> s[i][j];
        }
    }

    fenwick.resize(R + 10, vector <int> (C + 10, 0));
    for(int i = 1; i <= R; i++) {
        for(int j = 1; j <= C; j++) {
            if(s[i][j] == 'S') {
                int minx = max(1, i - D), miny = max(1, j - D);
                int maxx = min(R, i + D), maxy = min(C, j + D);

                update(minx, miny, 1);
                update(minx, maxy + 1, -1);
                update(maxx + 1, miny, -1);
                update(maxx + 1, maxy + 1, 1);
            }
        }
    }

    int ans = 0;
    for(int i = 1; i <= R; i++) {
        for(int j = 1; j <= C; j++) {
            if(s[i][j] == 'M' and query(i, j) >= K) {
                ans++;
            }
        }
    }
    cout << ans;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 316 KB Output is correct
3 Correct 1 ms 328 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 1492 KB Output is correct
2 Correct 4 ms 1492 KB Output is correct
3 Correct 5 ms 1876 KB Output is correct
4 Correct 5 ms 1492 KB Output is correct
5 Correct 4 ms 1620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 29648 KB Output is correct
2 Correct 30 ms 29668 KB Output is correct
3 Correct 25 ms 29728 KB Output is correct
4 Correct 39 ms 29664 KB Output is correct
5 Correct 27 ms 29668 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 316 KB Output is correct
13 Correct 1 ms 328 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 4 ms 1492 KB Output is correct
17 Correct 4 ms 1492 KB Output is correct
18 Correct 5 ms 1876 KB Output is correct
19 Correct 5 ms 1492 KB Output is correct
20 Correct 4 ms 1620 KB Output is correct
21 Correct 26 ms 29648 KB Output is correct
22 Correct 30 ms 29668 KB Output is correct
23 Correct 25 ms 29728 KB Output is correct
24 Correct 39 ms 29664 KB Output is correct
25 Correct 27 ms 29668 KB Output is correct
26 Correct 28 ms 5972 KB Output is correct
27 Correct 21 ms 3388 KB Output is correct
28 Correct 40 ms 3924 KB Output is correct
29 Correct 27 ms 3796 KB Output is correct
30 Correct 21 ms 5324 KB Output is correct