Submission #546889

# Submission time Handle Problem Language Result Execution time Memory
546889 2022-04-08T19:03:50 Z AbdelmagedNour Collecting Mushrooms (NOI18_collectmushrooms) C++17
100 / 100
10 ms 5460 KB
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
int n,m,d,k;
vector<vector<int>>pre;
void calc(){
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            pre[i][j]+=(j?pre[i][j-1]:0)+(i?pre[i-1][j]:0)-(i&&j?pre[i-1][j-1]:0);
        }
    }
}
int sum(int x1,int x2,int y1,int y2){
    int res=pre[x2][y2];
    if(y1)res-=pre[x2][y1-1];
    if(x1)res-=pre[x1-1][y2];
    if(x1&&y1)res+=pre[x1-1][y1-1];
    return res;
}
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin>>n>>m>>d>>k;
    vector<string>grid(n);
    pre.resize(n,vector<int>(m,0));
    for(int i=0;i<n;i++){
        cin>>grid[i];
        for(int j=0;j<m;j++){
            if(grid[i][j]=='S')pre[i][j]++;
        }
    }
    calc();
    int res=0;
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            if(grid[i][j]=='M'){
                int x1=max(i-d,0),x2=min(i+d,n-1),y1=max(j-d,0),y2=min(j+d,m-1);
                if(sum(x1,x2,y1,y2)>=k)res++;
            }
        }
    }
    cout<<res;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 324 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 324 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 320 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 320 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1496 KB Output is correct
2 Correct 3 ms 1492 KB Output is correct
3 Correct 3 ms 1844 KB Output is correct
4 Correct 2 ms 1492 KB Output is correct
5 Correct 2 ms 1620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 4180 KB Output is correct
2 Correct 6 ms 4180 KB Output is correct
3 Correct 6 ms 4180 KB Output is correct
4 Correct 8 ms 4180 KB Output is correct
5 Correct 7 ms 4180 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 324 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 0 ms 320 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 1 ms 320 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 3 ms 1496 KB Output is correct
17 Correct 3 ms 1492 KB Output is correct
18 Correct 3 ms 1844 KB Output is correct
19 Correct 2 ms 1492 KB Output is correct
20 Correct 2 ms 1620 KB Output is correct
21 Correct 7 ms 4180 KB Output is correct
22 Correct 6 ms 4180 KB Output is correct
23 Correct 6 ms 4180 KB Output is correct
24 Correct 8 ms 4180 KB Output is correct
25 Correct 7 ms 4180 KB Output is correct
26 Correct 10 ms 5460 KB Output is correct
27 Correct 7 ms 3284 KB Output is correct
28 Correct 7 ms 3332 KB Output is correct
29 Correct 7 ms 3284 KB Output is correct
30 Correct 10 ms 4564 KB Output is correct