This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#define ll long long
#define pll pair<ll, ll>
#define pii pair<int, int>
#define pff pair<float, float>
#define coutpair(p) cout << p.first << " " << p.second << "\n"
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_multiset;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
ll r, c, d, k; cin >> r >> c >> d >> k;
char arr[r+1][c+1];
int pre[r+1][c+1];
memset(pre, 0, sizeof(pre));
for (int i=1; i<=r; i++) {
for (int j=1; j<=c; j++) {
cin >> arr[i][j];
if (arr[i][j] == 'S') pre[i][j] = 1;
else pre[i][j] = 0;
pre[i][j] = pre[i][j] + pre[i - 1][j] + pre[i][j - 1] - pre[i - 1][j - 1];
}
}
ll ans = 0;
for (int i=1; i<=r; i++) {
for (int j=1; j<=c; j++) {
if (arr[i][j] == 'M') {
int x1 = i - d;
int y1 = j - d;
int x2 = i + d;
int y2 = j + d;
if (x1 <= 0) x1 = 1;
if (y1 <= 0) y1 = 1;
if (x2 > r) x2 = r;
if (y2 > c) y2 = c;
if (pre[x2][y2] - pre[x1 - 1][y2] - pre[x2][y1 - 1] + pre[x1 - 1][y1 - 1] >= k) {
ans = ans + 1;
}
}
}
}
cout << ans;
return 0;
}
# | 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... |