이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int maxR = 5e5+5;
int r, c, d, k;
string garden[maxR];
int main(){
// bool watered[maxR][maxR];
// memset(watered, false, sizeof(watered));
cin >> r >> c >> d >> k;
for(int i = 0; i<r; i++){
cin >> garden[i];
}
vector<vector<bool>> watered;
vector<vector<int>> kena;
for(int i = 0; i<r; i++){
vector<int> ps;
vector<bool> ps1;
for(int j = 0; j<c; j++){
ps.push_back(0);
ps1.push_back(false);
}
kena.push_back(ps);
watered.push_back(ps1);
}
for(int i = 0; i<r; i++){
for(int j = 0; j<c; j++){
if(garden[i][j]=='S')
{
// atas kiri [i-d][j-d]
// bawah kanan [i+d][j+d]
// atas kanan [i-d][j+d]
// bawah kiri [i+d][j-d]
int atas = max(i-d, 0);
int kiri = max(j-d, 0);
kena[atas][kiri]++;
int kanan = -1, bawah = -1;
if(i+d+1<=r-1) bawah = i+d+1;
if(j+d+1<=c-1) kanan = j+d+1;
if(kanan!=-1) kena[atas][kanan]--;
if(bawah!=-1) kena[bawah][kiri]--;
if(kanan!=-1 && bawah!=-1) kena[kanan][bawah]++;
}
}
}
ll ans = 0;
for(int i = 0; i<r; i++){
for(int j = 0; j<c; j++){
if(i!=0) kena[i][j] += kena[i-1][j];
if(j!=0) kena[i][j] += kena[i][j-1];
if(i!=0 && j!=0) kena[i][j] -= kena[i-1][j-1];
if(garden[i][j]=='M' && kena[i][j] >= k) ans++;
}
// cout << endl;
}
cout << ans << endl;
}
# | 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... |