#include <bits/stdc++.h>
#define eb emplace_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define svec(x) sort(x.begin(), x.end())
#define press(x) x.erase(unique(x.begin(), x.end()), x.end())
#define lb(x, v) lower_bound(x.begin(), x.end(), v)
#define ub(x, v) upper_bound(x.begin(), x.end(), v)
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
typedef pair<int, LL> pil;
typedef pair<LL, int> pli;
const LL llinf=2000000000000000000;
const LL mod1=1000000007;
const LL mod2=998244353;
const int inf=2000000000;
struct FENWICK{
int tree[100010];
int sum(int i){
LL ans=0;
while(i){
ans+=tree[i];
i-=(i&-i);
}
return ans;
}
int update(int i, LL num){
while(i<=100000){
tree[i]+=num;
i+=(i&-i);
}
}
void cl(){memset(tree, 0, sizeof tree);}
}fen;
int n, m, r, k, p;
vector<char> arr[100010];
vector<int> ans[100010];
vector<int> ndel[100010];
int main(){
scanf("%d %d %d %d", &n, &m, &r, &k);
for(int i=1; i<=n; i++){
arr[i].resize(m+1);
ans[i].resize(m+1);
}
for(int i=1; i<=n; i++){
for(int j=1; j<=m; j++){
scanf(" %c", &arr[i][j]);
}
}
for(int i=1; i<=n; i++){
for(int j=1; j<=m; j++){
if(arr[i][j]=='S'){
fen.update(max(1, j-r), 1);
fen.update(min(m, j+r)+1, -1);
if(i+r<n)ndel[i+r+1].eb(j);
}
}
for(auto j:ndel[i]){
fen.update(max(1, j-r), -1);
fen.update(min(m, j+r)+1, 1);
}
ndel[i].clear();
for(int j=1; j<=m; j++){
if(arr[i][j]=='M'){
ans[i][j]+=fen.sum(j);
}
}
}
fen.cl();
for(int i=n; i>=1; i--){
for(auto j:ndel[i]){
fen.update(max(1, j-r), -1);
fen.update(min(m, j+r)+1, 1);
}
ndel[i].clear();
for(int j=1; j<=m; j++){
if(arr[i][j]=='M'){
ans[i][j]+=fen.sum(j);
if(ans[i][j]>=k)p++;
}
}
for(int j=1; j<=m; j++){
if(arr[i][j]=='S'){
fen.update(max(1, j-r), 1);
fen.update(min(m, j+r)+1, -1);
if(i-r>1)ndel[i-r-1].eb(j);
}
}
}
printf("%d", p);
}
Compilation message
mushrooms.cpp: In member function 'int FENWICK::update(int, LL)':
mushrooms.cpp:37:5: warning: no return statement in function returning non-void [-Wreturn-type]
}
^
mushrooms.cpp: In function 'int main()':
mushrooms.cpp:47:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d %d %d", &n, &m, &r, &k);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
mushrooms.cpp:54:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf(" %c", &arr[i][j]);
~~~~~^~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
7808 KB |
Output is correct |
2 |
Correct |
11 ms |
7808 KB |
Output is correct |
3 |
Correct |
11 ms |
7808 KB |
Output is correct |
4 |
Correct |
10 ms |
7808 KB |
Output is correct |
5 |
Correct |
9 ms |
7808 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
7808 KB |
Output is correct |
2 |
Correct |
11 ms |
7808 KB |
Output is correct |
3 |
Correct |
11 ms |
7808 KB |
Output is correct |
4 |
Correct |
10 ms |
7808 KB |
Output is correct |
5 |
Correct |
9 ms |
7808 KB |
Output is correct |
6 |
Correct |
9 ms |
7808 KB |
Output is correct |
7 |
Correct |
9 ms |
7808 KB |
Output is correct |
8 |
Correct |
12 ms |
7808 KB |
Output is correct |
9 |
Correct |
9 ms |
7808 KB |
Output is correct |
10 |
Correct |
9 ms |
7808 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
7808 KB |
Output is correct |
2 |
Correct |
10 ms |
7808 KB |
Output is correct |
3 |
Correct |
10 ms |
7808 KB |
Output is correct |
4 |
Correct |
10 ms |
7808 KB |
Output is correct |
5 |
Correct |
9 ms |
7808 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
23 ms |
9080 KB |
Output is correct |
2 |
Correct |
28 ms |
8952 KB |
Output is correct |
3 |
Correct |
27 ms |
9216 KB |
Output is correct |
4 |
Correct |
26 ms |
8960 KB |
Output is correct |
5 |
Correct |
25 ms |
9008 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
57 ms |
20856 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
7808 KB |
Output is correct |
2 |
Correct |
11 ms |
7808 KB |
Output is correct |
3 |
Correct |
11 ms |
7808 KB |
Output is correct |
4 |
Correct |
10 ms |
7808 KB |
Output is correct |
5 |
Correct |
9 ms |
7808 KB |
Output is correct |
6 |
Correct |
9 ms |
7808 KB |
Output is correct |
7 |
Correct |
9 ms |
7808 KB |
Output is correct |
8 |
Correct |
12 ms |
7808 KB |
Output is correct |
9 |
Correct |
9 ms |
7808 KB |
Output is correct |
10 |
Correct |
9 ms |
7808 KB |
Output is correct |
11 |
Correct |
9 ms |
7808 KB |
Output is correct |
12 |
Correct |
10 ms |
7808 KB |
Output is correct |
13 |
Correct |
10 ms |
7808 KB |
Output is correct |
14 |
Correct |
10 ms |
7808 KB |
Output is correct |
15 |
Correct |
9 ms |
7808 KB |
Output is correct |
16 |
Correct |
23 ms |
9080 KB |
Output is correct |
17 |
Correct |
28 ms |
8952 KB |
Output is correct |
18 |
Correct |
27 ms |
9216 KB |
Output is correct |
19 |
Correct |
26 ms |
8960 KB |
Output is correct |
20 |
Correct |
25 ms |
9008 KB |
Output is correct |
21 |
Runtime error |
57 ms |
20856 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
22 |
Halted |
0 ms |
0 KB |
- |