# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1131521 | mingga | Collecting Mushrooms (NOI18_collectmushrooms) | C++17 | 28 ms | 36092 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)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |