Submission #923855

#TimeUsernameProblemLanguageResultExecution timeMemory
923855pccCollecting Mushrooms (NOI18_collectmushrooms)C++14
100 / 100
11 ms11724 KiB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define pll pair<ll,ll>
#define pii pair<int,int>
#define fs first
#define sc second
#define tlll tuple<ll,ll,ll>


int R,C,K,D;
vector<vector<int>> arr,mush;
vector<string> v;

int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>R>>C>>D>>K;
	arr = mush = vector<vector<int>>(R+1,vector<int>(C+1,0));
	v = vector<string>(R+1);
	for(int i = 0;i<R;i++){
		cin>>v[i];
		for(int j = 0;j<C;j++){
			if(v[i][j] == 'S'){
				int rl = i-D,rr = i+D+1;
				int cl = j-D,cr = j+D+1;
				cl = max(0,cl),cr = min(cr,C);
				rl = max(0,rl),rr = min(rr,R);
				arr[rl][cl]++,arr[rl][cr]--;
				arr[rr][cl]--,arr[rr][cr]++;
			}
			else if(v[i][j] == 'M'){
				mush[i][j] = 1;
			}
		}
	}
	int ans = 0;
	vector<int> now(C+1,0);
	for(int i = 0;i<R;i++){
		int pref = 0;
		for(int j = 0;j<=C;j++){
			pref += arr[i][j];
			now[j] += pref;
			ans += (mush[i][j])*(now[j]>=K);
		}
	}
	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...