Submission #873531

# Submission time Handle Problem Language Result Execution time Memory
873531 2023-11-15T09:06:16 Z dsyz Collecting Mushrooms (NOI18_collectmushrooms) C++17
100 / 100
19 ms 17576 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  ios_base::sync_with_stdio(false);cin.tie(0);
  ll R,C,D,K;
  ll sum = 0;
  ll num = 0;
  cin>>R>>C>>D>>K;
  char arr[R + 1][C + 1];
  ll dp[R + 1][C + 1];
  ll ans[R + 1][C + 1];
  //memset(arr,0,sizeof(arr));
  memset(dp,0,sizeof(dp));
  memset(ans,0,sizeof(ans));
  for(ll i = 1;i <= R;i++){
    for(ll j = 1;j <= C;j++){
      cin>>arr[i][j];
    }
  }
  for(ll i = 1;i <= R;i++){
    for(ll j = 1;j <= C;j++){
      if(arr[i][j] == 'S'){
        dp[i][j] = 1;
        //num += 1;
        //dp[i][j] = num;
      }
      //dp[i][j] = num;
    }
  }
  for(ll i = 1;i <= R;i++){
    for(ll j = 0;j <= C;j++){
      ans[i][j] = ans[i - 1][j] + ans[i][j - 1] - ans[i - 1][j - 1] + dp[i][j];
    }
  }  
  // for(ll i = 1;i <= C;i++){
  //   for(ll j = 1;j <= R;j++){
  //     if(arr[j][i] == 'S'){
  //       num += 1;
  //       //dp[i][j] = num;
  //     }
  //     dp[j][i] = num;
  //   }
  // }  
  for(ll i = 1;i <= R;i++){
    for(ll j = 1;j <= C;j++){
      //cout<<"ARR: "<<arr[i][j]<<" "<<i<<" "<<j<<'\n';
      if(arr[i][j] == 'M'){
        ll a = i - D;
        ll b = j - D;
        ll c = i + D;
        ll d = j + D;
        if(a <= 0){
          a = 1;
        }
        if(b <= 0){
          b = 1;
        }
        if(c > R){
          c = R;
        }
        if(d > C){
          d = C;
        }
        //a = 0,b = 4,c = 2;d = 6(5)
        //cout<<"M: "<<i<<" "<<dp[c][d] - dp[a - 1][d] - dp[c][b - 1] + dp[a - 1][b - 1]<<'\n';
        if(ans[c][d] - ans[a - 1][d] - ans[c][b - 1] + ans[a - 1][b - 1] >= K){
          sum += 1;
        } 
      }
    }
  }
  cout<<sum<<'\n';
}

Compilation message

mushrooms.cpp: In function 'int main()':
mushrooms.cpp:8:6: warning: unused variable 'num' [-Wunused-variable]
    8 |   ll num = 0;
      |      ^~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 356 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 3928 KB Output is correct
2 Correct 5 ms 3928 KB Output is correct
3 Correct 6 ms 4700 KB Output is correct
4 Correct 5 ms 3928 KB Output is correct
5 Correct 6 ms 4188 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 17576 KB Output is correct
2 Correct 18 ms 17500 KB Output is correct
3 Correct 19 ms 17452 KB Output is correct
4 Correct 18 ms 17316 KB Output is correct
5 Correct 19 ms 17496 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 356 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 5 ms 3928 KB Output is correct
17 Correct 5 ms 3928 KB Output is correct
18 Correct 6 ms 4700 KB Output is correct
19 Correct 5 ms 3928 KB Output is correct
20 Correct 6 ms 4188 KB Output is correct
21 Correct 18 ms 17576 KB Output is correct
22 Correct 18 ms 17500 KB Output is correct
23 Correct 19 ms 17452 KB Output is correct
24 Correct 18 ms 17316 KB Output is correct
25 Correct 19 ms 17496 KB Output is correct
26 Correct 13 ms 9052 KB Output is correct
27 Correct 12 ms 9052 KB Output is correct
28 Correct 13 ms 9212 KB Output is correct
29 Correct 13 ms 9304 KB Output is correct
30 Correct 14 ms 9328 KB Output is correct