Submission #533751

# Submission time Handle Problem Language Result Execution time Memory
533751 2022-03-07T06:06:18 Z kebine Collecting Mushrooms (NOI18_collectmushrooms) C++17
100 / 100
18 ms 10416 KB
#include <bits/stdc++.h>
using namespace std;

int n, m, d, k;
pair<int,int> g(pair<int,int> a, int d){
  int x = a.first, y = a.second;
  x = max(1, min(x+d, n));
  y = max(1, min(y+d, m));
  return {x, y};
}

int main(){
  cin.tie(0) -> ios_base::sync_with_stdio(0);

  cin >> n >> m >> d >> k;
  vector<vector<int>> ps(n + 1, vector<int>(m + 1));
  vector<pair<int,int>> v;
  for(int i=1;i<=n;i++)
    for(int j=1;j<=m;j++){
      char a;
      cin >> a;
      if(a == 'M')
      {
        v.push_back({i, j});
      }
      else if(a == 'S')
      {
        ps[i][j]++;
      }
    }
  for(int i=1;i<=n;i++)
  {
    for(int j=1;j<=m;j++)
    {
      ps[i][j] += ps[i-1][j] + ps[i][j-1] - ps[i-1][j-1];
    }
  }
  int ans = 0;
  for(auto i : v){
    auto se = g(i, d);
    auto fi = g(i, -d);
    ans += ((long long)ps[se.first][se.second] - ps[se.first][fi.second-1] - ps[fi.first-1][se.second] + ps[fi.first-1][fi.second-1]) >= k;
  }  
  cout << ans << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 308 KB Output is correct
10 Correct 1 ms 208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 1100 KB Output is correct
2 Correct 3 ms 1132 KB Output is correct
3 Correct 5 ms 1228 KB Output is correct
4 Correct 4 ms 1100 KB Output is correct
5 Correct 4 ms 1196 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 7464 KB Output is correct
2 Correct 18 ms 10364 KB Output is correct
3 Correct 18 ms 10396 KB Output is correct
4 Correct 16 ms 7760 KB Output is correct
5 Correct 18 ms 10416 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 308 KB Output is correct
10 Correct 1 ms 208 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 460 KB Output is correct
14 Correct 0 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 4 ms 1100 KB Output is correct
17 Correct 3 ms 1132 KB Output is correct
18 Correct 5 ms 1228 KB Output is correct
19 Correct 4 ms 1100 KB Output is correct
20 Correct 4 ms 1196 KB Output is correct
21 Correct 15 ms 7464 KB Output is correct
22 Correct 18 ms 10364 KB Output is correct
23 Correct 18 ms 10396 KB Output is correct
24 Correct 16 ms 7760 KB Output is correct
25 Correct 18 ms 10416 KB Output is correct
26 Correct 13 ms 4300 KB Output is correct
27 Correct 17 ms 4416 KB Output is correct
28 Correct 13 ms 3432 KB Output is correct
29 Correct 12 ms 3432 KB Output is correct
30 Correct 14 ms 5060 KB Output is correct