Submission #921803

#TimeUsernameProblemLanguageResultExecution timeMemory
921803vjudge1Collecting Mushrooms (NOI18_collectmushrooms)C++17
60 / 100
2033 ms11208 KiB
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;

void solve(){
    ll a,b,d,k,t;
    cin>>a>>b>>d>>k;
    t=a;
    if(a==1){
        char c[b+1];
        ll ans=0;
        map<ll,ll>mp;
        vector<ll>v;
        for(ll i=1;i<=b;i++){
            cin>>c[i];
            if(c[i]=='M'){
                v.pb(i);
            }
        }
        for(ll i=1;i<=b;i++){
            if(c[i]=='S'){
                for(ll j=0;j<v.size();j++){
                    if(v[j]>=i-d && v[j]<=i+d){
                        mp[v[j]]++;
                    }
                }
            }
        }
        for(ll i=0;i<v.size();i++){
            if(mp[v[i]]>=k){
                ans++;
            }
        }
        cout<<ans;
    }
    else {
        vector<pair<ll,ll> >v,l;
        char c[a+1][b+1];
        for(ll i=1;i<=a;i++){
            for(ll j=1;j<=b;j++){
                cin>>c[i][j];
                if(c[i][j]=='S'){
                    v.pb({i,j});
                }
                else if(c[i][j]=='M'){
                    l.pb({i,j});
                }
            }
        }
        //sort(v.begin(),v.end());
        ll ans=0,count=0;
        for(ll i=0;i<l.size();i++){
            ans=0;
            for(ll j=0;j<v.size();j++){
                ll res=0;
                res=max(abs(v[j].first-l[i].first),abs(v[j].second-l[i].second));
                if(res<=d){
                    ans++;
                }
                if(ans>=k){
                    count++;
                    break;
                }
            }
            ans=0;
        }
        cout<<count;
    }
}

int main()
{
    ios_base::sync_with_stdio(0),cin.tie(0);
    ll t=1,i=1;
    //cin>>t;
    while(t--){
        //cout<<"Case ";
        //cout<<i<<':'<<"\n";
        //i++;
        solve();
    }
    return 0;
}

Compilation message (stderr)

mushrooms.cpp: In function 'void solve()':
mushrooms.cpp:23:29: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |                 for(ll j=0;j<v.size();j++){
      |                            ~^~~~~~~~~
mushrooms.cpp:30:21: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |         for(ll i=0;i<v.size();i++){
      |                    ~^~~~~~~~~
mushrooms.cpp:53:21: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |         for(ll i=0;i<l.size();i++){
      |                    ~^~~~~~~~~
mushrooms.cpp:55:25: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |             for(ll j=0;j<v.size();j++){
      |                        ~^~~~~~~~~
mushrooms.cpp:7:16: warning: variable 't' set but not used [-Wunused-but-set-variable]
    7 |     ll a,b,d,k,t;
      |                ^
mushrooms.cpp: In function 'int main()':
mushrooms.cpp:75:12: warning: unused variable 'i' [-Wunused-variable]
   75 |     ll t=1,i=1;
      |            ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...