답안 #533750

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
533750 2022-03-07T06:04:45 Z kebine Collecting Mushrooms (NOI18_collectmushrooms) C++17
100 / 100
19 ms 10408 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';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 332 KB Output is correct
6 Correct 0 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 360 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 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
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 1100 KB Output is correct
2 Correct 4 ms 1100 KB Output is correct
3 Correct 4 ms 1228 KB Output is correct
4 Correct 4 ms 1100 KB Output is correct
5 Correct 4 ms 1192 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 7464 KB Output is correct
2 Correct 19 ms 10296 KB Output is correct
3 Correct 17 ms 10344 KB Output is correct
4 Correct 16 ms 7848 KB Output is correct
5 Correct 18 ms 10408 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 332 KB Output is correct
6 Correct 0 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 360 KB Output is correct
10 Correct 1 ms 204 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 4 ms 1100 KB Output is correct
18 Correct 4 ms 1228 KB Output is correct
19 Correct 4 ms 1100 KB Output is correct
20 Correct 4 ms 1192 KB Output is correct
21 Correct 14 ms 7464 KB Output is correct
22 Correct 19 ms 10296 KB Output is correct
23 Correct 17 ms 10344 KB Output is correct
24 Correct 16 ms 7848 KB Output is correct
25 Correct 18 ms 10408 KB Output is correct
26 Correct 17 ms 4300 KB Output is correct
27 Correct 16 ms 4424 KB Output is correct
28 Correct 14 ms 3432 KB Output is correct
29 Correct 14 ms 3432 KB Output is correct
30 Correct 16 ms 5012 KB Output is correct