fork download
  1. #include <bits/stdc++.h>
  2. #define int long long
  3.  
  4. using namespace std;
  5.  
  6. struct info {
  7. int x, y;
  8. };
  9.  
  10. int m, n, d, k;
  11. vector<info> market;
  12. vector<info> house;
  13.  
  14.  
  15. int32_t main() {
  16. ios_base::sync_with_stdio(false);
  17. cin.tie(NULL);
  18.  
  19. freopen("KHUDANCU.INP", "r", stdin);
  20. freopen("KHUDANCU.OUT", "w", stdout);
  21.  
  22. cin >> m >> n >> d >> k;
  23.  
  24. for (int i = 1; i <= m; i += 1) {
  25. for (int j = 1; j <= n; j += 1) {
  26. char c;
  27. cin >> c;
  28. if (c == 'P') house.push_back({i, j});
  29. if (c == 'M') market.push_back({i, j});
  30. }
  31. }
  32.  
  33. int res = 0;
  34. for (info a : house) {
  35. int check = 0;
  36.  
  37. for (info b : market) {
  38. if (abs(a.x - b.x) <= d && abs(a.y - b.y) <= d) {
  39. check += 1;
  40. if (check >= k) {
  41. res += 1;
  42. break;
  43. }
  44. }
  45. }
  46. }
  47.  
  48. cout << res;
  49.  
  50. return 0;
  51. }
  52.  
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
Standard output is empty