Submission #197414

#TimeUsernameProblemLanguageResultExecution timeMemory
197414quocnguyen1012Collecting Mushrooms (NOI18_collectmushrooms)C++14
100 / 100
45 ms30776 KiB
#include <bits/stdc++.h>

#define fi first
#define se second
#define mp make_pair
#define pb push_back

using namespace std;
typedef long long ll;

vector<vector<char>> type;
int N, M, D, K;
vector<vector<ll>> sum;

void inc(int x1, int y1, int x2, int y2, int val)
{
  sum[x1][y1] += val;
  sum[x1][y2 + 1] -= val;
  sum[x2 + 1][y1] -= val;
  sum[x2 + 1][y2 + 1] += val;
}

signed main(void)
{
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  if (fopen("A.INP", "r")){
    freopen("A.INP", "r", stdin);
    freopen("A.OUT", "w", stdout);
  }
  cin >> N >> M >> D >> K;
  type.assign(N + 5, vector<char>(M + 5));
  sum.assign(N + 5, vector<ll>(M + 5));
  for (int i = 1; i <= N; ++i){
    for (int j = 1; j <= M; ++j){
      cin >> type[i][j];
      if (type[i][j] == 'S'){
        int x1 = max(1, i - D);
        int y1 = max(1, j - D);
        int x2 = min(N, i + D);
        int y2 = min(M, j + D);
        inc(x1, y1, x2, y2, 1);
      }
    }
  }
  int ret = 0;
  for (int i = 1; i <= N; ++i){
    for (int j = 1; j <= M; ++j){
      sum[i][j] += sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1];
      ///cerr << sum[i][j] << " \n"[j == M];
      if (type[i][j] == 'M' && sum[i][j] >= K){
        ++ret;
      }
    }
  }
  cout << ret << '\n';
}

Compilation message (stderr)

mushrooms.cpp: In function 'int main()':
mushrooms.cpp:27:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
     freopen("A.INP", "r", stdin);
     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
mushrooms.cpp:28:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
     freopen("A.OUT", "w", stdout);
     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
#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...