Submission #733826

#TimeUsernameProblemLanguageResultExecution timeMemory
733826vjudge1Collecting Mushrooms (NOI18_collectmushrooms)C++17
100 / 100
43 ms49276 KiB
#include<bits/stdc++.h>
using namespace std;

#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define in insert
#define all(x) x.begin(),x.end()
#define pb push_back
#define eb emplace_back
#define ff first
#define ss second

#define int long long
 
typedef long long ll;
typedef vector<int> vi;
typedef set<int> si;
typedef multiset<int> msi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;

template<typename T, typename U>
ostream & operator << (ostream &out, const pair<T, U> &c) {
    out << c.first << ' ' << c.second;
    return out;
}

template<typename T>
ostream & operator << (ostream &out, vector<T> &v) {
    const int sz = v.size();
    for (int i = 0; i < sz; i++) {
        if (i) out << ' ';
        out << v[i];
    }
    return out;
}

template<typename T>
istream & operator >> (istream &in, vector<T> &v) {
    for (T &x : v) in >> x;
    return in;
}

template<typename T>
void mxx(T &a, T b){if(b > a) a = b;}
template<typename T>
void mnn(T &a, T b){if(b < a) a = b;}

void go() {
	int n, m, d, k;
	cin >> n >> m >> d >> k;
	vector<vector<int>> cnt(n + 10, vector<int>(m + 10, 0));
	vector<vector<char>> g(n + 10, vector<char>(m + 10));
	for(int i = 1; i <= n; i++) {
		for(int j = 1; j <= m; j++) {
			cin >> g[i][j];
			if(g[i][j] == 'S') {
				int id = i - d;
				int l1 = j - d;
				int r1 = j + d + 1;
				mxx(l1, 1ll);
				mnn(r1, m + 1);
				mxx(id, 1ll);
				cnt[id][l1]++;
				cnt[id][r1]--;
				id = i + d + 1;
				mnn(id, n + 1);
				cnt[id][l1]--;
				cnt[id][r1]++;
			}
		}
	}
	for(int i = 1; i <= n; i++) {
		for(int j = 1; j <= m; j++) {
			cnt[i][j] += cnt[i][j - 1];
		}
	}
	for(int i = 1; i <= m; i++) {
		for(int j = 1; j <= n; j++) {
			cnt[j][i] += cnt[j - 1][i];
		}
	}
	int ans = 0;
	for(int i = 1; i <= n; i++) {
		for(int j = 1; j <= m; j++) {
			if(cnt[i][j] >= k && g[i][j] == 'M') {
				ans++;
			}
		}
	}
	cout << ans << '\n';
}

signed main() {
    fast;
    int t = 1;
    // cin >> t;
    while(t--) {
        go();
    }
    return 0;
}
#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...