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"
using namespace std;
#define int long long
#define fr first
#define sc second
#define eb emplace_back
#define nl '\n'
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define dbg(x...) cerr << "LINE(" << __LINE__ << ") -> " <<"[" << #x << "] = ["; _print(x)
#else
#define dbg(x...)
#endif
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
int R, C, D, K; cin >> R >> C >> D >> K;
int a[R + 2][C + 2] = {};
vector<pair<int, int>> mush;
for(int i = 1; i <= R; ++i) {
for(int j = 1; j <= C; ++j) {
char c; cin >> c;
if(c == '.') continue;
if(c == 'M') {
mush.eb(i, j);
continue;
}
int x, y;
x = max(0LL, i - D); y = max(0LL, j - D);
++a[x][y];
x = min(R + 1, i + D + 1); y = max(0LL, j - D);
--a[x][y];
x = max(0LL, i - D); y = min(C + 1, j + D + 1);
--a[x][y];
x = min(R + 1, i + D + 1); y = min(C + 1, j + D + 1);
++a[x][y];
}
}
for(int i = 0; i <= R + 1; ++i) {
for(int j = 0; j <= C + 1; ++j) {
a[i][j] = a[i][j] + (i ? a[i - 1][j] : 0) + (j ? a[i][j - 1] : 0) - (i && j ? a[i - 1][j - 1] : 0);
/* cout << a[i][j] << ' ' ; */
}
/* cout << nl; */
}
int res = 0;
for(auto [x, y] : mush) {
if(a[x][y] >= K) ++res;
}
cout << res << nl;
}
# | 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... |