Submission #321047

# Submission time Handle Problem Language Result Execution time Memory
321047 2020-11-10T17:41:44 Z arujbansal Collecting Mushrooms (NOI18_collectmushrooms) C++17
100 / 100
22 ms 8172 KB
#include <bits/stdc++.h>

#define FAST_IO ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
#define setIO(i, o) freopen(i, "r", stdin), freopen(o, "w", stdout)
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int) (x).size()
#define lc(i) 2*i
#define rc(i) 2*i+1
//#define int long long
using namespace std;
using ll = long long;
using ii = pair<int, int>;
using vii = vector<ii>;
using vi = vector<int>;
using vvi = vector<vi>;
using vb = vector<bool>;
using vvb = vector<vb>;

const int N = 1e5 + 5, MOD = 1e9 + 7, INF = 1e9 + 5;

signed main() {
    FAST_IO;
#ifdef arujbansal_local
    setIO("input.txt", "output.txt");
#endif

    int n, m, d, k;
    cin >> n >> m >> d >> k;

    vvi dp(n + 2, vi(m + 2, 0));

    char grid[n + 2][m + 2];
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            cin >> grid[i][j];
            if (grid[i][j] != 'S') continue;

            dp[max(1, i - d)][max(1, j - d)]++;
            dp[min(n, i + d) + 1][max(1, j - d)]--;

            dp[max(1, i - d)][min(m, j + d) + 1]--;
            dp[min(n, i + d) + 1][min(m, j + d) + 1]++;
        }
    }

    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= m; j++)
            dp[i][j] += dp[i - 1][j];

    int ans = 0;

    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            dp[i][j] += dp[i][j - 1];
            ans += (grid[i][j] == 'M' && dp[i][j] >= k);
        }
    }

    cout << ans;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 0 ms 364 KB Output is correct
7 Correct 1 ms 360 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 0 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 1260 KB Output is correct
2 Correct 5 ms 1388 KB Output is correct
3 Correct 6 ms 1772 KB Output is correct
4 Correct 6 ms 1516 KB Output is correct
5 Correct 7 ms 1644 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 8172 KB Output is correct
2 Correct 15 ms 8172 KB Output is correct
3 Correct 15 ms 8172 KB Output is correct
4 Correct 22 ms 8172 KB Output is correct
5 Correct 17 ms 8172 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 0 ms 364 KB Output is correct
7 Correct 1 ms 360 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 0 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 5 ms 1260 KB Output is correct
17 Correct 5 ms 1388 KB Output is correct
18 Correct 6 ms 1772 KB Output is correct
19 Correct 6 ms 1516 KB Output is correct
20 Correct 7 ms 1644 KB Output is correct
21 Correct 19 ms 8172 KB Output is correct
22 Correct 15 ms 8172 KB Output is correct
23 Correct 15 ms 8172 KB Output is correct
24 Correct 22 ms 8172 KB Output is correct
25 Correct 17 ms 8172 KB Output is correct
26 Correct 17 ms 4204 KB Output is correct
27 Correct 14 ms 3436 KB Output is correct
28 Correct 18 ms 3436 KB Output is correct
29 Correct 15 ms 3436 KB Output is correct
30 Correct 16 ms 3948 KB Output is correct