Submission #534848

# Submission time Handle Problem Language Result Execution time Memory
534848 2022-03-09T04:05:27 Z makanhulia Collecting Mushrooms (NOI18_collectmushrooms) C++17
100 / 100
19 ms 8900 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
const ll mod = 1e9 + 7;
#pragma GCC optimize("Ofast")
#define vi vector<int>
#define vll vector<ll>
#define pii pair<int, int>
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define sc second
#define endl '\n'
#define gl ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

int r, c, d, k;
char x;

int main()
{
  gl
  cin >> r >> c >> d >> k;
  int grid[r + 1][c + 1];
  memset(grid, 0, sizeof(grid));
  vector<pii > v;
  
  for(int i = 1; i <= r; i++){
    for(int j = 1; j <= c; j++){
      cin >> x;
      if(x == 'M')
        v.pb({i, j});
      if(x == 'S')
        grid[i][j]++;
    }
  }
  
  for(int i = 1; i <= r; i++){
    for(int j = 1; j <= c; j++){
      grid[i][j] += grid[i - 1][j] + grid[i][j - 1] - grid[i - 1][j - 1];
    }
  }
  
  int ans = 0;
  for(auto i : v){
    int x = i.fi, y = i.sc;
    pii L = make_pair(max(1, x - d), max(1, y - d));
    pii R = make_pair(min(x + d, r), min(y + d, c));
    ans += (grid[R.fi][R.sc] - grid[R.fi][L.sc - 1] - grid[L.fi - 1][R.sc] + grid[L.fi-1][L.sc-1] >= k);
  }
  
  cout << ans << endl;
}
# 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 1 ms 308 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 1 ms 308 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 312 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1284 KB Output is correct
2 Correct 4 ms 1312 KB Output is correct
3 Correct 4 ms 1484 KB Output is correct
4 Correct 4 ms 1228 KB Output is correct
5 Correct 4 ms 1356 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 6728 KB Output is correct
2 Correct 16 ms 8892 KB Output is correct
3 Correct 19 ms 8900 KB Output is correct
4 Correct 14 ms 6848 KB Output is correct
5 Correct 17 ms 8840 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 1 ms 308 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 312 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 460 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 3 ms 1284 KB Output is correct
17 Correct 4 ms 1312 KB Output is correct
18 Correct 4 ms 1484 KB Output is correct
19 Correct 4 ms 1228 KB Output is correct
20 Correct 4 ms 1356 KB Output is correct
21 Correct 14 ms 6728 KB Output is correct
22 Correct 16 ms 8892 KB Output is correct
23 Correct 19 ms 8900 KB Output is correct
24 Correct 14 ms 6848 KB Output is correct
25 Correct 17 ms 8840 KB Output is correct
26 Correct 15 ms 3780 KB Output is correct
27 Correct 14 ms 4800 KB Output is correct
28 Correct 13 ms 3788 KB Output is correct
29 Correct 12 ms 3868 KB Output is correct
30 Correct 12 ms 4924 KB Output is correct