Submission #1131521

#TimeUsernameProblemLanguageResultExecution timeMemory
1131521minggaCollecting Mushrooms (NOI18_collectmushrooms)C++17
100 / 100
28 ms36092 KiB
#include "bits/stdc++.h"

using namespace std;

#define ln "\n"
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define int long long
const int mod = 1e9 + 7;
const int inf = 2e18;
int r, c, d, k;
vector<vector<int>> a;
signed main() {
	cin.tie(0) -> sync_with_stdio(0);
	#define task ""
	if(fopen(task ".INP", "r")) {
		freopen(task ".INP", "r", stdin);
		freopen(task ".OUT", "w", stdout);
	}
	cin >> r >> c >> d >> k;
	a.resize(r + 5, vector<int>(c + 5, 0));
	vector<pair<int, int>> vec;
	for(int i = 1; i <= r; i++) {
		for(int j = 1; j <= c; j++) {
			char x; cin >> x;
			if(x == 'M') {
				vec.pb({i, j});
			} else if(x == 'S') {
				int x1 = max(1ll, i - d);
				int y1 = max(1ll, j - d);
				int x2 = min(r, i + d);
				int y2 = min(c, j + d);
				a[x1][y1]++;
				a[x1][y2 + 1]--;
				a[x2 + 1][y1]--;
				a[x2 + 1][y2 + 1]++;
			}
		}
	}
	for(int i = 1; i <= r; i++) {
		for(int j = 1; j <= c; j++) {
			a[i][j] += a[i - 1][j] + a[i][j - 1] - a[i - 1][j - 1];
		}
	}
	int ans = 0;
	for(auto x : vec) {
		if(a[x.fi][x.se] >= k) ans++;
	}
	cout << ans << ln;
    cerr << "\nTime: " << clock() * 1000 / CLOCKS_PER_SEC;
}

Compilation message (stderr)

mushrooms.cpp: In function 'int main()':
mushrooms.cpp:20:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |                 freopen(task ".INP", "r", stdin);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
mushrooms.cpp:21:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |                 freopen(task ".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...