제출 #894632

#제출 시각아이디문제언어결과실행 시간메모리
894632IWKRCollecting Mushrooms (NOI18_collectmushrooms)C++17
100 / 100
12 ms9744 KiB
#include <bits/stdc++.h> using namespace std; #define int long long int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int r, c, d, k; cin >> r >> c >> d >> k; char arr[r + 1][c + 1]; int ss[r + 1][c + 1]; memset(ss, 0, sizeof ss); for (int i = 1; i <= r; i++) { for (int j = 1; j <= c; j++) { cin >> arr[i][j]; if (arr[i][j] == 'S') { ss[i][j] = 1; } else { ss[i][j] = 0; } ss[i][j] = ss[i][j] + ss[i - 1][j] + ss[i][j - 1] - ss[i - 1][j - 1]; } } int ans = 0; for (int i = 1; i <= r; i++) { for (int j = 1; j <= c; j++) { if (arr[i][j] == 'M') { int x1 = i - d; int y1 = j - d; int x2 = i + d; int y2 = j + d; if (x1 <= 0) { x1 = 1; } if (y1 <= 0) { y1 = 1; } if (x2 > r) { x2 = r; } if (y2 > c) { y2 = c; } if (ss[x2][y2] - ss[x1 - 1][y2] - ss[x2][y1 - 1] + ss[x1 - 1][y1 - 1] >= k) { ans = ans + 1; } } } } cout << ans; }
#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...