Submission #504960

# Submission time Handle Problem Language Result Execution time Memory
504960 2022-01-10T11:00:57 Z akshtsinghania Collecting Mushrooms (NOI18_collectmushrooms) C++17
0 / 100
16 ms 19220 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long

void solve(){
	int r,c,d,k;
	cin>>r>>c>>d>>k;
	vector<vector<int>> g(r+1,vector<int>(c+1));
	vector<vector<char>> ga(r+1,vector<char>(c+1));
	for(int i=1;i<=r;i++){
		for(int j=1;j<=c;j++){
			char a;
			cin>>a;
			ga[i][j]=a;
			//if(a=='M')g[i][j]+=0;
			if(a=='S'){
				int start_x=max((int)1,i-d),start_y=max((int)1,j-d);
				int end_x=max((int)r,i+d),end_y=max((int)r,j+d);
				g[start_x][start_y]++;
				g[end_x][end_y]++;
				g[start_x][end_y]--;
				g[end_x][start_y]--;
				
			}
			
		}
	}
	int ans=0;
	vector<vector<int>> prefix(r+1,vector<int>(c+1));
	for(int i=1;i<=r;i++){
		for(int j=1;j<=c;j++){
			prefix[i][j]=g[i][j]
					+prefix[i-1][j]
					+prefix[i][j-1]
					-prefix[i-1][j-1];
			if(ga[i][j]=='M'&&prefix[i][j]>=k)ans++;
			//cout<<prefix[i][j]<<" ";
		}
		//cout<<endl;
	}
	cout<<ans<<endl;
}

signed main(){
	cin.tie(NULL);
	cout.tie(NULL);
	ios_base::sync_with_stdio(NULL);
	int t=1;
	//cin>>t;
	while(t--)solve();
	return 0;	
}
/*
5 5 1 1 
....M
.M...
..S..
.S...
...M.

*/
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 460 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 460 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 460 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 4 ms 4044 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 16 ms 19220 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 460 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -