Submission #925978

#TimeUsernameProblemLanguageResultExecution timeMemory
925978vjudge1Collecting Mushrooms (NOI18_collectmushrooms)C++17
100 / 100
21 ms29912 KiB
#include<bits/stdc++.h> using namespace std; #define ll long long #define lld long long double #define pb push_back #define pf push_front #define F first #define S second #define all(a) a.begin(), a.end() #define IShowSpeed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); const int N=5e5+100; const int mod=1e9+7; const int K=500; const ll inf=1e18+1337; const int dx[]={-1, 0, 0, 1}; const int dy[]={0, -1, 1, 0}; vector<ll>h[N]; vector< pair<ll,ll> >v; int main() { IShowSpeed ll n,m,d,k,ans=0; cin>>n>>m>>d>>k; for(int i=0;i<=n;i++) for(int j=0;j<=m;j++) h[i].pb(0); for(int i=1;i<=n;++i) { for(int j=1;j<=m;++j) { char c; cin>>c; h[i][j]=h[i-1][j]+h[i][j-1]-h[i-1][j-1]; if(c=='S') h[i][j]++; if(c=='M') v.pb({i,j}); } } for(auto p: v) { ll x=p.F,y=p.S; ll x1=max(0ll,x-d-1),x2=min(n,x+d); ll y1=max(0ll,y-d-1),y2=min(m,y+d); if(h[x2][y2]-h[x2][y1]-h[x1][y2]+h[x1][y1]>=k) ans++; } cout<<ans; }
#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...