답안 #533805

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
533805 2022-03-07T10:19:38 Z andecaandeci Collecting Mushrooms (NOI18_collectmushrooms) C++17
100 / 100
20 ms 10880 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 312 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 312 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 1 ms 204 KB Output is correct
7 Correct 1 ms 304 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 312 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 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 1220 KB Output is correct
2 Correct 4 ms 1228 KB Output is correct
3 Correct 5 ms 1568 KB Output is correct
4 Correct 4 ms 1228 KB Output is correct
5 Correct 4 ms 1352 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 7964 KB Output is correct
2 Correct 20 ms 10780 KB Output is correct
3 Correct 20 ms 10780 KB Output is correct
4 Correct 19 ms 8288 KB Output is correct
5 Correct 19 ms 10880 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 312 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 1 ms 204 KB Output is correct
7 Correct 1 ms 304 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 312 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 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 4 ms 1220 KB Output is correct
17 Correct 4 ms 1228 KB Output is correct
18 Correct 5 ms 1568 KB Output is correct
19 Correct 4 ms 1228 KB Output is correct
20 Correct 4 ms 1352 KB Output is correct
21 Correct 16 ms 7964 KB Output is correct
22 Correct 20 ms 10780 KB Output is correct
23 Correct 20 ms 10780 KB Output is correct
24 Correct 19 ms 8288 KB Output is correct
25 Correct 19 ms 10880 KB Output is correct
26 Correct 13 ms 4712 KB Output is correct
27 Correct 13 ms 4828 KB Output is correct
28 Correct 13 ms 3808 KB Output is correct
29 Correct 13 ms 3944 KB Output is correct
30 Correct 15 ms 5564 KB Output is correct