Submission #141282

#TimeUsernameProblemLanguageResultExecution timeMemory
141282meatrowCollecting Mushrooms (NOI18_collectmushrooms)C++17
100 / 100
29 ms11624 KiB
//#pragma GCC optimize("O3") //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native") //#pragma GCC optimize ("unroll-loops") #include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; vector<vector<int>> f, s; int r, c, d, k; void add(int x, int y) { int x1 = max(1, x - d); int y1 = max(1, y - d); int x2 = x + d + 1; int y2 = y + d + 1; f[x1][y1]++; if (y2 <= c) { f[x1][y2]--; } if (x2 <= r) { f[x2][y1]--; } if (x2 <= r && y2 <= c) { f[x2][y2]++; } } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cin >> r >> c >> d >> k; vector<vector<char>> field(r + 1, vector<char>(c + 1)); f.assign(r + 1, vector<int>(c + 1, 0)); s.assign(r + 1, vector<int>(c + 1, 0)); for (int i = 1; i <= r; i++) { for (int j = 1; j <= c; j++) { cin >> field[i][j]; if (field[i][j] == 'S') { add(i, j); } } } int ans = 0; for (int i = 1; i <= r; i++) { for (int j = 1; j <= c; j++) { s[i][j] = s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1] + f[i][j]; if (field[i][j] == 'M' && s[i][j] >= k) { ans++; } } } cout << ans; 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...