Submission #654647

#TimeUsernameProblemLanguageResultExecution timeMemory
654647horiseunCollecting Mushrooms (NOI18_collectmushrooms)C++11
100 / 100
28 ms31400 KiB
#include <iostream> #include <tuple> #include <vector> using namespace std; #define f first #define s second int r, c, d, k, ans, spr, r1, r2, c1, c2; vector<pair<int, int>> mushrooms; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> r >> c >> d >> k; vector<vector<int>> grid(r + 5, vector<int> (c + 5, 0)); vector<vector<int>> pref(r + 5, vector<int> (c + 5, 0)); for (int i = 1; i <= r; i++) { for (int j = 1; j <= c; j++) { char x; cin >> x; if (x == 'M') { mushrooms.push_back({i, j}); } else if (x == 'S') { grid[i][j] = 1; } } } for (int i = 1; i <= r; i++) { for (int j = 1; j <= c; j++) { pref[i][j] = pref[i - 1][j] + pref[i][j - 1] - pref[i - 1][j - 1] + grid[i][j]; } } for (pair<int, int> p : mushrooms) { r1 = (p.f + d >= r ? r : p.f + d); c1 = (p.s + d >= c ? c : p.s + d); r2 = (p.f - d - 1 >= 0 ? p.f - d - 1 : 0); c2 = (p.s - d - 1 >= 0 ? p.s - d - 1 : 0); spr = pref[r1][c1] - pref[r1][c2] - pref[r2][c1] + pref[r2][c2]; if (spr >= k) ans++; } cout << ans << "\n"; }
#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...