제출 #1323447

#제출 시각아이디문제언어결과실행 시간메모리
1323447kawhietCollecting Mushrooms (NOI18_collectmushrooms)C++20
100 / 100
18 ms24524 KiB
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n, m, d, k; cin >> n >> m >> d >> k; vector<string> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } vector<vector<int>> p(n + 10, vector<int>(m + 10)); auto add = [&](int x1, int y1, int x2, int y2) { x1++; y1++; x2++; y2++; x1 = max(x1, 1); y1 = max(y1, 1); x2 = min(x2, n); y2 = min(y2, m); p[x1][y1]++; p[x1][y2 + 1]--; p[x2 + 1][y1]--; p[x2 + 1][y2 + 1]++; }; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { if (a[i][j] == 'S') { add(i - d, j - d, i + d, j + d); } } } for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { p[i][j] += p[i - 1][j] + p[i][j - 1] - p[i - 1][j - 1]; } } int ans = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { if (a[i][j] == 'M' && p[i + 1][j + 1] >= k) { ans++; } } } cout << ans << '\n'; 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...