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>
#define ii pair<int, int>
using namespace std;
vector<vector<int>> v;
int ans = 0;
queue<ii> q;
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
int N, M, D, K;
cin >> N >> M >> D >> K;
int rd = D * 2 + 1;
for(int i = 0; i < N; i++){
string line;
cin >> line;
vector<int> tmp;
for(int j = 0; j < M; j++){
int qsl = j == 0 ? 0 : tmp[j - 1];
int qsu = i == 0 ? 0 : v[i - 1][j];
int qslu = (i == 0 || j == 0) ? 0 : v[i - 1][j - 1];
tmp.push_back(qsl + qsu - qslu + (line[j] == 'S' ? 1 : 0));
if(line[j] == 'M') q.push({i + D, j + D});
}
v.push_back(tmp);
}
while(!q.empty()){
auto [ni, nj] = q.front();
int mi = min(ni, N - 1), mj = min(nj, M - 1);
int qsu2 = ni - rd < 0 ? 0 : v[ni - rd][mj];
int qsl2 = nj - rd < 0 ? 0 : v[mi][nj - rd];
int qslu2 = (ni - rd < 0 || nj - rd < 0) ? 0 : v[ni - rd][nj - rd];
if(v[mi][mj] - qsl2 - qsu2 + qslu2 >= K) ans++;
q.pop();
}
cout << ans;
}
# | 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... |