Submission #535009

#TimeUsernameProblemLanguageResultExecution timeMemory
535009christinelynnCollecting Mushrooms (NOI18_collectmushrooms)C++17
60 / 100
2075 ms8448 KiB
#include <bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
typedef long long ll;
using namespace std;

struct range{
  ll x1,x2,y1,y2;
};

ll r, c, d, k, ans;
vector<range>vec;
vector<pair<ll,ll>>shroom;
map<pair<ll,ll>,ll>mp;

bool inside(ll x, ll y){
  return (x >= 1 && y >= 1 && x <= r && y <= c);
}

void check(ll x, ll y){
  for(range z : vec){
    if(x >= z.x1 && x <= z.x2 && y >= z.y1 && y <= z.y2){
      mp[{x,y}]++;
      if(mp[{x,y}] == k){
        ans++;
      }
    }
  }
}

int main(){
  ios_base::sync_with_stdio(0); cin.tie(0);
  cin >> r >> c >> d >> k;
  vector<pair<ll,ll>>spr;
  for(int i = 1; i <= r; i++){
    for(int j = 1; j <= c; j++){
      char f; cin >> f;
      if(f == 'M'){
        shroom.pb({i,j});
      }
      else if(f == 'S'){
        range x;
        x.x1 = i-d; x.x2 = i+d; x.y1 = j-d; x.y2 = j+d;
        vec.pb(x);
      }
    }
  }
  for(pair<ll,ll> x : shroom){
    check(x.fi, x.se);
  }
  cout << ans << "\n";
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...