제출 #925598

#제출 시각아이디문제언어결과실행 시간메모리
925598vjudge1Collecting Mushrooms (NOI18_collectmushrooms)C++11
0 / 100
2043 ms8132 KiB
#include<bits/stdc++.h>

#define int long long
#define pb push_back
#define nl '\n'
#define sz(a) a.size()

using namespace std;

const int N = 1e5 + 1;
const int INF = 1e9;

void solve(){	
	int n, m, d, k;
	cin >> n >> m >> d >> k;
	char a[n + 1][m + 1];
	vector<pair<int, int>> ma, sp;

	for(int i = 1; i <= n; ++i){
		for(int j = 1; j <= m; ++j){
			cin >> a[i][j];
			if(a[i][j] == 'M'){
				ma.pb({i, j});			
			}
			if(a[i][j] == 'S'){
				sp.pb({i, j});	
			}
		}
	}
	
	int ans = 0;

	for(auto to : ma){
		int cnt = 0;
		for(auto ot : sp){
			if(max(abs(to.first - ot.first), abs(to.second - ot.second)) <= d){
				cnt++;					
			}			
		}
		if(cnt == k){
			ans ++;
		}
	}
	cout << ans << nl;
}
      
                                                                                                    
signed main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    int tt = 1;
   	//cin >> tt;
    
    while(tt--){
        solve();
    }
}

//written by Akhmad Khaber
#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...