Submission #538272

#TimeUsernameProblemLanguageResultExecution timeMemory
538272four_specksCollecting Mushrooms (NOI18_collectmushrooms)C++17
100 / 100
25 ms12684 KiB
#include <bits/stdc++.h> using namespace std; inline namespace { } // namespace /* - use 2D prefix sums to find number of sprinklers covering a square */ void solve() { int r, c, d, k; cin >> r >> c >> d >> k; vector pref(r + 1, vector(c + 1, 0)); vector grid(r, vector<bool>(c, 0)); for (int i = 0; i < r; i++) { for (int j = 0; j < c; j++) { char s; cin >> s; if (s == 'S') { pref[max(0, i - d)][max(0, j - d)]++; pref[max(0, i - d)][min(c, j + d + 1)]--; pref[min(r, i + d + 1)][max(0, j - d)]--; pref[min(r, i + d + 1)][min(c, j + d + 1)]++; } else if (s == 'M') grid[i][j] = 1; } } vector a(r + 2, vector(c + 2, 0)); for (int i = 0; i <= r; i++) { for (int j = 0; j <= c; j++) a[i + 1][j + 1] = a[i + 1][j] + a[i][j + 1] - a[i][j] + pref[i][j]; } int cnt = 0; for (int i = 0; i < r; i++) { for (int j = 0; j < c; j++) { if (grid[i][j] && a[i + 1][j + 1] >= k) cnt++; } } cout << cnt << '\n'; } int main() { ios_base::sync_with_stdio(false), cin.tie(NULL); solve(); 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...