Submission #922235

# Submission time Handle Problem Language Result Execution time Memory
922235 2024-02-05T09:32:23 Z vjudge1 Collecting Mushrooms (NOI18_collectmushrooms) C++17
100 / 100
23 ms 33520 KB
#include <bits/stdc++.h>
#include <iomanip>
#define ll long long
#define int long long
#define pb push_back
#define F first
#define mpk make_pair
#define S second
#define st string
#define sz(x) x.size()
#define all(x) x.begin(), x.end()
#define vi vector<int>
#define mii map<int,int>
#define mll map<ll,ll>
#define YES cout<<"YES\n";
#define NO cout<<"NO\n";
#define yes cout<<"Yes\n";
#define no cout<<"No\n";
#define lf else if 
using namespace std;

void why(){
    ll n,m,d,k,ans=0;
    cin>>n>>m>>d>>k;
    ll pp[n+7][m+7];
    for(ll i=0;i<=n;i++){
        pp[i][0]=0;
    }
    for(ll i=0;i<=m;i++){
        pp[0][i]=0;
    }
    st v[n+7],s;
    for(ll i=1;i<=n;i++)
    {
        v[i]=" ";
        cin>>s;
        v[i]+=s;
        for(ll j=1;j<=m;j++)
        {
            pp[i][j]=(v[i][j]=='S');
            pp[i][j]+=pp[i-1][j];
            pp[i][j]+=pp[i][j-1];
            pp[i][j]-=pp[i-1][j-1];
        }
    }
    for(ll i=1;i<=n;i++)
    {
        for(ll j=1;j<=m;j++)
        {
            if(v[i][j]!='M')continue;
            ll l1=max(i-d,1ll);
            ll l2=min(i+d,n);
            ll r1=max(j-d,1ll);
            ll r2=min(j+d,m);
            ll an=pp[l2][r2]-pp[l1-1][r2]-pp[l2][r1-1]+pp[l1-1][r1-1];
            if(an>=k)
            {
                ans++;
            }
        }
    }
    cout<<ans;
}
signed main(){
    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    //srand( time(0));
    //freopen("sum.in", "r", stdin);
    //freopen("sum.out", "w", stdout);
    //ll tests=1;
    //cin>>tests;
    //for(ll i=1;i<=tests;i++)
    //{
        //cout<<"Case "<<i<<":\n";
    why();
    //}
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 0 ms 456 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 464 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2396 KB Output is correct
2 Correct 2 ms 2500 KB Output is correct
3 Correct 2 ms 2908 KB Output is correct
4 Correct 2 ms 2392 KB Output is correct
5 Correct 2 ms 2648 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 33320 KB Output is correct
2 Correct 21 ms 33520 KB Output is correct
3 Correct 21 ms 33264 KB Output is correct
4 Correct 21 ms 33252 KB Output is correct
5 Correct 23 ms 33300 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 0 ms 456 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 464 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 3 ms 2396 KB Output is correct
17 Correct 2 ms 2500 KB Output is correct
18 Correct 2 ms 2908 KB Output is correct
19 Correct 2 ms 2392 KB Output is correct
20 Correct 2 ms 2648 KB Output is correct
21 Correct 21 ms 33320 KB Output is correct
22 Correct 21 ms 33520 KB Output is correct
23 Correct 21 ms 33264 KB Output is correct
24 Correct 21 ms 33252 KB Output is correct
25 Correct 23 ms 33300 KB Output is correct
26 Correct 9 ms 7768 KB Output is correct
27 Correct 5 ms 5468 KB Output is correct
28 Correct 5 ms 5980 KB Output is correct
29 Correct 5 ms 5724 KB Output is correct
30 Correct 9 ms 6748 KB Output is correct