제출 #1016302

#제출 시각아이디문제언어결과실행 시간메모리
1016302toast12Collecting Mushrooms (NOI18_collectmushrooms)C++14
100 / 100
24 ms14776 KiB
#include <bits/stdc++.h> using namespace std; int main() { int r, c, d, k; cin >> r >> c >> d >> k; vector<vector<int>> ps(r+2, vector<int>(c+2)); vector<pair<int, int>> mushrooms; for (int i = 1; i <= r; i++) { for (int j = 1; j <= c; j++) { char x; cin >> x; if (x == 'S') ps[i][j]++; else if (x == 'M') mushrooms.push_back({i, j}); } } for (int j = 1; j <= c; j++) { for (int i = 1; i <= r; i++) { ps[i][j+1] += ps[i][j]; ps[i][j] += ps[i-1][j]; } } int ans = 0; for (auto m : mushrooms) { int row = m.first, col = m.second; int left = max(1, col-d); int right = min(c, col+d); int up = max(1, row-d); int down = min(r, row+d); int cnt = ps[down][right]-ps[up-1][right]-ps[down][left-1]+ps[up-1][left-1]; if (cnt >= 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...