Submission #623448

# Submission time Handle Problem Language Result Execution time Memory
623448 2022-08-05T15:43:57 Z hail Collecting Mushrooms (NOI18_collectmushrooms) C++17
100 / 100
24 ms 20900 KB
#include <bits/stdc++.h>
 
using namespace std;
 
#define vi vector<int>
#define vll vector<long long>
#define pb push_back
using ll= long long;
#define fast_io ios::sync_with_stdio(0); cin.tie(0)
#define inpint(x) int x; cin>>x
#define inpll(x) long long x; cin>>x
#define fl(i, n) for(int i=0; i<n; i++)
#define fl_1(i, n) for(int i=1; i<=n; i++)
#define int long long 
#define pi pair<int, int>
#define mp make_pair
#define ld long double



void solve()
{
    int r, c, d, k;
    cin>>r>>c>>d>>k;

    vector<pi> mushrooms(0);

    vector<vector<int>> sp_pre(r+1, vector<int>(c+1, 0));

    for(int i=1; i<=r; i++)
    {
        for(int j=1; j<=c; j++)
        {
            char a;
            cin>>a;

            sp_pre[i][j] = sp_pre[i-1][j] + sp_pre[i][j-1] - sp_pre[i-1][j-1];

            if(a=='M')
            {
                mushrooms.pb(mp(i, j));
            }
            else if(a=='S')
            {
                sp_pre[i][j]++;
            }
        }
    }

    int ans{};

    for(auto i: mushrooms)
    {
        pi tl = mp(max((int)1, i.first-d), max((int)1, i.second-d));
        pi br = mp(min(r, i.first+d), min(c, i.second+d));

        int nmus = sp_pre[br.first][br.second] - sp_pre[tl.first-1][br.second] - sp_pre[br.first][tl.second-1] + sp_pre[tl.first-1][tl.second-1];
        if(nmus>=k) ans++;
    }


    cout<<ans<<"\n";
    
}
 
int32_t main()
{
    fast_io;
 
    int t=1; 
    //cin>>t;
    while(t--)
    {
        solve();
    }
 
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 316 KB Output is correct
2 Correct 1 ms 456 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 316 KB Output is correct
2 Correct 1 ms 456 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 316 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 320 KB Output is correct
3 Correct 1 ms 724 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 1992 KB Output is correct
2 Correct 5 ms 2140 KB Output is correct
3 Correct 5 ms 2516 KB Output is correct
4 Correct 5 ms 2132 KB Output is correct
5 Correct 5 ms 2260 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 15284 KB Output is correct
2 Correct 24 ms 20900 KB Output is correct
3 Correct 23 ms 20896 KB Output is correct
4 Correct 20 ms 15888 KB Output is correct
5 Correct 22 ms 20880 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 316 KB Output is correct
2 Correct 1 ms 456 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 316 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 1 ms 320 KB Output is correct
13 Correct 1 ms 724 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 596 KB Output is correct
16 Correct 5 ms 1992 KB Output is correct
17 Correct 5 ms 2140 KB Output is correct
18 Correct 5 ms 2516 KB Output is correct
19 Correct 5 ms 2132 KB Output is correct
20 Correct 5 ms 2260 KB Output is correct
21 Correct 21 ms 15284 KB Output is correct
22 Correct 24 ms 20900 KB Output is correct
23 Correct 23 ms 20896 KB Output is correct
24 Correct 20 ms 15888 KB Output is correct
25 Correct 22 ms 20880 KB Output is correct
26 Correct 18 ms 7528 KB Output is correct
27 Correct 16 ms 8784 KB Output is correct
28 Correct 14 ms 6924 KB Output is correct
29 Correct 14 ms 7056 KB Output is correct
30 Correct 18 ms 9532 KB Output is correct