Submission #500723

#TimeUsernameProblemLanguageResultExecution timeMemory
500723pootyCollecting Mushrooms (NOI18_collectmushrooms)C++17
100 / 100
13 ms8484 KiB
#define REP(i, n) for(int i = 0; i < n; i ++)
#define REPL(i,m, n) for(int i = m; i < n; i ++)
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define SORT(arr) sort(arr.begin(), arr.end())
#define LSOne(S) ((S)&-(S))
#define M_PI 3.1415926535897932384
#define INF 999999999
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef double ld;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	int r,c,d,k;cin>>r>>c>>d>>k;
	vector<string> arr(r);
	REP(i, r) {
		cin>>arr[i];
	}
	vector<vii> actions(r);
	REP(i, r) {
		REP(j, c) {
			if (arr[i][j] == 'S') {
				int si = max(0, i-d);
				int ei = i+d+1;
				int sj = max(0, j-d);
				int ej = j+d+1;
				actions[si].push_back({sj, 1});
				if (ej < c) {
					actions[si].push_back({ej, -1});
				}
				if (ei < r) {
					actions[ei].push_back({sj, -1});
					if (ej < c) {
						actions[ei].push_back({ej, 1});
					}
				}
			}
		}
	}
	vvi amt(r, vi(c));
	vi diffarr(c, 0);
	REP(i, r) {
		for (auto [idx, co]: actions[i]) {
			diffarr[idx] += co;
		}
		int cur = 0;
		REP(j, c) {
			cur += diffarr[j];
			amt[i][j] = cur;
		}
	}
	int tot = 0;
	REP(i, r) {
		REP(j, c) {
			if (arr[i][j] == 'M' && amt[i][j] >= k) {
				tot++;
			}
		}
	}cout<<tot;
}
#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...